Updated POP3 Wrapper Class

This CPop class is an apdate from the POP3 Protocol wrapper class written by Asif Rasheed. I had some troubles with this class because it went out from short lists/top/messages and in real live we could have 200 messages waiting on our server (hmmm i do... it's the same as reading a newspaper every morning:), and we could also have large emails (with some zip files in it). So this class needs some changes.

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 command

The 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.

Download source - 3.86 KB

Date Posted: