message Electronic mail, usually called email, e-mail or simply mail, is a method of sending messages to other people on the Net.. It allows the user to read, forward and reply to incomi
Trang 1Electronic mail:
clients
In this chapter:
• Files, folders or
director ies?
message
In this chapter:
• Files, folders or
director ies?
message
Electronic mail, usually called email, e-mail or simply mail, is a method of sending
messages to other people on the Net As with other network services, there are two parts
to mail software:
• The part of the mail system that most users know is the client, the Mail User Agent,
or MUA, the program that interacts with the user and handles incoming and outgoing mail In this chapter we’ll look at my favourite MUA, mutt, and we’ll briefly touch
on what others are available
• The server part is the Mail Transfer Agent, or MTA As the name suggests, it is
responsible for moving mail from one system to another We’ll look at MTAs in the
next chapter, Chapter 27, Electronic mail: servers.
Mail, formats
Email is defined by a number of Internet standards, the so-called RFCs, or Requests For
Comments You can browse the RFCs at http://www.faqs.org/rfcs/ Here are the most
important ones
• RFC 2821 is a recent update to the venerable RFC 821, which dates from the early
1980s It defines the Simple Mail Transfer Protocol or SMTP It specifies how to
send mail round the network For most people it’s not very interesting, but it does impose some restrictions such as the basic line length limit Apart from this problem (which Microsoft abuses), most mail systems adhere to SMTP
Trang 2Mail, for mats 470
• Similarly, RFC 2822 replaces RFC 822 It defines the basic format of a mail message It defines the headers (To:, Cc:, Subject: and so on) and a simple body made up of US-ASCII text, the message itself This was fine for when it was written, but it can’t handle the more complex formats used nowdays, such as images, binary files or embedded messages It also can’t handle non-US character sets, which causes problems in particular in countries like Russia, Israel and Japan
• RFC 2045, RFC 2046, RFC 2047, RFC 2048 and RFC 2049 together describe the
Multipurpose Internet Mail Extensions, better known as MIME They define how to
encode non US-ASCII text and attachments so that they can be represented in ASCII and hence sent by RFC 2822, and also how to divide the single RFC 2822 body into multiple parts using ASCII separators
MIME is one area in which UNIX is weak Many UNIX users consider themselves Real Men who don’t need these fancy toys This is a pity In countries like Germany, people can get by with ASCII, but that doesn’t work in Japan, Israel or Russia
In case you’re wondering, German has seven special characters Ä, Ö, Ü, ä, ö, ü and ß ß is lower case only There is a national standard defining how to represent these characters in US-ASCII: replace the characters with Ae, Oe, Ue, ae, oe, ue and ss respectively.
There are plenty of good MIME-aware mail readers available for UNIX It’s a good idea to use one On the other hand, if your target audience typically does not use MIME-aware mailers, you should probably avoid sending MIME messages
Mail user agents
A mail user agent is a program that interfaces between the user and the mail system It
allows the user to read, forward and reply to incoming mail, and to send his own mail
Beyond that, it usually has facilities for creating and maintaining folders, where you can
keep received mail messages For most UNIX MUAs, a folder is the same thing as a file, but some MUAs, which we won’t discuss here, keep mail messages as individual files, and the folder corresponds to a directory
The oldest MUA you’re likely to meet is mail It’s a very basic, character-oriented
program, but nevertheless it has its advantages You can use it in scripts to send mail For example, if you have a job running and producing copious output, where you want to save the output, you might normally write something like:
$ longjob 2>&1 > logfile
This command runs longjob The sequence 2>&1 redirects the error output to the standard output, and the>writes them to the file logfile While this is a good way to
solve the problem, you might find that you have a lot of such jobs, or that you tend to forget the log files and leave them cluttering up your disks An alternative is to send yourself mail You can do this with the following command:
mua.mm,v v4.12 (2003/04/02 04:07:59)
Trang 3$ longjob 2>&1 | mail me
In this case, me is your user ID When the job finishes, you get a mail message with the
output of the commands cron (see page 151) uses this method to send you its output.
Other MUAs
mail has a number of limitations: it can’t deal very well with long mail messages, it’s
difficult to keep an overview of large quantities of mail, like most people seem to
accumulate, and it can’t handle MIME.
Many more sophisticated mailers have been written since mail Some of the more
popular ones, which are also available in the Ports Collection, are:
• elm is one of the oldest full-screen mailers Its age is showing: it has a few annoying
problems that make it less desirable now that there’s a choice
• pine is not elm—that’s what the acronym stands for It’s quite like elm, nonetheless.
• mutt is also similar to elm and pine It’s my current favourite, and we’ll look at it in
the next section
• exmh is built on Rand’s mh MUA Some people like it, but it seems relatively easy
to configure it to mutilate messages
• xfmail is an X-based mailer, which you might prefer to the text-based mailers we’re
talking about here
• sylpheed is a more recent X-based mailer You may prefer it to xfmail.
Files, folders or directories?
There are two schools of thought about how to store mail:
• Traditional MUAs represent folders as files They store all the messages in a folder
in that single file This is sometimes called the mbox method mail, elm and pine
do it this way
• Other MUAs, including exmh, xfmail and sylpheed, represent a folder as a directory.
Each message in the folder is then a file by itself
• mutt can use either method, but the default is the mbox method.
Which method should you use? Both have their advocates The directory and file approach is more robust (if you trash a file, you only lose one message, not all of them), and it enables you to have the same message in multiple folders On the other hand, it
also imposes a lot higher overhead Current versions of ufs, at least on FreeBSD, have a
default block size of 16 kB and a fragment size of 2 kB That means that all files have a length that is a multiple of 2 kB, and so the average waste of space is 1 kB In addition, each file uses an inode If you have a lot of mail, this can add up to a lot of wasted space For example, I currently have 508,649 saved mail messages, which take up a total of 2.1
Trang 4Files, folders or directories? 472
GB, almost exactly 4 kB per message If I stored them in a directory structure, I would lose about another 500 MB of space, or 25% The file system on which the messages are stored is 9.5 GB in size and has 1.2 million inodes; nearly half of them would be used for the mail messages
mutt
In this section, we’ll take a detailed look at mutt Start it by typing in its name Like most UNIX mailers, mutt runs on a character-oriented terminal, including of course an
xterm We’ll take a look into my mailbox By default, when starting it up you get a
display like the one shown in Figure 26-1
Figure 26-1: mutt main menu
mutt sets reverse video by default You can change the way it displays things, however.
On page 479 we’ll see how to change it to the style shown in one shown in Figure 26-2 This display shows a number of things:
• The line at the top specifies the name of the file (‘‘folder’’) that contains the mail
messages (/var/mail/grog), the number of messages in the folder, and its size It also states the manner in which the messages are sorted: first by threads, then by date.
We’ll look at threads further down
• The bottom line gives a brief summary of the most common commands Each
command is a single character You don’t need to press Enter to execute the
command
• The rest of the screen contains information about the messages in the folder The first column gives the message a number, then come some flags:
• In the first column, we can seernext to some messages This indicates that I have already replied to these messages
mua.mm,v v4.12 (2003/04/02 04:07:59)
Trang 5Figure 26-2: mutt main menu
• In the same column,N signalizes a new message (an unread message that has arrived after the last invocation of mutt finished).
• The symbolDmeans that the message has been marked for deletion It won’t be
deleted until you leave mutt or update the display with the$command, and until then you can undelete it with theucommand
• The symbol+means that the message is addressed to me, and only to me We’ll
see below how mutt decides who I am.
• The symbolTmeans that the message is addressed to me and other people
• The symbol Cmeans that the message is addressed to other people, and that I have been copied
• The symbolFmeans that the message is from me
• The symbol*means that the message is tagged: certain operations work on all
tagged messages We’ll look at that on page 478
• The next column is the date (in international notation in this example, but it can be changed)
• The next column is the name of the sender, or, if I’m the sender, the name of the recipient
• The next column is the name of the recipient This is often me, of course, but frequently enough it’s the name of a mailing list You’ll notice that this is a column I have added; it’s not in the default display
• The next column gives the size of the message The format is variable: you can specify number of lines (as in the example), or the size in kilobytes
Trang 6Files, folders or directories? 474
• The last column is usually the subject For messages 56 to 61, it’s a series of line
drawings This is threading, and it shows a relationship between a collection of
messages on the same topic Message 56 was the original message in the thread, message 57 is a reply to message 56, and so on Messages 60 and 61 are both replies
to message 59 mutt automatically collects all messages in a thread in one place.
You’ll notice in the example that the lines are of different intensity In the original, these are different colours, and they’re a matter of personal choice; they highlight specific kinds
of message I use different colours to highlight messages on different topics If you’re
interested in the exact colours, see http://ezine.daemonnews.org/200210/ports.html,
which contains an early version of this text
Message 52 is appears to be in reverse video In fact, it’s in white on a blue background,
a colour I don’t use for anything else This is the cursor, which you can position either with the cursor up and cursor down keys, or with the vi-like commandsj(move down) or
k (move up) In the default display, it is in normal video (i.e not reversed, or doubly reversed) You can also move between pages with the left and right cursor commands Many commands, such asr(reply) or Enter (read), operate on the message on which the cursor is currently positioned For example, if you press Enter at this point, you’ll see a
display like that in Figure 26-3
Figure 26-3: mutt message display
Here, the display has changed to show the contents of the message The top line now tells you the sender of the message, the subject, and how much of the message is displayed, in this case 50% As before, the bottom line tells you the most common commands you might need in this context: they’re not all the same as in the menu display The message itself is divided into three parts: the first 6 lines are a selection of the
headers The headers can be quite long They include information on how the message
got here, when it was sent, who sent it, who it was sent to, and much more We’ll look at them in more detail on page 482
The headers are separated from the message body by an empty line The first part, which
mua.mm,v v4.12 (2003/04/02 04:07:59)
Trang 7mutt displays in bold, is quoted text: by putting a>character before each line, the sender has signalized that the text was written by another person, often the person to whom it is addressed: this message is a reply, and the text is what he is replying to Normally there
is an attribution above the text, but it’s missing in this example We’ll see attributions below in the section on replying
If the message is longer than one screen, press SPACE to page down and -(hyphen) to page up In general, a 25 line display is inadequate for reading mail On an X display, choose as high a window as you can
Replying to a message
To reply to a message, simply pressr mutt starts your favourite editor for you How
does it know which one? If you set yourEDITORenvironment variable to the name of
your editor, it starts that editor; otherwise it starts vi You can also specify it in the mutt
configuration file, which we’ll look at below
In this case, we start emacsclient emacsclient isn’t really an editor at all: it simply finds
an Emacs process and latches on to it This is much faster than starting a new instance of
Emacs: it’s practically instantaneous, whereas even on fast modern machines, starting Emacs causes a brief delay To exit the client, you use the key combinationc-x c-#
Before entering any text, the editor screen looks like Figure 26-4 You’ll notice that mutt
automatically ‘‘quotes’’ the text The original text started with:
>I think I now understand the problem here Try the following patch
>and tell me if it solves the problem:
>
>+++ vinumio.c 19 Sep 2002 05:10:27 -0000
Tried patch System no longer reads ad0h/ad2h, but after the second
’vinum start’, the system shows 0 drives (’vinum ld’ lists nothing.)
This message itself starts with quoted text, which indicates that it was written by somebody else Normally there should be a line at the top stating who wrote it, but it’s missing here The text from the submitter starts withTried patch When you reply, however, all this text is quoted again, so what you see on the screen is the display of Figure 26-4 Here you see that the first line attributes the text below You’ll notice that
this reply also includes a selection of headers for the outgoing message This can be very
convenient if you want to tailor your headers to the message you’re sending, or just to add other recipients
Trang 8Replying to a message 476
Figure 26-4: Replying to a message: initial state
In this case, since it’s in reply to a technical question, I change theFrom:header to my
FreeBSD.org address and copy the original mailing list I also remove irrelevant text and add a reply, as shown in Figure 26-5 It wasn’t necessary to reformat the original text, since it was relatively short The quoting method makes lines grow, though, and many MUAs hav e difficulty with long lines, so it’s a good idea to reformat long
paragraphs See http://www.lemis.com/email.html for more details.
In this example, I reply with ther(reply to sender) command I could also do a group
reply with thegkey, which would include all the original recipients, so it wouldn’t be necessary to add the mailing list again
Next, I leave the editor withc-x c-# and return to the screen in Figure 26-6 Here I have another opportunity to change some of the headers before sending the message You’ll note what seem to be a couple of additional headers in this display:PGPandFcc:
In fact, they’re not headers at all PGPstates what parts of the message, if any, should be
encrypted with pgp or gpg In this case, Clear (the default) means not to encrypt anything
Fcc:is also not a header It specifies the name of a folder in which to save the outgoing message We’ll look at folders in the next section
After making any further changes to the headers, I send the message with the y
command, after which I return to the previous display
mua.mm,v v4.12 (2003/04/02 04:07:59)
Trang 9Figure 26-5: Replying to a message: after editing
Figure 26-6: Replying to a message: ready to send
Trang 10Replying to a message 478
Using folders
As I mentioned, mutt can handle multiple folders By default, it starts with your incoming mail folder, sometimes called an inbox On BSD, it is a single file in /var/mail
with the same name as your user ID We saw that above at the top of the index screen:
mine is called /var/mail/grog.
mutt stores other folders as single files in the directory ˜/Mail, in other words a
subdirectory of your home directory Many MUAs use this method, but not all of them:
some use the directory ˜/mail instead By default, when you write a mail message, the
outgoing message gets copied to a file in this directory In the previous section, the
Compose menu contained the pseudo-header Fcc: =jbozza This refers to the file
˜/Mail/jbozza: the shorthand=refers to the mail directory
To keep incoming mail, you use thes(save) command, which sets a default folder name from the name of the sender, the same name as when saving sent messages You can thus reply a message, saving a copy in the folder, then save the original message, without explicitly mentioning a folder name at all
To read messages in a folder, you can tell mutt to read it directly on startup:
$ mutt -f =fred
Alternatively you can change folders with theccommand
Deleting messages
Once you’ve finished reading a message, you may want to delete it You can do this by enteringd TheDflag appears on the left of the line, but nothing much else happens The
message doesn’t get deleted until you exit mutt, or until you enter$
When you save a message to a folder, it is automatically deleted from the current folder
If you don’t want to do that, or if you have accidentally deleted a message, you can
undelete it by enteringu
Finished reading a thread? You can delete the entire thread by enteringˆD (Control-D).
Ta g ging messages
We’v e seen that you can delete an entire thread with a single keystroke What about other operations on multiple messages? There are a couple of useful possibilities You select the messages under the cursor by enteringt In the example above, messages 51 and 64 are tagged You can reply to all tagged messages in one reply by pressing;r In this
case, mutt ignores the message under the cursor and replies only to the tagged messages,
reply to all people on theTo:headers of each message Similarly, you can do a group reply to all the tagged messages with;g, and you can delete them all with;d
mua.mm,v v4.12 (2003/04/02 04:07:59)