2.4.4 Reading Mail

To read messages from a given mailbox, use one of the following ways of invoking mail:

mail

To read messages from your system mailbox.

mail -f
mail --file

To read messages from your mailbox (‘$HOME/mbox’). If the ‘--user’ option (see below) is also given, read messages from that user's ‘mbox’.

mail -f path_to_mailbox
mail --file path_to_mailbox

To read messages from the specified mailbox.

mail -u user
mail --user=user

To read messages from the system mailbox belonging to user.

Please note, that usual mailbox permissions won't allow you to use the last variant of invocation, unless you are a super-user. Similarly, the last but one variant is also greatly affected by the permissions the target mailbox has.

Notice that path_to_mailbox is not an argument to ‘--file’ (‘-f’) option, but rather the first non-optional argument on the command line. Therefore, the following three invocations are equivalent:

 
$ mail -fin mymbox
$ mail -f mymbox -in
$ mail --file -in mymbox
$ mail --file -i mymbox -n

Additionally, for conformance to the GNU standards, the following form is also accepted:

 
$ mail --file=mymbox -i -n

Unless you have started mail with ‘--norc’ command line option, it will read the contents of the system-wide configuration file. Then it reads the contents of user configuration file, if any. For detailed description of these files, see Personal and System-wide Configuration Files. After this initial setup, mail displays the first page of header lines and enters interactive mode. In interactive mode, mail displays its prompt (‘?’, if not set otherwise) and executes the commands the user enters.

Quitting the Program

Following commands quit the program:

quit

Terminates the session. If mail was operating upon user's system mailbox, then all undeleted and unsaved messages that have been read and are not marked with hold flag are saved to the user's mbox file (‘$HOME/mbox’). The messages, marked with delete are removed. The program exits to the Shell, unless saving the mailbox fails, in which case user can escape with the exit command.

exit
ex
xit

Program exits to the Shell without modifying the mailbox it operates upon.

Typing EOF (‘C-D’) alone is equivalent to ‘quit’.

Obtaining Online Help

Following commands can be used during the session to request online help:

help [command]
hel [command]
? [command]

Display detailed command synopsis. If no command is given, help for all available commands is displayed.

list
*

Print a list of available commands.

version
ve

Display program version.

warranty
wa

Display program warranty statement.

Moving Within a Mailbox

^

Move to the first undeleted message.

$

Move to the last undeleted message.

next
n

Move to the next message.

previous
prev

Move to the previous message.

Changing Mailbox/Directory

cd [dir]
chdir [dir]
ch [dir]

Change to the specified directory. If dir is omitted, $HOME is assumed.

file [mailbox]
fi [mailbox]
folder [mailbox]
fold [mailbox]

Read in the contents of the specified mailbox. The current mailbox is updated as if quit command has been issued. If mailbox is omitted, the command prints the current mailbox name followed by the summary information regarding it, e.g.:

 
& fold
"/var/spool/mail/gray": 23 messages 22 unread

Controlling Header Display

To control which headers in the message should be displayed, mail keeps two lists: a retained header list and an ignored header list. If retained header list is not empty, only the header fields listed in it are displayed when printing the message. Otherwise, if ignored header list is not empty, only the headers not listed in this list are displayed. The uppercase variants of message-displaying commands can be used to print all the headers.

The following commands modify and display the contents of both lists.

discard [header-field-list]
di [header-field-list]
ignore [header-field-list]
ig [header-field-list]

Add header-field-list to the ignored list. When used without arguments, this command prints the contents of ignored list.

retain [header-field-list]
ret [header-field-list]

Add header-field-list to the retained list. When used without arguments, this command prints the contents of retained list.

Displaying Information

=

Displays the current message number.

headers [msglist]
h [msglist]

Lists the current pageful of headers.

from [msglist]
f [msglist]

Lists the contents of ‘From’ headers for a given set of messages.

z [arg]

Presents message headers in pagefuls as described for headers command. When arg is ‘.’, it is generally equivalent to headers. When arg is omitted or is ‘+’, the next pageful of headers is displayed. If arg is ‘-’, the previous pageful of headers is displayed. The latter two forms of z command may also take a numerical argument meaning the number of pages to skip before displaying the headers. For example:

 
& z +2

