Опубликован: 06.08.2012 | Уровень: специалист | Доступ: платный
Лекция 26:

Electronic mail: clients

< Лекция 25 || Лекция 26: 12345 || Лекция 27 >
Аннотация: Mail formats; Mail user agents; Files, folders or directories?; Creating a new message; Replying to a message; Using folders; Deleting messages; Tagging messages; Configuring mutt; Mail aliases; Mail headers.
Ключевые слова: mail, method, net, AS, with, network, software, email, Internet, CAN, MOST, important, imposing, abuse, mail message, binary file, aware, USER, AND, system, read, forward, reply, incoming, send, WHERE, Unix, folder, individual, directory, standard output, clutter, accumulate, sophisticated, full-screen, store, approach, robust, if, trash, ONE, NOT, ALL, hand, overhead, default, block size, fragment, size, length, average, space, addition, inode, this, Add, example, total, PER, directory structure, half, used, reverse video, undelete, mailing list, kilobyte, off-topic message, threaded message, intensive, read operation, current position, message body, hyphen, create, new, editor, set, environment variable, look, CASE, latch, instance, even, fast, delay, exit, client, key combination, fill, recipient, appropriate, enter, text, Line, FROM, Actions, NEXT, section, screen, LIKE, original, else, Top, First, selection, very, convenience, technical, question, change, header, Copy, remove, irrelevant, reformat, short, long, IDEA, SEE, sender, Command, include, leave, return, additional, FCC, fact, encrypt, save, previous, BSD, ID, SAW, INDEX, subdirectory, home directory, Write, Menu, shorthand, startup, DELETE, Left, GET, thread, entire, keystroke, useful, CURSOR, tagged, group, running, override, abbreviate, e-mail address, string, regular expression, determine, account, difference, layout, color, custom, format string, information, bottom, international, ignore, EXCEPT, specified, foreground color, status bar, find, option, setting, contact, separate, format, angle brackets, parentheses, VALUES, HAVING, local time, deliver, time zone, coincidence, plain ascii, impersonation, formulate, proprietary, illegal, mailer

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 user interface to the mail system is the client, the Mail User Agent, or MUA. It interacts with the user and handles incoming and outgoing mail. People frequently use the word mailer when referring to MUAs. In this chapter we'll look at my favorite 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, "Electronic mail: servers" , 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.
  • 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 now days, 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.

    A number of UNIX MUAs have inadequate MIME support. Find one which does the job properly. On the other hand, if your target audience typically does not use MIME-aware MUAs, a void 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. 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 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 mail to yourself. You can do this with the following command:

$ 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 doesn'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 MUAs 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 MUAs. 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, none the less.
  • mutt is also similar to elm and pine. It's my current favorite, 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 MUA, which you might prefer to the text-based MUAs we're talking about here.
  • sylpheed is a more recent X-based MUA. 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 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.

< Лекция 25 || Лекция 26: 12345 || Лекция 27 >
Бехзод Сайфуллаев
Бехзод Сайфуллаев
Узбекистан, Бухара, Бухарский институт высоких технологий, 2013
Василь Остапенко
Василь Остапенко