Home : Network Programming |
POP3 and IMAP4 |
We know that it is not possible for all computers to be continuously connected to the internet. This is especially true for users who use dial-up connections to access the Internet. These computers cannot run their own SMTP (RFC 821) servers to manage incoming and outgoing mails because the server needs to be running and connected to the internet all the time. Imagine a situation where someone can only send mail to you while you are logged onto the Internet. This situation is certainly unacceptable and ways have been developed to remedy it. Read on.
One solution is to maintain a mailbox on a machine (the server) which is continuously connected to the Internet. This machine would accept all mails on our behalf. We (the clients) could periodically connect to this server via the Internet to view or download the mails in our mailbox using a agreed upon protocol. Some of the ways to access ones's mailbox are listed below:
It is common for a mailbox to be accessible using multiple methods. For example, the mailbox provided to me by VSNL is accessible using both POP3 and a web-interface.
Since POP3 is a more commonly used protocol (and simpler too), we will discuss it in detail here.
(much of the stuff in this section is derived from RFC 1939)
Initially, the server host starts the POP3 service by listening on TCP port 110. When a client host wishes to make use of the service, it establishes a TCP connection with the server host. When the connection is established, the POP3 server sends a greeting. The client and POP3 server then exchange commands and responses (respectively) until the connection is closed or aborted.
Commands in the POP3 consist of a keyword, possibly followed by one or more arguments. All commands are terminated by a CRLF (Carriage Return and Line Feed) pair.
Responses in the POP3 consist of a status indicator and a keyword possibly followed by additional information. All responses are terminated by a CRLF pair. There are currently two status indicators: positive ("+OK") and negative ("-ERR"). Responses to certain commands are multi-line. In these cases, lines sent are terminated by a CRLF pair. When all lines of the response have been sent, a final line is sent, consisting of a "." and a CRLF pair. A server responds to an unrecognized, unimplemented, or syntactically invalid command with a negative status indicator.
There are two methods of authentication specified by the protocol. A system needs to implement at least one of them. (Details of the commands are given later)
A list of valid commands is listed below. Note that the implementation of some commands is optional. Such commands are denoted by "(Optional)" towards the end of the definition. Some of the arguments to a command may also be optional, such arguments are enclosed in square brackets.
This section may seem a bit out of place, but we need to use Telnet in the next section so i thought it would be nice to give all of you a little introduction.
The telnet command is used to communicate with another host. It sets up a TCP connection with a specified host at a given port number and presents us with an interface so that we can type messages to be sent to the other host and view the replies sent by the host. Since the POP3 command is a text based protocol, we can see what actually goes on beneath all the layers of the mail client by directly interacting with the POP3 server usign Telnet.
The problem I encountered was that Telnet didn't seem to work from hosts within CL. After a lot of asking around, i finally got the answer on the CSA Newsgroups. There is a IP firewall installed on all CL linux hosts which filters out IP packets from all but a few ports. The details of the permitted connections can be obtained here. Telnet is on the banned list, but there is still a ray of hope.
The solaris machines in CL (kohinoor, bhrigu and osiris) have no firewall. So we can telnet remote hosts through these machines. :)
I am going to show you samples from a conversation I had with the POP3 server of VSNL. The server's replies are prefixed with a "S:" and the lines displayed by the client are prefixed with a "C:".
$ telnet mail.vsnl.net 110
C: Trying 203.200.235.182 ...
C: Connected to mail.vsnl.net.
C: Escape character is '^]'.
S: +OK Messaging Multiplexor (iPlanet Messaging Server 5.2 HotFix 1.16 )
C: USER malhotra_g
S: +OK password required for user malhotra_g@vsnl.net
C: PASS ***********
S: +OK Maildrop ready
C: STAT
S: +OK 86 1228352
C: LIST
S: +OK scan listing follows
S: 1 1720
S: 2 65796
S: 3 54771
..................
S: 84 6962
S: 85 5336
S: 86 5036
S: .
C: UIDL 7
S: +OK 7 7-1053395393
C: TOP 86 5
S: +OK
S: Return-path: < managementstudies@indiatimes.com >
S: Received: from mx4.vsnl.net (mx1-c2.vsnl.net [172.16.28.149])
S: by pop2.vsnl.net (iPlanet Messaging Server 5.2 HotFix 1.16
S: with ESMTP id <0HMC0007BLFVBA@pop2.vsnl.net>; Mon,
S: 06 Oct 2003 23:46:44 +0530 (IST)
............................
S: Date: Mon, 06 Oct 2003 23:45:03 +0000
S: From: managementstudies@indiatimes.com
S: Subject: Management Entrance Preparatory SERIES... Mumbai
S: Reply-to: managementstudies@indiatimes.com
S: Message-id: <309.286955.724678@indiatimes.com>
S: MIME-version: 1.0
S: Content-type: text/html; charset=us-ascii
S:
S:
S: <html>
S: <head>
S: <title>Management CDROM</title>
S: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
S: .
C: DELE 86
S: +OK message deleted
C: NOOP
S: +OK
C: STAT
S: +OK 85 1223316
C: QUIT
S: +OK
C: Connection closed by foreign host.
As always, here are some links for those thirsty for more
Back to Network Programming |