will skip two pages of messages before displaying the header summary.

size [msglist]
si [msglist]

Lists the message number and message size in bytes for each message in msglist.

folders

Displays the value of folder variable.

summary
su

Displays current mailbox summary. E.g.:

 
& summary
"/var/spool/mail/gray": 23 messages 22 unread

Displaying Messages

print [msglist]
p [msglist]
type [msglist]
t [msglist]

Prints out the messages from msglist. The variable crt determines the minimum number of lines the body of the message must contain in order to be piped through pager command specified by environment variable PAGER. If crt is set to a numeric value, this value is taken as the minimum number of lines. Otherwise, if crt is set without a value then the height of the terminal screen is used to compute the threshold. The number of lines on screen is controlled by screen variable.

Print [msglist]
P [msglist]
Type [msglist]
T [msglist]

Like print but also prints out ignored header fields.

decode [msglist]
dec [msglist]

Print a multipart message. The decode command decodes and prints out specified message parts. E.g.

 
& decode 15[2]
+---------------------------------------
| Message=15[2]
| Type=message/delivery-status
| encoding=7bit
+---------------------------------------
Content-Type: message/delivery-status
...
top [msglist]
to [msglist]

Prints the top few lines of each message in msglist. The number of lines printed is controlled by the variable toplines and defaults to five.

pipe [msglist] [shell-command]
| [msglist] [shell-command]

Pipe the contents of specified messages through shell-command. If shell-command is empty but the string variable cmd is set, the value of this variable is used as a command name.

struct [msglist]

Prints the MIME structure of each message from msglist. Empty msglist means current message.

Example:

 
& struct 2
2      multipart/mixed            14k
2[1]   text/plain                 296
2[2]   application/octet-stream    5k
2[3]   text/x-diff                31k

Marking Messages

tag [msglist]
ta [msglist]

Tag messages. The tagged messages can be referred to in message list using ‘:t’ notation.

untag [msglist]
unt [msglist]

Clear tags from specified messages. To untag all messages tagged so far type

 
& untag :t
hold [msglist]
ho [msglist]
preserve [msglist]
pre [msglist]

Marks each message to be held in user's system mailbox. This command does not override the effect of delete command.

Disposing of Messages

delete [msglist]
d [msglist]

Mark messages as deleted. Upon exiting with quit command these messages will be deleted from the mailbox. Until the end of current session the deleted messages can be referred to in message lists using :d notation.

undelete [msglist]
u [msglist]

Clear delete mark from the specified messages.

dp [msglist]
dt [msglist]

Deletes the current message and prints the next message. If msglist is specified, deletes all messages from the list and prints the message, immediately following last deleted one.

Saving Messages

save [[msglist] file]
s [[msglist] file]

Takes a message list and a file name and appends each message in turn to the end of the file. The name of file and number of characters appended to it is echoed on the terminal. Each saved message is marked for deletion as if with delete command, unless the variable keepsave is set.

Save [msglist]
S [msglist]

Like save, but the file to append messages to is named after the sender of the first message in msglist. For example:

 
& from 14 15
 U  14 smith@noldor.org Fri Jun 30 18:11  14/358   The Save c
 U  15 gray@noldor.org  Fri Jun 30 18:30  8/245    Re: The Sa
& Save 14 15
"smith" 22/603

i.e., 22 lines (603 characters) have been appended to the file “smith”. If the file does not exist, it is created.

write [[msglist] file]
w [[msglist] file]

Similar to save, except that only message body (without the header) is saved.

Write [msglist]
W [msglist]

Similar to Save, except that only message body (without the header) is saved.

mbox [msglist]
mb [msglist]
touch [msglist]
tou [msglist]

Mark list of messages to be saved in the user's mailbox (‘$HOME/mbox’) upon exiting via quit command. This is the default action for all read messages, unless you have variable hold set.

copy [[msglist] file]
c [[msglist] file]

Similar to save, except that saved messages are not marked for deletion.

Copy [msglist]
C [msglist]

Similar to Save, except that saved messages are not marked for deletion.

Editing Messages

