<CRLF>.<CRLF>
." Commands are line-oriented and can return a single or multi-line response.
For detailed information about POP3, see RFC 1939: "Post Office Protocol - Version 3."
[Top]
Figure 5.1 POP3 Session States
Response Type |
Response Code and Description
|
|
|
Final line: . (dot) and Note: If an error occurs on a multi-line response, a single line is returned. |
---|
Step |
Section with details
|
|
|
|
|
|
|
|
| |
---|
netscape.messaging.pop3.IPOP3Sink
. Interface for the POP3 response sink. See Creating a Response Sink.netscape.messaging.pop3.POP3Client
. Represents the POP3 client. See Creating a Client.netscape.messaging.pop3.POP3Sink
. Implementation of the IPOP3Sink
interface. See Creating a Response Sink. netscape.messaging.pop3.POP3Exception
. Exception thrown when an POP3 API error condition is detected by the Messaging Access SDK. Extends IOException
.netscape.messaging.pop3.POP3ServerException
. Exception thrown from the error
callback on the response sink when the server sends an error. Extends IOException
and POP3Exception
. IPOP3Sink
interface contains callbacks for each client call. The client's processResponses
method invokes the interface method that corresponds to the client call. Methods with multi-line responses map to more than one callback. The first type of callback indicates the start of a notification. The second type passes back multi-line data. The third type of callback provides a notification that the operation is complete.
If a server error occurs, the error callback is invoked.
Table 5.3 shows which POP3 methods are mapped to callbacks in the IPOP3Sink
interface. Table 5.4 shows methods that do not map to callbacks.
Table 5.3 Methods with Callbacks
Methods Without Callbacks
disconnect processResponses setChunkSize setResponseSink setTimeout |
---|
IPOP3Sink
interface. The response sink contains the callback methods for the POP3 client. For general information about the response sink, see SDK Sink Classes for Java.
The IPOP3Sink
interface contains callbacks for each client call. You must implement this interface in order to use the POP3 client object. The constructor for the POP3Client
class takes an IPOP3Sink
object as a parameter.
To implement your own response sink class, you can extend the IPOP3Sink
interface, using this syntax:
public class newIPOP3Sink extends ObjectAs a convenience, the Messaging SDK provides the
implements IPOP3Sink
POP3Sink
class, which implements the IPOP3Sink
interface. POP3Sink
implements all the interfaces in IPOP3Sink
. By default, the implementation does nothing, except for the error
callback, which throws an exception. You can save a step by extending this class, using this syntax:
public class newPOP3Sink extends IPOP3Sink{The following section of code creates a response sink.
}
POP3Sink l_pop3Sink;
l_pop3Sink = new POP3Sink();After you create the response sink, the next step is Creating a Client. [Top]
POP3Client
object to communicate with the server. To create the POP3Client
object and set the response sink for the client's use, call the POP3Client.POP3Client
class constructor, which takes an existing response sink. Use this syntax:
public POP3Client(IPOP3Sink in_sink)The client class must implement all of the methods in the
IPOP3Sink
interface.
The following section of code creates a client.
/* Create sink first as described in Creating a Response Sink */
POP3Client l_client;
l_client = new POP3Client( l_pop3Sink );After you initialize the client, the next step is Connecting to a Server. [Top]
POP3Client
connect
methods, depending on whether or not you want to specify the connection port. The SDK methods perform some error-checking.
To connect to the server using the default port for the POP3 protocol (port 110), use this form of connect
and supply the identifier of the server:
public synchronized void connect(String in_server)To specify the server port to use for the server connection, use this form of
throws IOException
connect
:
public synchronized void connect(String in_server,
int in_port) throws IOException
NOTE: For the callback mapping for these methods, see POP3 Callback Mapping. §The following section of code connects the client to the server.
/* After Creating a Response Sink and Creating a Client */
l_client.connect( "pop3server.com" );
l_client.processResponses();After connecting to the server, the next step is Logging In. To disconnect the client from the server and close the socket connection, use this
POP3Client
class method:
public synchronized void disconnect() throws IOExceptionYou could use this method as part of a Cancel operation while retrieving a message. Remember that you do not call
processResponses
after disconnect
.
[Top]POP3Client.user
and give the name of the user's maildrop or mailbox:
public synchronized void user(String in_user) throws IOExceptionThis method sends the USER POP3 protocol command. To submit the user password, call the
POP3Client.pass
method:
public synchronized void pass(String in_password)This method sends the PASS POP3 protocol command. While these commands execute, the session is in Authorization state. Successful completion moves the session to the Transaction state. For a list of states and commands that can be executed in each state, see POP3 Session States. A successful login moves the POP3 session from the Authorization state to the Transaction state, where the user can perform a number of operations.
throws IOException
NOTE: For the callback mapping for these methods, see POP3 Callback Mapping. §The following section of code shows a login sequence for a user.
/* User id sequence */
l_client.user( "pop3user" );
l_client.processResponses();
/* Password sequence */
l_client.pass( "pop3password" );
l_client.processResponses();After you log in, you can perform any Transaction state operations. The next step is Retrieving a Message. [Top]
POP3Client
.status method gets the mailbox status for a given client by issuing the STAT protocol command.
The POP3Client
.status method gets mailbox status for a given mailbox:
public synchronized String status(String in_mailbox,The status returned includes the number of messages present and the octet size of the mail drop.
String in_statusData) throws IOException
NOTE: For this method's callback mapping, see POP3 Callback Mapping. §The following section of code requests the status of the mail drop.
l_client.stat();
l_client.processResponses();[Top]
POP3Client.list
methods, depending on whether you want to list all of the messages in a mailbox or a specific message.
To go through all the messages in the mailbox and generate a list of messages, use the list
method that takes no parameters:
public synchronized void list() throws IOExceptionThis method sends the LIST POP3 protocol command. To list only the message specified by the message number, use this
list
method:
public synchronized void list(int in_messageNumber)Supply the message number as a parameter. This method sends the LIST [arg] POP3 protocol command.
throws IOException
NOTE: For the callback mapping for these methods, see POP3 Callback Mapping. §The following section of code retrieves the email address of the sender along with authenticated messages.
l_client.list();
l_client.processResponses();[Top]
POP3Client.top
method, which issues the TOP protocol command:
public synchronized void top(int in_messageNumber,To retrieve all headers for a given mailbox, combine
int in_lines) throws IOException
POP3Client
.top with a call to POP3Client
.stat. First, call stat
to find the number of messages in the mailbox. When you get the number, for example, 10, call top
once, passing each message number in turn, until you get to the total (in this case, 10). For the in_lines
parameter, use a value of 0 so that no body lines are returned.
NOTE: For this method's callback mapping, see POP3 Callback Mapping. §The following section of code lists the header of the message specified by its message number. It retrieves no body lines.
l_client.top( 1, 0 );
l_client.processResponses();After you retrieve message headers, you can go on to Retrieving a Message if you like. [Top]
POP3Client
.pop3_retrieve
method takes the identifier of the POP3 client that is retrieving the mail and the message number, and retrieves the contents of the message:
public synchronized void retrieve(int in_messageNumber)The message is returned in the form of data chunks, which are sent to the application through callbacks. The
throws IOException
pop3_retrieve
method issues a RETR command. It fails if the message with the specified number does not exist.
NOTE: For this method's callback mapping, see POP3 Callback Mapping. §The following section of code retrieves the contents of a message.
l_client.retrieve( 1 );
l_client.processResponses();[Top]
POP3Client.quit
to notify the server:
public synchronized void quit() throws IOException
This method sends the QUIT POP3 protocol command. The server closes the TCP connection and sends back a response. It is preferable to end a session with quit
instead of just closing the connection.
If the session is in the Authentication state when this method is called, the server simply closes the connection. If the session is in the Transaction state, the server goes into the Update state and expunges any messages marked for deletion, and then quits.
NOTE: For this method's callback mapping, see POP3 Callback Mapping. §The following section of code notifies the server that the client is terminating the session.
l_client.quit();
l_client.processResponses();[Top]
Last Updated: June 3, 1998