Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

20.7 Mail Retrieval: Using the POP3 Client

The next example program provides basic POP3 command access. After making a successful connection to an intended POP3 server and completing login transactions, the program checks for any pending messages in a mail box. If there is at least one message, the first message in the mail drop is retrieved and displayed on the screen.

20.7.1 Code and Explanation

Here is a portion of code followed by comments explaining key lines.

//1Constructs an RWIPop3Client object. The object is set to an unconnected state, ready to use the connect() method of RWIPop3Client to establish a connection with a POP3 server. When the object goes out of scope, disconnection from the server is automatic.
//2Establishes a connection with a POP3 server of interest.
//3Performs the USER protocol command.
//4Performs the PASS protocol command.
//5Performs the STAT protocol command.
//6Gets the total number of pending messages in the mail drop, via the messages() method invocation on the returned statReply object of class RWIPop3StatReply.
//7Performs the RETR protocol command, and immediately redeems the result as the RWIPop3DataReply object dataReply, which contains a socket portal to complete the data portion of the protocol transfer.
//8Checks whether the data reply is +OK. A successful reply from the retr() method is normally +OK, which indicates that the data connection has been opened.
//9Gets the data socket portal from the dataReply object to retrieve data from the underlying socket.
//10Creates an RWPortalIStream object istr built from the socket portal available from //9. The object istr becomes the data source.
//11Reads one line of the mail data at a time.
//12Removes the line feed at the end of the line.
//13Reads message data until a period is contained in a line by itself, which is the indication of the end of a mail message.
//14This catch clause catches all the int library, the net library, and Threads.h++ exceptions that can be thrown from within the try block, since all Rogue Wave exceptions are derived from RWxmsg.

20.7.2 Further Discussion

This example demonstrates one method of redeeming an RWIOUResult object. For other methods, please refer to Chapter 19 and Section 20.4. The application determines which way needs to apply.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.