Updated POP3 Wrapper Class
We need to buffer the incomming messages where needed, for example when asking the pop server for a LIST command, that will be very large, we need to store this list somewhere before proceding it. We also need to buffer the TOP and RETR command, wich could be large as well.
I use 2 temp. files,because i dont want to know how my memory looks like when getting 100.000 messages and allocating memory for this. Also when you make some kind of program where more as 100 people could ask for a list at the same time, try figuring out how less memory your computer will have at that moment. I also made a new command to extract the TOP of a message (from,to, date ect.). This still needs some more options, but if you want to do this look at RFC822.
In the top of the CPP file you can define two names that will be used as tempory files.
#define templist "templist.pop" // file used for temp list command #define temptop "temptop.pop" // file used for temp top commandThe new procedures in this class are:
BOOL CPop::Retrieve(int MsgNumber,CString fname)
{
char buf [512];
if (SetOutputFile(fname)) m_todisk=TRUE;
else
{
m_ErrorMessage = _T("Error opening output file");
return FALSE;
}
wsprintf (buf, "RETR %d\r\n",MsgNumber );
m_PopServer.Send(buf, strlen (buf));
if (CheckResponse(RETR_CHECK)==FALSE)
return FALSE;
else
return TRUE;
}
Input:MsgNumber: the number of the message to get fname: the name of the file in wich the message is copyed.
return:
True/False
BOOL CPop::ExtractTop(CString fname)
{
CString tcstring;
int pos;
TRY{
CStdioFile f(fname,CFile::modeRead);
while (f.ReadString(tcstring))
{
tcstring.TrimLeft(); tcstring.TrimRight();
if (tcstring.Find('\r')!=-1) tcstring=tcstring.Left(tcstring.GetLength()-1);
if (tcstring.Find('\n')!=-1) tcstring=tcstring.Left(tcstring.GetLength()-1);
tcstring.TrimLeft(); tcstring.TrimRight();
if (pos=tcstring.Find("To:")==0) t_To=tcstring.Right(tcstring.GetLength()-sizeof("To:"));
if (pos=tcstring.Find("From:")==0) t_From=tcstring.Right(tcstring.GetLength()-sizeof("From:"));
if (pos=tcstring.Find("Subject:")==0) t_Subject=tcstring.Right(tcstring.GetLength()-sizeof("Subject:"));
if (pos=tcstring.Find("Date:")==0) t_Date=tcstring.Right(tcstring.GetLength()-sizeof("Date:"));
}
f.Close();
if ((t_To=="")||(t_From=="")||(t_Date=="")) return FALSE;
else return TRUE;
}
CATCH( CFileException, e ){
m_ErrorMessage="cant open message file";
return FALSE;
}END_CATCH
}
Input:fname, the name of a message wich you stored with the Retreive function.
Remarks:
This command will will extract the top from a message.
New variables are:
t_To: top To field t_From: top From field t_Subject: top Subject field t_Date: top Date field
For the rest the changes are in the class.
Date Posted:

Comments
I need to download E-mail attachments
Posted by Legacy on 12/21/2001 12:00amOriginally posted by: Masoud Aghapour
ReplyNO RESPONSE FOR COMMENTS.
Posted by Legacy on 06/08/2001 12:00amOriginally posted by: TSANG SUI
ReplyHow to download files attached to the mail ?
Posted by Legacy on 06/07/2001 12:00amOriginally posted by: Raphael KISTER
I would like to download files attached to the mail. How can i do?
Thank you.
ReplyRaphael
CheckResponse ---> Sleep (2000); ???
Posted by Legacy on 01/06/2000 12:00amOriginally posted by: Peter
Reply
Something to modify
Posted by Legacy on 02/18/1999 12:00amOriginally posted by: jof4002
Reply