POP3 Wrapper Class 2001
Looking at the publishing date of Robert E. Peters' article I decided to write a new and updated POP3 Wrapper Class.
Fixed or Changed:
I restructured the class and replaced the #define constants through enums. I also figured out a few accidentally made bugs in the old POP3 class and fixed them. For example the implementation of the LIST
command where Robert E. Peters sent one space character too much which resulted in -ERR by a few POP3 servers.
The returned data of the LIST, RETR and TOP command can now be bufferd in a temp file or be directly returned (unbuffered). This assumes that you don't have too big mails.
Here are the most important procedures of the new POP3 Class:
enum DataTypes
{
MAIL_AS_STRING,
TOP_AS_STRING,
LIST_AS_STRING
};
class CPOP3Handler
{
...
public:
bool Connect
(LPCTSTR p_User, LPCTSTR p_Password,
LPCTSTR p_Host, int p_Port = 110);
bool Disconnect();
bool Statistics ();
bool Delete
(int p_MsgNumber);
bool Noop ();
bool Reset ();
bool Retrieve
(int p_MsgNumber);
bool Retrieve
(int p_MsgNumber, LPCTSTR p_pTargetFileName);
bool List ();
bool GetTop
(int p_MsgNumber, int p_Length);
bool SetOutputFile
(LPCTSTR p_OutputFileName);
int GetNumberNewMails ();
int GetTotalMailSize ();
CString Get
(int p_DataType, int p_MessageNumber = 1);
CString GetErrorMessage ();
};
After calling Connect you can easily use the Get command to retrieve Mail-Headers, Complete Mails or a List of mails.
Example:
CPOP3Handler POP3;
POP3.Connect ("Username", "Password", pop.host.de, 110);
CString List;
CString Header;
CString WholeMail;
// use one of the enum values to tell GET which data type
// to return.
List = POP3.Get (LIST_AS_STRING);
// Here you need to specify the e-mail number
// as second parameter.
Header = POP3.Get (TOP_AS_STRING, 1);
WholeMail = POP3.Get (MAIL_AS_STRING, 1);
The rest of this class is self explaining in my oppinion. If you have problems using this class, bugs or ideas send a mail at my given mail address.
The Demo is a small console based App which asks for your username, password and POP3 host address. It then does a LIST, TOP and RETR command. The results will be saved in Test.txt at the same directory.
Downloads
Download demo project - 14 KbDownload source - 4 Kb

Comments
How to download
Posted by Legacy on 12/23/2003 12:00amOriginally posted by: Eric Brown
Using http://de.geocities.com/janraddatz/downloads/POP3.zip doesn't work for me. But go to http://de.geocities.com/janraddatz/downloads and selecting POP3.zip from there does.
ReplyWhere are files to download ???
Posted by Legacy on 09/03/2003 12:00amOriginally posted by: matrix666
I cannot download files ...
Replybroken links ...
I need this class
CheckResponse code needs altering ... slightly
Posted by Legacy on 05/23/2003 12:00amOriginally posted by: Duncan Weir
where it checks the following codes
LIST_CHECK
RETR_CHECK
TOP_CHECK
the code currently checks for end of buffer by looking for the last 3 chars being .\r\n
BUT some emails can screw this check up.
For instance i had an email that had a subject line ending in ....\r\n
in this case the code thought it had reached the end of the buffer when in fact is was only part way through.
Solution is to alter the code to look for \n.\r\n
ReplyHope this helps.
Getting just the header - sometimes a problem
Posted by Legacy on 05/19/2003 12:00amOriginally posted by: Duncan Weir
Just a note that after extensive testing with this class in an anti-spam application i'm writing, i've found that the command GetTop works best if you do:
GetTop(<message number>,1);
ReplyDoing GetTop(<message number>,0); works the majority of the time, but sometimes it times out and retrieves nothing !
New URL the Third
Posted by Legacy on 04/29/2003 12:00amOriginally posted by: Jan Raddatz
Hello again,
here is a new URL to download the POP3 Wrapper class.
It's on a fortunecity account and should work finally.
http://members.fortunecity.com/phobos3/POP3.zip
If you have any questions or problems using the class feel free to drop me an e-mail. :-)
ReplyGreetings to all codegurus
Jan
no Connect after Disconnect :(
Posted by Legacy on 04/13/2003 12:00amOriginally posted by: Marco Gohl
I connect to the server and get my mails, but after
i disconnect then I can't connect again :(
"Server cannot be connected"...
How can I solve this Problem?
ReplyURL Fix 2nd
Posted by Legacy on 04/09/2003 12:00amOriginally posted by: Jan Raddatz
Hello,
I posted the new URL a few days ago.
The problem is that it seems not to work for some people.
I will get a new domain soon and publish the new URL to the files soon here.
If the geocities link does not work for you (It worked for me) feel free to post me a mail and I will send you the files immediately.
mail: jan-raddatz@web.de
Greetings
ReplyJan
URL Fix 09.03.2003
Posted by Legacy on 03/09/2003 12:00amOriginally posted by: Jan Raddatz
Hello,
due to ISP problems I had to move my website and so the URL's were broken.
Here is the fixed URL to the POP3 Wrapper class source code.
It's a zipped file.
Greetings
Jan
http://de.geocities.com/janraddatz/downloads/POP3.zip
Replypop3
Posted by Legacy on 02/09/2003 12:00amOriginally posted by: prasad
very nice project
ReplyURL's for source/project are down :-(
Posted by Legacy on 05/12/2002 12:00amOriginally posted by: Agent_White
Does anybody know the new url where i can download the source / demo project ???
Maybe it's possible that someone could mail this files to Agent_White@hotmail.com !!!
thanx in advance.
cu Agent_White
ReplyLoading, Please Wait ...