GNU Mailutils Manual

Short Contents

Table of Contents


Next: , Previous: (dir), Up: (dir)

Appendices

Indices


Next: , Previous: Top, Up: Top

1 Introduction

gnu Mailutils contains a series of useful mail clients, servers, and libraries. These are the primary mail utilities of the GNU system. Specifically, this package contains a POP3 server, an IMAP4 server, and a Sieve mail filter. It also provides a POSIX `mailx' client, and a collection of other tools. The central library is capable of accessing different mailbox formats and mailers as well as off of local or remote POP3 and IMAP4 servers.

This software is part of the GNU Project and belongs to the Free Software Foundation. All libraries are licensed using the GNU LGPL. The documentation is licensed under the GNU FDL, and everything else is licensed using the GNU GPL.

Why use this package?

This package started off to try and handle large mailbox files more gracefully then current POP3 servers did. While it handles this task, it also allows you to support a variety of different mailbox formats without any real effort on your part. Also, if a new format is added at a later date, your program will support that new format automatically as soon as it is compiled against the new library.


Next: , Previous: Introduction, Up: Top

2 Mailutils Programs

gnu Mailutils provides a set of programs for handling the e-mail.


Next: , Up: Programs

2.1 Mailutils Configuration File

There are some command line options that are used so often that it is inconvenient to specify them in the command line each time you run a Mailutils utility. The configuration files provide a way to add default command line arguments without having to type them in the command line. Upon startup, each Mailutils utility scans and processes the contents of the three startup files, none of which are required to exist:

  1. the site-wide configuration file

    mailutils.rc, found in your your system configuration directory (usually /etc or /usr/local/etc).

  2. the user-specific configuration file

    Usually ~/.mailutils, unless ~/.mailutils is a directory, in which case ~/.mailutils/mailutils is used.

  3. the programs-specific configuration file

    Usually ~/.mu.programrc, unless ~/.mailutils is a directory, in which case ~/.mailutils/programrc is used (where program means the program name).

These files have simple line-oriented syntax. Comments begin with the pound sign (‘#’) and extend through the end of the line 1. Very long lines may be split across several lines by escaping final newline with a backslash (‘\’) character.

In the non-program-specific configuration files, any configuration line must start with a tag. In the program-specific configuration file the tag must not be present, all options are for that specific program.

A tag is either a name of a particular Mailutils utility or option group, prefixed with colon (‘:’). The command line options common for several Mailutils programs are divided into option groups or capabilities, e.g. the options --mail-spool and --lock-flags form group ‘mailbox’. These groups are discussed in detail below.

When processing the non-program-specific configuration files, a Mailutils utility selects those lines whose tag is either the name of that utility or the name of the option group supported by it. In the program-specific configuration file, all lines are selected. For each line found, its tag (if present) is stripped away, and the rest of the line is split up into words. These words are regarded as command line options and are inserted to the program arguments before any options from the command line. Thus the options from .mailutils take precedence over those from mailutils.rc, and the options from the command line take precedence over those from all three configuration files.

The word splitting occurs at whitespace characters and is similar to that performed by the shell. If an option must contain embedded whitespace, it should be enclosed in a pair of quotes (either double or single quotes).


Next: , Up: configuration

2.1.1 Common

Each program understands the following informational options:

-u
--usage
Display a short usage message and exit.
-h
--help
Display help message and exit.
-L
--license
Display gnu General Public License and exit.
-v
--version
Display program version and exit.


Next: , Previous: common, Up: configuration

2.1.2 Mailbox

Option group ‘mailbox’ consists of options used to specify the location of the mail spool, and the locking strategy.

-m path
--mail-spool=path
Set path to the mailspool directory
--lock-flags=flags
Set the default mailbox lock flags (E=external, R=retry, T=time, P=pid).


Next: , Previous: mailbox, Up: configuration

2.1.3 Mailer

This option group overrides the default mailer URL (sendmail:).

-m url
--mailer url


Next: , Previous: mailer, Up: configuration

2.1.4 Address

Option group ‘address’ consists of options used to specify how to qualify email addresses.

An unqualified address (one without an @) is qualified by appending @defaultdomain. defaultdomain is the return of gethostname(), or the result of gethostbyname() on the return of gethostname() (if the DNS lookup is successful).

If the email address of the current user is needed, either the address set by --email-addr is returned, or the current uid is looked up in the user database, and qualified with the defaultdomain.

-E email
--email-addr=email
Set the current user's email address, this it makes more sense to use this in one of the per-user configuration files.
-D domain
--email-domain=domain
Set the default email domain, this might make sense to use in either the global or one of the per-user configuration files.


Next: , Previous: address, Up: configuration

2.1.5 Daemon

-d[number]
--daemon[=number]
Run in standalone mode. An optional number specifies the maximum number of child processes the daemon is allowed to fork. When it is omitted, it defaults to 20 processes. Please note, that there should be no whitespace between the -d and its parameter.
-i
--inetd
Run in inetd mode.
-p number
--port number
Listen on given port number. This option is meaningful only in standalone mode. It defaults to port 143.
-t number
--timeout number
Set idle timeout to given number of seconds. The daemon breaks the connection if it receives no commands from the client within that number of seconds.


Next: , Previous: daemon, Up: configuration

2.1.6 Auth

These options control the authorization and authentication module lists. For a description of authentication concepts, refer to See authentication.

--authorization modlist
This option allows to set up a list of modules to be used for authorization. modlist is a colon-separated list of modules. Valid modules are:
system
User credentials are retrieved from the system user database (/etc/password).
sql
User credentials are retrieved from the sql database. The set of --sql- options (see below) is used to configure access to the database.
virtdomain
User credentials are retrieved from a “virtual domain” user database.

--authentication modlist
This option allows to set up a list of modules to be used for authentication. modlist is a colon-separated list of modules. Valid modules are:
generic
The generic authentication type. User password is hashed and compared against the hash value returned in authorization stage.
system
The hashed value of the user password is retrieved from /etc/shadow file on systems that support it.
sql
The hashed value of the user password is retrieved from the sql database using query supplied by --sql-getpass option (see below).
pam
The user is authenticated via pluggable authentication module (pam). The pam service name to be used is configured via --pam-service option (see below).

--pam-service name
When compiled with pam support, this option specifies the name of pam service to be used when authenticating.

The following options exist in this group if the package was configured with --enable-sql option. They take effect only if the ‘sql’ module is used in authentication and/or authorization.

--sql-interface iface
Specify sql interface to use. Iface is either ‘mysql’ or ‘postgres’. This allows to select sql subsystem on runtime if mailutils was compiled with support for several sql drivers.

If this option is omitted, mailutils will use the first available sql driver.

--sql-host name
Name or IP of MySQL server to connect to.
--sql-user name
sql user name
--sql-passwd string
sql connection password
--sql-db string
Name of the database to connect to.
--sql-port number
Port to use
--sql-getpwnam query
sql query to retrieve a passwd entry based on username
--sql-getpwuid query
sql query to retrieve a passwd entry based on user ID
--sql-getpass query
sql query to retrieve a password from the database


Next: , Previous: auth, Up: configuration

2.1.7 Encryption

These options control TLS/SSL encryption in imap4d and pop3d daemons.

--ssl-cert file
This option specifies the file name of the server side SSL certificate (accepts PEM format).
--ssl-key file
This option specifies the file name of the server side private SSL key (accepts PEM format). The key must be protected with 0600 file permissions (u=rw,g=,o=), otherwise imap4d or pop3d daemons will refuse to support TLS/SSL encryption.
--ssl-cafile file
This option specifies a file containing the list of trusted CAs (PEM list) in order to verify client's certificates. This option is not required.


Next: , Previous: encryption, Up: configuration

2.1.8 Logging

--log-facility facility
Output logs to the specified syslog facility. The following facility names are recognized: ‘user’, ‘daemon’, ‘mail’, ‘auth’ and ‘local0’ through ‘local7’. These names are case-insensitive.


Next: , Previous: logging, Up: configuration

2.1.9 Sieve Specific Options

The following options comprise this group:

-I dir
--includedir=dir
Append directory dir to the list of directories searched for include files.
-L dir
--libdir=dir
Append directory dir to the list of directories searched for library files.


Previous: sieve group, Up: configuration

2.1.10 A Sample Configuration File

The following configuration file specifies that all Mailutils programs should use /var/spool/mail as a local mailspool directory. Programs performing authentication will use pam service ‘mailutils’. All programs, except imap4d will issue log messages via ‘mail’ facility, imap4d will use facility ‘local1’.

     :mailbox --mail-spool /var/spool/mail
     :auth --authentication pam --pam-service mailutils
     :logging --log-facility mail
     imap4d --daemon=20 --timeout=1800 --log-facility local1


Next: , Previous: configuration, Up: Programs

2.2 Authorization and Authentication Principles

Some mail utilities provide access to their services only after verifying that the user is actually the person he is claiming to be. Such programs are, for example, pop3d and imap4d. The process of the verification is broken down into two stages: authorization and authentication. In authorization stage the program retrieves the information about a particular user. In authentication stage, this information is compared against the user-supplied credentials. Only if both stages succeed is the user allowed to use the service.

A set of modules is involved in performing each stage. For example, the authorization stage can retrieve the user description from various sources: system database, sql database, virtual domain table, etc. Each module is responsible for retrieving the description from a particular source of information. The modules are arranged in a module list. The modules from the list are invoked in turn, until either a one of them succeeds or the list is exhausted. In latter case the authorization fails. Otherwise the data returned by the succeeded module are used in authentication.

Similarly, authentication may be performed in several ways. The authentication modules are also grouped in a list. Each module is tried in turn until either a module succeeds, in which case the authentication succeeds, or the end of the list is reached.

We represent the module lists as column-separated lists of module names. For example, the authorization list

     system:sql:virtdomains

means that first the system user database (/etc/password) is searched for a description of a user in question. If the search fails, the sql database is searched. Finally, if it also fails, the search is performed in the virtual domain database.

Note, that some authentication and/or authorization modules may be disabled when configuring the package before compilation. The names of the disabled modules are nevertheless available for use in runtime configuration options, but they represent a “fail-only” functionality, e.g. if the package was compiled without sql support then the module ‘sql’ in the above example will always fail, thus passing the execution on to the next module.

The modules available for use in authorization list are:

system
User credentials are retrieved from the system user database (/etc/password).
sql
User credentials are retrieved from the sql database. The set of --sql- options (see auth) is used to configure access to the database.
virtdomain
User credentials are retrieved from a “virtual domain” user database.

The modules available for use in authentication list are:

generic
The generic authentication type. User password is hashed and compared against the hash value returned in authorization stage.
system
The hashed value of the user password is retrieved from /etc/shadow file on systems that support it.
sql
The hashed value of the user password is retrieved from the sql database using query supplied by --sql-getpass option (see auth).
pam
The user is authenticated via pluggable authentication module (pam). The pam service name to be used is configured via --pam-service option (see auth)

Unless overridden by --authentication command line option, the list of authentication modules is:

     generic:system:pam:sql

Unless overridden by --authorization command line option, the list of authorization modules is:

     system:sql:virtdomains


Next: , Previous: authentication, Up: Programs

2.3 frm and from — List Headers from a Mailbox

GNU mailutils provides two commands for listing messages in a mailbox. These are from and frm.

frm

The frm command outputs a header information of the selected messages in a mailbox. By default, frm reads the user's system mailbox and outputs the contents of From and Subject headers for each message. If a folder is specified in the command line, the program reads that folder rather than the default mailbox.

The program uses following option groups: See mailbox.

The following command line options alter the behavior of the program:

-f string
--field string
Display the header named by string instead of From Subject pair.
-l
--to
Include the contents of To header to the output. The output field order is then: To From Subject.
-n
--number
Prefix each line with corresponding message number.
-Q
--Quiet
Be very quiet. Nothing is output except error messages. This is useful in shell scripts where only the return status of the program is important.
-q
--query
Print a message only if there are unread messages in the mailbox.
-S
--summary
Print a summary line.
-s attr
--status attr
Only display headers from messages with the given status. Attr may be one of the following: ‘new’, ‘read’, ‘unread’. It is sufficient to specify only first letter of an attr. Multiple -s options are allowed.
-t
--align
Tidy mode. In this mode frm tries to preserve the alignment of the output fields. It also enables the use of BIDI algorithm for displaying subject lines that contain text in right-to-left orientation (such as Arabic or Hebrew).

from

The from utility displays sender and subject of each message in a mailbox. By default, it reads the user's system mailbox. If the program is given a single argument, it is interpreted as a user name whose mailbox is to be read. Obviously, permissions are required to access that user's mailbox, so such invocations may be used only by superuser.

Option -f (--file) instructs the program to read the given mailbox.

The full list of options, supported by from follows:

-c
--count
Prints only a count of messages in the mailbox and exit.
-d
--debug
Prints additional debugging outut.
-s string
--sender=string
Prints only mail from addresses containing the supplied string. FIXME: only From: header is examined.
-f url
--file=url
Examine mailbox from the given url.


Next: , Previous: frm and from, Up: Programs

2.4 mail — Send and Receive Mail

Mail is an enhanced version of standard /bin/mail program. As well as its predecessor, it can be used either in sending mode or in reading mode. Mail enters sending mode when one or more email addresses were specified in this command line. In this mode the program waits until user finishes composing the message, then attempts to send it to the specified addresses and exits. See Composing Mail, for a detailed description of this behavior.

If the command line contained no email addresses, mail switches to reading mode. In this mode it allows to read and manipulate the contents of a mailbox. The URL of the mailbox to operate upon is taken from the argument of --file command line option. If it is not specified, the user's system mailbox is assumed. For more detail, see Reading Mail.


Next: , Up: mail

2.4.1 Invoking mail

General usage of mail program is:

           mail [option...] [address...]

If [address...] part is present, mail switches to mail sending mode, otherwise it operates in mail reading mode.

The program uses following option groups: See mailbox.

Mail understands following command line options:

-e
--exist
Return true if the mailbox contains some messages. Return false otherwise. This is useful for writing shell scripts.
-E command
--exec=command
Execute command before opening the mailbox. Any number of --exec options can be given. The commands will be executed after sourcing configuration files (see Mail Configuration Files), but before opening the mailbox.
--exec
-f[file]
--file[=file]
Operate on mailbox file. If this option is not specified, the default is user's system mailbox. If it is specified without argument, the default is $HOME/mbox. Please note, that there should be no whitespace between the short variant of the option (-f), and its parameter. Similarly, when using long option (--file), its argument must be preceded by equal sign.
-F
--byname
Save messages according to sender. Currently this option is not implemented.
-H
--headers
Print header summary to stdout and exit.
-i
--ignore
Ignore interrupts.
-m path
--mail-spool=path
Set path to the mailspool directory
-n
--norc
Do not read the system-wide mailrc file. See Mail Configuration Files.
-N
--nosum
Do not display initial header summary.
-p
--print
-r
--read
Print all mail to standard output. It is equivalent to issuing following commands after starting ‘mail -N’:
          print *
          quit

-q
--quit
Cause interrupts to terminate program.
-s subj
--subject=subj
Send a message with a Subject of subj. Valid only in sending mode.
-t
--to
Switch to sending mode.
-u user
--user=user
Operate on user's mailbox. This is equivalent to:
          mail -f/spool_path/user

with spool_path being the full path to your mailspool directory
(/var/spool/mail or /var/mail on most systems).

-?
--help
Display a help message.
--usage
Display a short usage summary.
-V
--version
Print program version and exit.


Next: , Previous: Invoking Mail, Up: mail

2.4.2 How to Specify Message Sets

Many mail commands such as print and delete can be given a message list to operate upon. Wherever the message list is omitted, the command operates on the current message.

The message list in its simplest form is one of:

.
Selects current message. It is equivalent to empty message list.
*
Selects all messages in the mailbox.
^
Selects first non-deleted message.
$
Selects last non-deleted message.

In its complex form, the message list is a comma or whitespace-separated list of message specifiers. A message specifier is one of

Message Number
This specifier addresses the message with the given ordinal number in the mailbox.
Message range
Message range is specified as two message numbers separated by a dash. It selects all messages with the number lying within that range.
Attribute specifier
An Attribute specifier is a colon followed by a single letter. The Attribute specifier addresses all messages in the mailbox that have the given attribute. These are the valid attribute specifiers:
:d
Selects all deleted messages.
:n
Selects all recent messages, i.e. the messages that have not been neither read not seen so far.
:o
Selects all messages that have been seen.
:r
Selects all messages that have been read.
:u
Selects all messages that have not been read.
:t
Selects all tagged messages.
:T
Selects all untagged messages.

Header match
The header match is a string in the form:
          [header:]/string/

It selects all messages that contain header field header matching given regexp. If the variable regexp is set, the string is assumed to be a POSIX regexp. Otherwise, a header is considered to match string if the latter constitutes a substring of the former (comparison is case-insensitive).

If header: part is omitted, it is assumed to be ‘Subject:’.

Message body match
The message body match is a string in the form:
          :/string/

It selects all messages whose body matches the string. The matching rules are the same as described under “Header match”.

A message specifier can be followed by message part specifier, enclosed in a pair of brackets. A message part specifier controls which part of a message should be operated upon. It is meaningful only for multipart messages. A message part specifier is a comma or whitespace - separated list of part numbers or ranges. Each part number can in turn be message part specifier, thus allowing for operating upon multiply-encoded messages.

The following are the examples of valid message lists:


Next: , Previous: Specifying Messages, Up: mail

2.4.3 Composing Mail

You can compose the message by simply typing the contents of it, line by line. But usually this is not enough, you would need to edit your text, to quote some messages, etc. Mail provides these capabilities through compose escapes. The compose escapes are single-character commands, preceded by special escape character, which defaults to ‘~’. The combination escape character + command is recognized as a compose escape only if it occurs at the beginning of a line. If the escape character must appear at the beginning of a line, enter it twice. The actual escape character may be changed by setting the value of escape mail variable (see Mail Variables).


Next: , Up: Composing Mail
Quitting Compose Mode

There are several commands allowing you to quit the compose mode.

Typing the end-of-file character (‘C-D’) on a line alone finishes compose mode and sends the message to its destination. The ‘C-D’ character looses its special meaning if ignoreeof mail variable is set.

If mail variable dot is set, typing dot (‘.’) on a line alone achieves the same effect as ‘C-D’ above.

Finally, using ‘~.’ escape always quits compose mode and sends out the composed message.

To abort composing of a message without sending it, type interrupt character (by default, ‘C-C’) twice. This behavior is disabled when mail variable ignore is set. In this case, you can use ‘~x’ escape to achieve the same effect.


Next: , Previous: Quitting Compose Mode, Up: Composing Mail
Getting Help on Compose Escapes: ~?

The ‘~?’ escape prints on screen a brief summary of the available compose escapes. Please note, that ‘~h’ escape prompts for changing the header values, and does not give help.


Next: , Previous: Getting Help on Compose Escapes, Up: Composing Mail
Editing the Message: ~e and ~v

If you are not satisfied with the message as it is, you can edit it using a text editor specified either by EDITOR or by VISUAL environment variables. The ‘~e’ uses the former, and ‘~v’ uses the latter.

By default both escapes allow you to edit only the body of the message. However, if the editheaders variable is set, mail will load into the editor the complete text of the message with headers included, thus allowing you to change the headers as well.


Next: , Previous: Editing the Message, Up: Composing Mail
Modifying the Headers: ~h, ~t, ~c, ~b, ~s

To add new addresses to the list of message recipients, use ‘~t’ command, e.g.:

     ~t name1@domain.net name2

To add addresses to Cc or Bcc, use ‘~c’ or ‘~b’ escapes respectively.

To change the Subject header, use ‘~s’ escape, e.g.:

     ~s "Re: your message"

Finally, to edit all headers, type ‘~h’ escape. This will present you with the values of To, Cc, Bcc, and Subject headers allowing to edit them with normal text editing commands.


Next: , Previous: Modifying the Headers, Up: Composing Mail
Enclosing Another Message: ~m and ~M

If you are sending mail from within mail command mode, you can enclose the contents of any message sent to you by using ‘~m’ or ‘~M’ commands. Typing ‘~m’ alone will enclose the contents of the current message, typing ‘~m 12’ will enclose the contents of message #12 and so on.

The ‘~m’ uses retained and ignored lists when enclosing headers, the ‘~M’ encloses all header fields.

In both cases, the contents of indentprefix mail variable is prepended to each line enclosed.


Next: , Previous: Enclosing Another Message, Up: Composing Mail
Adding a File to the Message: ~r and ~d

To append the contents of file filename to the message, type

     ~r filename

or

     ~< filename

The ‘~d’ escape is a shorthand for

     ~r dead.letter


Next: , Previous: Adding a File to the Message, Up: Composing Mail
Printing And Saving the Message

The ‘~p’ escape types the contents of the message entered so far, including headers, on your terminal. You can save the message to an arbitrary file using ‘~w’ escape. It takes the filename as its argument.


Next: , Previous: Printing And Saving the Message, Up: Composing Mail
Signing the Message: ~a and ~A

To save you the effort of typing your signature at the end of each message, you can use ‘~a’ or ‘~A’ escapes. If your signature occupies one line only, save it to the variable sign and use ‘~a’ escape to insert it. Otherwise, if it is longer than one line, save it to a file, store the name of this file in the variable Sign, and use ‘~A’ escape to insert it into the message.


Next: , Previous: Signing the Message, Up: Composing Mail
Printing Another Message: ~f and ~F

Sometimes it is necessary to view the contents of another message, while composing. These two escapes allow it. Both take the message list as their argument. If they are used without argument, the contents of the current message is printed. The difference between ‘~f’ and ‘~F’ is that the former uses ignored and retained lists to select headers to be displayed, whereas the latter prints all headers.


Next: , Previous: Printing Another Message, Up: Composing Mail
Inserting Value of a Mail Variable: ~i

The ‘~i’ escape enters the value of the named mail variable into the body of the message being composed.


Next: , Previous: Inserting Value of a Mail Variable, Up: Composing Mail
Executing Other Mail Commands: ~: and ~-

You can execute a mail command from within compose mode using ‘~:’ or ‘~-’ escapes. For example, typing

     ~: from :t

will display the from lines of all tagged messages. Note, that executing mail-sending commands from within the compose mode is not allowed. An attempt to execute such a command will result in diagnostic message “Command not allowed in an escape sequence” being displayed. Also, when starting compose mode immediately from the shell (e.g. running ‘mail address@domain’), most mail commands are meaningless, since there is no mailbox to operate upon. In this case, the only commands that can reasonably be used are: alias, unalias, alternate, set, and unset.


Previous: Executing Other Mail Commands, Up: Composing Mail
Executing Shell Commands: ~! and ~|

The ‘~!’ escape executes specified command and returns you to mail compose mode without altering your message. When used without arguments, it starts your login shell. The ‘~|’ escape pipes the message composed so far through the given shell command and replaces the message with the output the command produced. If the command produced no output, mail assumes that something went wrong and retains the old contents of your message.


Next: , Previous: Composing Mail, Up: mail

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 --file
To read messages from your mailbox ($HOME/mbox).
mail --file=path_to_mailbox
To read messages from the specified mailbox.
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.

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 Mail 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.


Next: , Up: Reading Mail
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’.


Next: , Previous: Quitting the Program, Up: Reading Mail
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.


Next: , Previous: Obtaining Online Help, Up: Reading Mail
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.


Next: , Previous: Moving Within a Mailbox, Up: Reading Mail
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


Next: , Previous: Changing mailbox/directory, Up: Reading Mail
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.


Next: , Previous: Controlling Header Display, Up: Reading Mail
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


Next: , Previous: Displaying Information, Up: Reading Mail
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.


Next: , Previous: Displaying Messages, Up: Reading Mail
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.


Next: , Previous: Marking Messages, Up: Reading Mail
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.


Next: , Previous: Disposing of Messages, Up: Reading Mail
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.


Next: , Previous: Saving Messages, Up: Reading Mail
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.


Next: , Previous: Editing Messages, Up: Reading Mail
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.


Next: , Previous: Aliasing, Up: Reading Mail
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 Mail Variables) 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


Next: , Previous: Replying, Up: Reading Mail
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


Next: , Previous: Controlling Sender Fields, Up: Reading Mail
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.


Previous: Incorporating New Mail, Up: Reading Mail
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 !.


Next: , Previous: Reading Mail, Up: mail

2.4.5 Scripting

Comments

The ‘#’ character introduces an end-of-line comment. All characters until and including the end of line are ignored.

Displaying Arbitrary Text

The ‘echo’ (‘ec’) command prints its arguments to stdout.

Sourcing External Command Files

The command ‘source filename’ reads commands from the named file. Its minimal abbreviation is ‘so’.

Setting and Unsetting the Variables

The mail variables may be set using ‘set’ (‘se’) command. The command takes a list of assignments. The syntax of an assignment is

name=string
Assign a string value to the variable. If string contains whitespace characters it must be enclosed in a pair of double-quote characters (‘"’)
name=number
Assign a numeric value to the variable.
name
Assign boolean True value.
noname
Assign boolean False value.

Example:

     & set askcc nocrt indentprefix="> "

This statement sets askcc to True, crt to False, and indentprefix to “> ”.

To unset mail variables use ‘unset’(‘uns’) command. The command takes a list of variable names to unset.

Example: To undo the effect of the previous example, do:

     & unset askcc crt indentprefix
Setting and Unsetting Shell Environment Variables

Shell environment may be modified using ‘setenv’ (‘sete’) command. The command takes a list of assignments. The syntax of an assignment is:

name=value
If variable name does not already exist in the environment, then it is added to the environment with the value value. If name does exist, then its value in the environment is changed to value.
name
Delete the variable name from the environment (“unset” it).
Conditional Statements

The conditional statement allows to execute a set of mail commands depending on the mode the mail program is in. The conditional statement is:

     if cond
     ...
     else
     ...
     endif

where ‘...’ represents the set of commands to be executed in each branch of the statement. cond can be one of the following:

s
True if mail is operating in mail sending mode.
r
True if mail is operating in mail reading mode.
t
True if stdout is a terminal device (as opposed to a regular file).

The conditional statements can be nested to arbitrary depth. The minimal abbreviations for ‘if’, ‘else’ and ‘endif’ commands are ‘i’, ‘el’ and ‘en’.

Example:

     if t
     set crt prompt="& "
     else
     unset prompt
     endif
     if s
     alt gray@farlep.net gray@mirddin.farlep.net
     set


Next: , Previous: Scripting, Up: mail

2.4.6 How to Alter the Behavior of mail

Following variables control the behavior of gnu mail:

appenddeadletter

Type: Boolean.
Default: False. If this variable is True, the contents of canceled letter is appended to the user's dead.letter file. Otherwise it overwrites its contents.
askbcc

Type: Boolean.
Default: False. When set to True the user will be prompted to enter Bcc field before composing the message.
askcc

Type: Boolean.
Default: True. When set to True the user will be prompted to enter Cc field before composing the message.
asksub

Type: Boolean.
Default: True in interactive mode, False otherwise. When set to True the user will be prompted to enter Subject field before composing the message.
autoinc

Type: Boolean.
Default: True. Automatically incorporate newly arrived messages.
autoprint

Type: Boolean.
Default: False. Causes the delete command to behave like dp - thus, after deleting a message, the next one will be typed automatically.
bang

Type: Boolean.
Default: False. When set, every occurrence of ! in arguments to ! command is replaced with the last executed command.
datefield

Type: Boolean.
Default: False. By default the date in a header summary is taken from the SMTP envelope of the message. Setting this variable tells mail to use the date from Date: header field, converted to localtime. Notice, that for messages lacking this field mail will fall back to using SMTP envelope.
charset

Type: string
Default: ‘auto The value of this variable controls the output character set for the header fields encoding using RFC 2047. If the variable is unset, no decoding is performed and the fields are printed as they are. If the variable is set to ‘auto’, mail tries to deduce the name of the character set from the value of LC_ALL environment variable. Otherwise, its value is taken as the name of the charset.
cmd

Type: String.
Default: Unset. Contains default shell command for pipe.
columns

Type: Numeric.
Default: Detected at startup by querying the terminal device. If this fails, the value of environment variable COLUMNS is used. This variable contains the number of columns on terminal screen.
crt

Type: Boolean or Numeric
Default: True in interactive mode, False otherwise. 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 threshold. 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.
decode-fallback

Type: String.
Default: ‘none’. This variable controls the way to represent characters that cannot be rendered using current character set. It can have three values:
none
Such characters are not printed at all. The conversion process stops at the first character that cannot be rendered.
copy-pass
The characters are displayed ‘as is’. Notice, that depending on your setup, this may screw-up your terminal settings.
copy-octal
Unprintable characters are represented by their octal codes. Printable ones are printed ‘as is’.

dot

Type: Boolean.
Default: False. If True, causes mail to interpret a period alone on a line as the terminator of a message you are sending.
emptystart

Type: Boolean.
Default: False. If the mailbox is empty, mail normally prints ‘No mail for user’ and exits immediately. If this option is set, mail will start no matter is the mailbox empty or not.
editheaders

Type: Boolean.
Default: False. When set, mail will include message headers in the text to be the ~e and ~v escapes, thus allowing you to customize the headers.
escape

Type: String.
Default: ~ If defined, the first character of this option gives the character to denoting escapes.
flipr

Type: Boolean
Default: Unset The variable flipr if set swaps the meanings of reply and Reply commands (see Replying).
folder

Type: String.
Default: Unset. The name of the directory to use for storing folders of messages. If unset, $HOME is assumed.
header

Type: Boolean.
Default: True, unless started with --nosum (-N) option. Whether to run headers command automatically after entering interactive mode.
hold

Type: Boolean.
Default: False. When set to True, the read or saved messages will be stored in user's mailbox ($HOME/mbox). Otherwise, they will be held in system mailbox also. This option is in effect only when operating upon user's system mailbox.
ignore

Type: Boolean.
Default: False. When set to True, mail will ignore keyboard interrupts when composing messages. Otherwise an interrupt will be taken as a signal to abort composing.
ignoreeof

Type: Boolean.
Default: False. Controls whether typing EOF character terminates the letter being composed.
indentprefix

Type: String.
Default: "\t" (a tab character). String used by the ~m tilde escape for indenting quoted messages.
inplacealiases

Type: Boolean
Default: False

If set, mail will expand aliases in the address header field before entering send mode (see Composing Mail). By default, the address header fields are left intact while composing, the alias expansion takes place immediately before sending message.

keepsave

Type: Boolean.
Default: False. Controls whether saved messages should be kept in system mailbox too. This variable is in effect only when operating upon a user's system mailbox.
mailx

Type: Boolean.
Default: False. When set, enables mailx compatibility mode. This mode has the following effects:
metamail

Type: Boolean or String.
Default: True. This variable controls operation of decode command. If it is unset, decode will not attempt any interpretation of the content of message parts. Otherwise, if metamail is set to true, decode will use internal metamail support to interpret message parts. Finally, if metamail is assigned a string, this string is treated as command line of the external metamail command which will be used to display parts of a multipart message. For example:
          # Disable MIME interpretation:
          set nometamail
          # Enable built-in MIME support:
          set metamail
          # Use external program to display MIME parts:
          set metamail="metamail -m mail -p"

mimenoask

Type: String
Default: Empty By default mail asks for comnfirmation before running interpreter to view a part of the multi-part message. If this variable is set, its value is treated as a comma-separated list of MIME types for which no confirmation is needed. Elements of this list may include shell-style globbing patterns, e.g. setting
          set mimenoask=text/*,image/jpeg

will disable prompting before displaying any textual files, no matter what their subtype is, and before displaying files with type ‘image/jpeg’.

metoo

Type: Boolean.
Default: False. Usually, when an alias is expanded that contains the sender, the sender is removed from the expansion. Setting this option causes the sender to be included in the group.
mode

Type: String.
Default: The name of current operation mode. Setting this variable does not affect the operation mode of the program.
nullbody

Type: Boolean
Default: True Controls whether mail accepts messages with an empty body. The default value, true, means such messages are sent, and a warning (traditionally saying ‘Null message body; hope that's ok’) is displayed. The text of the warning can be set using nullbodymsg variable (see below).

If nullbody is unset, mail will silently ignor