These command allow to edit messages in a mailbox. Please note, that modified messages currently do not replace original ones. i.e. you have to save them explicitly using your editor's save command if you do not want the effects of your editing to be lost.

edit [msglist]
e [msglist]

Edits each message in msglist with the editor, specified in EDITOR environment variable.

visual [msglist]
v [msglist]

Edits each message in msglist with the editor, specified in VISUAL environment variable.

Aliasing

alias [alias [address...]]
a [alias [address...]]
group [alias [address...]]
g [alias [address...]]

With no arguments, prints out all currently-defined aliases. With one argument, prints out that alias. With more than one argument, creates a new alias or changes an old one.

unalias [alias...]
una [alias...]

Takes a list of names defined by alias commands and discards the remembered groups of users. The alias names no longer have any significance.

alternates name...
alt name...

The alternates command is useful if you have accounts on several machines. It can be used to inform mail that the listed addresses are really you. When you reply to messages, mail will not send a copy of the message to any of the addresses listed on the alternates list. If the alternates command is given with no argument, the current set of alternate names is displayed.

Replying

mail [address...]
m [address...]

Switches to compose mode. After composing the message, sends messages to the specified addresses.

reply [msglist]
respond [msglist]
r [msglist]

For each message in msglist, switches to compose mode and sends the composed message to the sender and all recipients of the message.

Reply [msglist]
Respond [msglist]
R [msglist]

Like reply, except that the composed message is sent only to originators of the specified messages.

Notice, that setting mail variable flipr (see section How to Alter the Behavior of mail) swaps the meanings of the two above commands, so that reply sends the message to the sender and all recipients of the message, whereas Reply sends it to originators only.

followup [msglist]
fo [msglist]

Switches to compose mode. After composing, sends the message to the originators and recipients of all messages in msglist.

Followup [msglist]
F [msglist]

Similar to followup, but reply message is sent only to originators of messages in msglist.

To determine the sender of the message mail uses the list of sender fields (see Controlling Sender Fields). The first field from this list is looked up in message headers. If it is found and contains a valid email address, this address is used as the sender address. If not, the second field is searched and so on. This process continues until a field is found in the headers, or the sender field list is exhausted, whichever happens first.

If the previous step did not determine the sender address, the address from SMTP envelope is used.

Let's illustrate this. Suppose your mailbox contains the following:

 
 U  1 block@helsingor.org  Fri Jun 30 18:30  8/245    Re: The Sa
& Print 1
From: Antonius Block <block@helsingor.org>
To: Smeden Plog <plog@helsingor.org>
Date: Tue, 27 Apr 2004 13:23:41 +0300
Reply-To: <root@helsingor.org>
Subject: News

Hi

Now, you issue the following commands:

 
& sender mail-followup-to reply-to from
& reply
To: <root@helsingor.org>
Subject: Re: News

As you see, the value of Reply-To field was taken as the sender address.

Now, let's try the following command sequence:

 
# Clear the sender list
& nosender
# Set new sender list
& sender From

Now, the From address will be taken:

 
& reply
To: Antonius Block <block@helsingor.org>
Subject: Re: News

Controlling Sender Fields

Commands sender and nosender are used to manipulate the contents of the sender field list.

If the command sender is used without arguments, it displays the contents of the sender field list. If arguments are given, each argument is appended to the sender field list. For example:

 
& sender
Sender address is obtained from the envelope
& sender mail-followup-to reply-to
& sender
mail-followup-to
reply-to
& sender from
& sender
mail-followup-to
reply-to
from

Command nosender is used to remove items from the sender field list:

 
& sender
mail-followup-to
reply-to
from
& nosender reply-to
& sender
mail-followup-to
from

When used without arguments, this command clears the list:

 
& nosender
Sender address is obtained from the envelope

Incorporating New Mail

The incorporate (inc) command incorporates newly arrived messages to the displayed list of messages. This is done automatically before returning to mail command prompt if the variable autoinc is set.

Shell Escapes

To run arbitrary shell command from mail command prompt, use shell (sh) command. If no arguments are specified, the command starts the user login shell. Otherwise, it uses its first argument as a file name to execute and all subsequent arguments are passed as positional parameters to this command. The shell command can also be spelled as !.