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

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds