Keep in mind that POP3 mail messages are terminated by <period> contained on a line by itself. When you retrieve a mail drop via an RWSocketPortal, which can be obtained through the portal method of an RWIPop3DataReply, don't look for more data if the mail termination indication has been reached.
If you attempt to save a mail message to a file using the RWStreamCoupler mechanism in the int library, make sure you use the pop3StreamFilter global function, whose declaration can be found in the pop3.h header file as the filter of the RWStreamCoupler::operator() method. This filter is used to indicate an end-of-data (mail) condition on a POP3 input stream. The following lines show how to do this:
RWIPop3DataReply reply; reply = client.retr(1); // retrieve the first message RWPortalIStream istr(reply.portal()); // construct an input stream ofstream ostr("save.me"); // construct an output stream in save.me RWStreamCoupler couple; couple(istr, ostr, pop3StreamFilter);
To handle the possibility that an email message might have a single period on a line, POP3 servers double any period that is the first character in a line. The RWCString utility function rwRemovePeriods() is available to strip any such changed lines. Here is an example:
#include "rw/toolpro/util.h" void saveMessage (RWIPop3Client client) { RWIPop3DataReply reply; reply = client.retr(1); // retrieve the first message RWPortalIStream istr(reply.portal()); // construct input stream RWCString body; body.readFile(istr); body = rwRemovePeriods(body); ofstream ostr("save.me"); // construct output stream in save.me RWStreamCoupler couple; couple(istr, ostr, pop3StreamFilter);
}
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.