USING POP3 TO ACCESS EMAIL The original host-to-host SMTP did not allow for attachments, limited messages to 1000 bytes, was a purely connection-oriented application, and never imagined
Trang 1and even as executable code (much to the chagrin of network administrators) Base64
encoding converts a binary data stream to a sequence of “text” characters This usually results in the size of the binary fi le growing by about 33% in terms of bytes This is because 6 bits can indicate the numbers 0 through 63 But bytes are 8 bits, of course, at least where the Internet and TCP/IP are concerned.
An Example of a MIME Message
Consider a writer delivering a short story to an editor as an email attachment (been there, done that) What would the MIME headers that form the overall body of the email message look like? Well, they would resemble the following:
Content-Type: multipart/mixed;
boundary = " - = _NextPart_000_027HB582.0E7E0F6"
This is a message in MIME format
- = _NextPart 000_027HB582.0E7E0F6
Content-Type: text/plain
Table 21.3 MIME Content Types and Subtypes
Type Subtypes
text plain, richtext, tab-separated-values, html, sgml
image jpeg, gif, ief, tiff, g3fax, png
video mpeg, quicktime, vnd.vivo
audio basic, 32kadpcm, vnd.vivo
application octet-stream, postscript, rtf, pdf, zip, macwriteii, msword, remote-printing, EDI-X12,
EDIFACT, dec-dx, dca-rft, activemessage, applefi le, mac-binhex40, news-message-id, mews-transmission, wordperfect5.1, mathematica, pgp-encrypted, pgp-signature, pgp-keys, andrew-inset, slate, set-payment, set-registration, sgml, wita, lotus-wordpro, lotus-1-2-3, lotus-organizer, ms-excel, powerbuilder-6
multipart mixed, alternative, digest, parallel, appledouble, header-set, form-data, report,
voice-message, signed, encrypted
message rfc822, partial, external-body, news, http, delivery-status
Table 21.4 MIME Encoding Methods and Meanings
Method Meaning
7bit Ordinary ASCII as used in the United States
quoted-printable Adds a few special characters and coding to ASCII text
base64 Content is mapped into a “text” package (very common)
8bit Similar to 7bit, but can include 8-bit characters
binary True binary data
x-(name) Experimental encodings must have a name starting with “x”
Trang 2Please take a look at the attached short story Thanks.
W
- = _NextPart_000_027HB582.0E7E0F6
Content-Type: application/msword;
name = "new story.doc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename = "new story.doc"
(Lots of nonsense characters form the base64 table.)
- = _NextPart_000_027HB582.0E7E0F6
The lines in bold are the MIME headers.
USING POP3 TO ACCESS EMAIL
The original host-to-host SMTP did not allow for attachments, limited messages to
1000 bytes, was a purely connection-oriented application, and never imagined a world
of personal computers and intermittent email checking STMP was built for immediate email delivery to a specifi c host, sort of what we think of as instant messaging (IM) today Email today is often delivered to mailboxes on mail servers, not directly to the end user, that is, users who might only have dial-up Internet access.
FIGURE 21.8
A POP3 capture, highlighting how the email listing is sent to the user
Trang 3Client–Server POP3 Connection (TCP 3-way handshake and close omitted)
⫹OK POP3 Inxserver (etc.)
⫹OK User name accepted, password please
⫹OK Mailbox open, 1 message
USER admin1
PASS admin11
DELE 1
QUIT
STAT
(SERVER) port 110
Inxserver
(CLIENT)
port 2447
Inxclient
⫹OK 1 1108
⫹OK Mailbox scan listing follows\r\n1 1108 (etc.)
⫹OK 1108 octets
⫹OK Message deleted
⫹OK Sayonara
LIST
RETR 1
FIGURE 21.9
A POP3 connection used to fetch email, showing a more schematic view than the capture
These intermittent Internet users log in and access their mailbox with POP3 (com-monly just called POP) POP3 does not send email: SMTP does that But POP3 retrieves the email, and the IMAP4 protocol maintains and controls access to the mailbox accounts.
POP3 uses TCP port 110, and users are authenticated by userID and password POP3 then places a lock on the mailbox to avoid access confl icts The POP3 server then enters transaction mode for user access to messages POP3 features include the abil-ity to view a list of email messages and their sizes and to selectively retrieve or delete messages, but many implementations simply dump all waiting mail to the client POP3 servers can be the same device as the SMTP mail server, but this is not a requirement Let’s add POP3 to our network We used the BSD hosts before, so let’s make lnxserver
(10.10.11.66) into our email server for the network We can then compose a fairly long (1108 bytes) message and send it to user admin1 Figure 21.8 shows the sequence of packets used to retrieve the message from host lnxclient (10.10.12.166).
POP3 employs a characteristic +OK and not a code when responding normally to a client The series of packets shown in Figure 21.8 is boiled down to its POP3 essentials
in Figure 21.9.
Trang 4Note that the retrieval of the message (RETR) by the client and its deletion from the server (DELE) are separate steps You don’t have to delete email as you read it, of course The +OK Sayonara is also part of the POP3 protocol implementation.
HEADERS AND EMAIL
We’ve mentioned email headers already and supplied some details about MIME headers (header extensions) Email has its own proper set of headers as well, and an Internet email message is little more than a sequence of headers and their values, one after the other, from the start of the email message to the end Table 21.5 outlines the basic email header fi eld names and groups established by RFC 822.
Now we have everything in place to examine the headers created when sending a short email message through our email server (lnxserver) from a client host to another user We’ll use the admin account on lnxclient to send a message to the admin user on
Table 21.5 RFC 822 Email Header Fields and Characteristics
Field Group Field Name Appearance
Occurrences per Message Comment
Destination
Address Field
To: Usually present 1 Primary recipient list
Identifi cation
Fields
Message-ID: Usually present 1 Unique code applied when
sent In-Reply-To: Optional, normal
for replies
1 Provides method to
coordi-nate responses References: Optional 1 Other documents or
mes-sage IDs Informational
Fields
Subject: Usually present 1 Topic of the message Comments: Optional Unlimited Describe message Keywords: Optional Unlimited Useful search item Origination
Date
mail Originator
Fields
“originator”
“originator”
Reply-To: Optional 1 If absent, reply goes to
“from”
Trang 5lnxserver (these are not necessarily the same users: they just share a mailbox name) Then we’ll fetch the message from the email server mailbox using the admin account, showing that we can fetch our email almost anywhere, even from the sending host.
We can use the same basic mail program as we did on the BSD hosts This time, we’ll use the –s fl ag to create a subject for the message The text is simple, and we end our message with a single dot as before.
[admin@lnxclient admin]$ mail –s "Here is another example"
admin@lnxserver.booklab.englab.juniper.net
This is text…
Cc: (enter)
Now we’ll use fetchmail to “fetch” the mail message with POP3 from the email server (lnxserver) and bring it back to lnxclient Note that when we run the program and have email we get a version of the familiar “you’ve got mail” prompt.
[admin@lnxclient admin]$ fetchmail
Enter password for admin@lnxserver.booklab.englab.juniper.net: (not shown)
You have new mail in /var/spool/mail/admin
Usually, our complete email application would display the information and the mes-sage But there’s nothing magical about that We can do the same with the command prompt, listing the mailbox content and displaying the email message with normal Unix commands.
[admin@lnxclient admin]$ ls –l /var/spool/mail/admin
-rw - 1 admin mail 3122 Jan 17 16:42 /var/spool/mail/admin
Table 21.5 (continued)
Field Group Field Name Appearance
Occurrences per Message Comment
Resent Fields Resent-Date:
Resent-From:
Resent-Sender:
Resent-To:
Resent-Cc:
Resent-Bcc:
Resent-Message-ID:
Each time message is resent, this block
is generated
Resent-Date:
and Resent-Sender: are mandatory;
all others optional
Special, used for forwarding an email message to others
Trace Fields Received:
Return-Path:
Inserted by email system
Unlimited Used to trace the
message through the email system
Trang 6[admin@lnxclient admin]$ cat /var/spool/mail/admin
From admin@lnxserver.booklab.englab.juniper.net Wed Jan 16 13:04:50 2008 Return-Path: <admin@lnxclient.booklab.englab.juniper.net>
Received: from localhost (localhost.localdomain [127.0.0.1])
by lnxclient.booklab.englab.juniper.net (8.12.9/8.12.8) with ESMTP id
jBGL4onD026830
for <admin@localhost>; Wed, 16 Jan 2008 13:04:50 -0800
Received: from lnxserver.booklab.englab.juniper.net
by localhost with POP3 (fetchmail-6.2.0)
for admin@localhost (single-drop); Wed, 16 Jan 2008 13:04:50 -0800 (PST) Received: from lnxclient.booklab.englab.juniper.net ([10.10.12.166])
by lnxserver.booklab.englab.juniper.net (8.12.8/8.12.8) with ESMTP id
jBGL4HFa027257
for <admin@lnxserver.booklab.englab.juniper.net>; Wed, 16 Jan 2008
13:04:17 -0800 (PST)
Received: from lnxclient.booklab.englab.juniper.net (localhost.localdomain [127.0.0.1])
by lnxclient.booklab.englab.juniper.net (8.12.8/8.12.8) with ESMTP id
jBGL4HnD026820
for <admin@lnxserver.booklab.englab.juniper.net>; Wed, 16 Jan 2008
13:04:17 -0800
Received: (from admin@localhost)
by lnxclient.booklab.englab.juniper.net (8.12.8/8.12.8/Submit) id jBGL4HHf026818
for admin@lnxserver.booklab.englab.juniper.net; Wed, 16 Jan 2008
13:04:17 -0800
Date: Wed, 16 Jan 2008 13:04:17 -0800
From: admin@lnxclient.booklab.englab.juniper.net
Message-Id: <200801172104.jBGL4HHf-26818 @lnxclient.booklab.englab.juniper.net>
To: admin@lnxserver.booklab.englab.juniper.net
Subject: Here is another example
X-IMAPbase: 1134766876 8
Status: o
X-UID: 8
X-Keywords:
This is text…
The important fi elds are highlighted Most of the other headers were added when the email was created, of course Most useful is the series of Received: headers, which
allows us to trace the message back to its origin It might seem odd that there are fi ve
receiver headers along the trace for a message that has gone from client to email server and then back to client But the application adds a localhost step at each end, at the sender (admin@localhost) and receiver (from localhost) to the message trace The complete path of the message recorded in the headers (from “bottom to top”) is:
1 The mail application receives the composed message from the local user.
2 The local mailbox receives the message using ESMTP.
3 The email server receives the message using ESMTP.
Trang 74 The other client retrieves the message from the email server using POP3
(fetchmail).
5 The local host transfers the message to the local mailbox using ESMTP.
6 The use of these protocols is highlighted in the headers.
HOME OFFICE EMAIL
Let’s end our email discussion by showing that Windows uses the same protocols and headers to send and receive email over the Internet This time, we’ll send a mes-sage from lnxclient on the Illustrated Network to my home offi ce host (which uses Outlook).
Almost all email applications have an option to view the complete headers In Out-look, it’s just “Message Header” in the singular, but the following is the result of viewing the message headers in Outlook Only the headers are displayed, not the message text itself.
Microsoft Mail Internet Headers Version 2.0
Received: from beta.jnpr.net ([172.24.18.109]) by positron.jnpr.net with Microsoft SMTPSVC(5.0.2195.6713);
Thu, 17 Jan 2008 07:37:14 -0700
Received: from merlot.juniper.net ([172.17.27.10]) by beta.jnpr.net over TLS secured channel with Microsoft SMTPSVC(6.0.3790.1830);
Thu, 17 Jan 2008 07:37:13 -0700
Received: from lnxclient.englab.juniper.net (lnxclient.englab.juniper.net [10.10.12.166])
by merlot.juniper.net (8.11.3/8.11.3) with ESMTP id k9JEbDH15244
for <walterg@juniper.net>; Thu, 17 Jan 2008 07:37:13 -0700 (PDT)
(envelope-from admin@lnxclient.englab.juniper.net)
Received: from lnxclient.englab.juniper.net (localhost.localdomain
[127.0.0.1])
by lnxclient.englab.juniper.net (8.12.8/8.12.8) with ESMTP id
k9JEacUg026193
for <walterg@juniper.net>; Thu, 17 Jan 2008 07:36:58 -0700
Received: (from admin@localhost)
by lnxclient.englab.juniper.net (8.12.8/8.12.8/Submit) id k9JEaSlp026191 for walterg@juniper.net; Thu, 17 Jan 2008 07:36:28 -0700
Date: Thu, 17 Jan 2008 07:36:28 -0700
From: admin@lnxclient.englab.juniper.net
Message-Id: <200801171436.k9JEaSlp026191@lnxclient.englab.juniper.net> To: walterg@juniper.net
Subject: here is an email example
Return-Path: admin@lnxclient.englab.juniper.net
X- OriginalArrivalTime: 17 Jan 2008 14:37:13.0230 (UTC) FILETIME=[10F80AE0: 01C6F38C]
Trang 9QUESTIONS FOR READERS
Figure 21.10 shows some of the concepts discussed in this chapter and can be used to answer the following questions.
FIGURE 21.10
POP3 session capture
1 Which port does POP3 use?
2 Which password is provided by the user?
3 Was the email message deleted after it was retrieved?
4 How long was the message?
5 How many other messages are in the user’s mailbox?