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:



Comments

  • I need to download E-mail attachments

    Posted by Legacy on 12/21/2001 12:00am

    Originally posted by: Masoud Aghapour

    Can anybody tell me how to doanload E-mail attachments? With best regards
    
    

    Reply
  • NO RESPONSE FOR COMMENTS.

    Posted by Legacy on 06/08/2001 12:00am

    Originally posted by: TSANG SUI

    PLEASE SEND THE PROPER RESPONSE FOR OUR QUERIES.
    

    Reply
  • How to download files attached to the mail ?

    Posted by Legacy on 06/07/2001 12:00am

    Originally posted by: Raphael KISTER

    I would like to download files attached to the mail. How can i do?

    Thank you.
    Raphael

    Reply
  • CheckResponse ---> Sleep (2000); ???

    Posted by Legacy on 01/06/2000 12:00am

    Originally posted by: Peter

    BOOL CPop::CheckResponse(int ResponseType) 
    
    {
    char buf[8192];
    int totr,skip;
    BOOL ready;

    for (int i=0;i<sizeof(buf);i++)
    buf[i]='\0';

    Sleep(2000);
    totr=m_PopServer.Receive(buf, sizeof(buf));
    ....

    Why Sleep (2000); ?

    I am using a class with the same problem. If I remove the Sleep (2000) and try to receive a message the program crashes. All other function like LIST STAT ... seems not to require the Sleep command.

    Any suggestions ?
    peter1727@my-Deja.com

    Reply
  • Something to modify

    Posted by Legacy on 02/18/1999 12:00am

    Originally posted by: jof4002

    In function BOOL CPop::CheckResponse(int ResponseType),
    
    

    case LIST_CHECK:

    line 348 is...
    ((buf[0]='O')&&(buf[1]=='K')&&(buf[totr-3]=='.')
    &&(buf[totr-2]=='\r')&&(buf[totr-1]=='\n'))


    I think (buf[0]='O') should be (buf[0]=='O').


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Data integrity and ultra-high performance dictate the success and growth of many companies. One of these companies is BridgePay Network Solutions, a recently launched and rapidly growing financial services organization that allows merchants around the world to process millions of daily credit card transactions. Due to the nature of their business, their IT team needed to strike the perfect balance between meeting regulatory-mandated data security measures with the lowest possible levels of latency and …

  • Relying on outside companies to manage your network and server environments for your business and applications to meet the needs and demands of your users can be stressful. This is especially true as many Managed Hosting organizations fail to meet their service level agreements. Read this Forrester total economic impact report and learn what makes INetU different and how they exceed their customers' managed hosting expectations.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date