Chapter 12

POP3 Client

The pop3 structure provides a client for the POP3 protocol that allows access to email on a maildrop server. It is often used in configurations where users connect from a client machine which doesn't have a permanent network connection or isn't always turned on, situations which make local SMTP delivery impossible. It is the most common form of email access provided by ISPs.

Two types of authentication are commonly used. The first, most basic type involves sending a user's password in clear over the network, and should be avoided. (Unfortunately, many POP3 clients only implement this basic authentication.) The digest authentication system involves the server sending the client a ``challenge'' token; the client encodes this token with the pass phrase and sends the coded information to the server. This method avoids sending sensitive information over the network. Both methods are implemented by pop3.

Once connected, a client may request information about the number and size of the messages waiting on the server, download selected messages (either their headers or the entire content), and delete selected messages.

The procedures defined here raise an error detectable via pop3-error? upon protocol errors with the POP3 server.

(pop3-connect [host-or-#f] [login-or-#f] [password-or-#f] [log-port])     --->     connection         (procedure) 
This procedure connects to the maildrop server named host, and logs in using the provided login name and password. Any of these can be omitted or #f, in which case the procedure uses defaults: MAILHOST for the host, and  /.netrc-provided values for login and password. If log-port is provided, the conversation to the server is logged to the specified output port.

Pop3-connect returns a value representing the connection to the POP3 server, to be used in the procedures below.

(pop3-stat connection)     --->     number bytes         (procedure) 
This returns the number of messages and the number of bytes waiting in the maildrop.

Most of the following procedures accept a msgid argument which specifies a message number, which ranges from 1 for the first message to the number returned by pop3-stat.

(pop3-retrieve-message connection msgid)     --->     headers message         (procedure) 
This downloads message number msgid from the mailhost. It returns the headers as an alist of field names and bodies; the names are symbols, the bodies are strings. (These are obtained using the rfc822 structure, see Section 9.) The message is returned as a list of strings, each string representing a line of the message.

(pop3-retrieve-headers connection msgid)     --->     headers         (procedure) 
This downloads the headers of message number msgid. It returns the headers in the same format as pop3-retrieve-message.

(pop3-last connection)     --->     msgid         (procedure) 
This returns the highest accessed message-id number for the current session. (This isn't in the RFC, but seems to be supported by several servers.)

(pop3-delete connection msgid)     --->     undefined         (procedure) 
This mark message number msgid for deletion. The message will not be deleted until the client logs out.

(pop3-reset connection)     --->     undefined         (procedure) 
This marks any messages which have been marked for deletion.

(pop3-quit connection)     --->     undefined         (procedure) 
This closes the connection with the mailhost.

(pop3-error? thing)     --->     boolean         (procedure) 
This returns #t if thing is a pop3-error object, otherwise #f.