Whole document tree 4. Advanced Usage4.1 Regular ExpressionsAll string patterns in Mutt including those in more complex patterns must be specified using regular expressions (regexp) in the ``POSIX extended'' syntax (which is more or less the syntax used by egrep and GNU awk). For your convenience, we have included below a brief description of this syntax. The search is case sensitive if the pattern contains at least one upper case letter, and case insensitive otherwise. Note that ``\'' must be quoted if used for a regular expression in an initialization command: ``\\''. A regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions, by using various operators to combine smaller expressions. Note that the regular expression can be enclosed/delimited by either " or ' which is useful if the regular expression includes a white-space character. See Syntax of Initialization Files for more information on " and ' delimiter processing. To match a literal " or ' you must preface it with \ (backslash). The fundamental building blocks are the regular expressions that match a single character. Most characters, including all letters and digits, are regular expressions that match themselves. Any metacharacter with special meaning may be quoted by preceding it with a backslash. The period ``.'' matches any single character. The caret ``^'' and the dollar sign ``$'' are metacharacters that respectively match the empty string at the beginning and end of a line. A list of characters enclosed by ``['' and ``]'' matches any single character in that list; if the first character of the list is a caret ``^'' then it matches any character not in the list. For example, the regular expression [0123456789] matches any single digit. A range of ASCII characters may be specified by giving the first and last characters, separated by a hyphen ``‐''. Most metacharacters lose their special meaning inside lists. To include a literal ``]'' place it first in the list. Similarly, to include a literal ``^'' place it anywhere but first. Finally, to include a literal hyphen ``‐'' place it last. Certain named classes of characters are predefined. Character classes consist of ``[:'', a keyword denoting the class, and ``:]''. The following classes are defined by the POSIX standard:
A character class is only valid in a regular expression inside the brackets of a character list. Note that the brackets in these class names are part of the symbolic names, and must be included in addition to the brackets delimiting the bracket list. For example, [[:digit:]] is equivalent to [0-9]. Two additional special sequences can appear in character lists. These apply to non-ASCII character sets, which can have single symbols (called collating elements) that are represented with more than one character, as well as several characters that are equivalent for collating or sorting purposes:
A regular expression matching a single character may be followed by one of several repetition operators:
Two regular expressions may be concatenated; the resulting regular expression matches any string formed by concatenating two substrings that respectively match the concatenated subexpressions. Two regular expressions may be joined by the infix operator ``|''; the resulting regular expression matches any string matching either subexpression. Repetition takes precedence over concatenation, which in turn takes precedence over alternation. A whole subexpression may be enclosed in parentheses to override these precedence rules. Note: If you compile Mutt with the GNU rx package, the following operators may also be used in regular expressions:
Please note however that these operators are not defined by POSIX, so they may or may not be available in stock libraries on various systems. 4.2 PatternsMany of Mutt's commands allow you to specify a pattern to match (limit, tag-pattern, delete-pattern, etc.). There are several ways to select messages:
Where EXPR, USER, ID, and SUBJECT are regular expressions. *) The forms Pattern ModifierNote that patterns matching 'lists' of addresses (notably c,C,p,P and t) match if there is at least one match in the whole list. If you want to make sure that all elements of that list match, you need to prefix your pattern with ^. This example matches all mails which only has recipients from Germany.
Complex PatternsLogical AND is performed by specifying more than one criterion. For example:
would select messages which contain the word ``mutt'' in the list of recipients and that have the word ``elkins'' in the ``From'' header field. Mutt also recognizes the following operators to create more complex search patterns:
Here is an example illustrating a complex search pattern. This pattern will select all messages which do not contain ``mutt'' in the ``To'' or ``Cc'' field and which are from ``elkins''.
Here is an example using white space in the regular expression (note the ' and " delimiters). For this to match, the mail's subject must match the ``^Junk +From +Me$'' and it must be from either ``Jim +Somebody'' or ``Ed +SomeoneElse'':
Searching by DateMutt supports two types of dates, absolute and relative. Absolute. Dates must be in DD/MM/YY format (month and year are optional, defaulting to the current month and year). An example of a valid range of dates is:
If you omit the minimum (first) date, and just specify ``-DD/MM/YY'', all messages before the given date will be selected. If you omit the maximum (second) date, and specify ``DD/MM/YY-'', all messages after the given date will be selected. If you specify a single date with no dash (``-''), only messages sent on the given date will be selected. Error Margins. You can add error margins to absolute dates. An error margin is a sign (+ or -), followed by a digit, followed by one of the following units: y years m months w weeks d daysAs a special case, you can replace the sign by a ``*'' character, which is equivalent to giving identical plus and minus error margins. Example: To select any messages two weeks around January 15, 2001, you'd use the following pattern:
Relative. This type of date is relative to the current date, and may be specified as:
offset is specified as a positive number with one of the following units: y years m months w weeks d days Example: to select messages less than 1 month old, you would use
Note: all dates used when searching are relative to the
local time zone, so unless you change the setting of your
$index_format to include a
4.3 Using TagsSometimes it is desirable to perform an operation on a group of messages all at once rather than one at a time. An example might be to save messages to a mailing list to a separate folder, or to delete all messages with a given subject. To tag all messages matching a pattern, use the tag-pattern function, which is bound to ``shift-T'' by default. Or you can select individual messages by hand using the ``tag-message'' function, which is bound to ``t'' by default. See patterns for Mutt's pattern matching syntax. Once you have tagged the desired messages, you can use the ``tag-prefix'' operator, which is the ``;'' (semicolon) key by default. When the ``tag-prefix'' operator is used, the next operation will be applied to all tagged messages if that operation can be used in that manner. If the $auto_tag variable is set, the next operation applies to the tagged messages automatically, without requiring the ``tag-prefix''. 4.4 Using HooksA hook is a concept borrowed from the EMACS editor which allows you to execute arbitrary commands before performing some operation. For example, you may wish to tailor your configuration based upon which mailbox you are reading, or to whom you are sending mail. In the Mutt world, a hook consists of a regular expression or pattern along with a configuration option/command. See for specific details on each type of hook available.Note: if a hook changes configuration settings, these changes remain effective until the end of the current mutt session. As this is generally not desired, a default hook needs to be added before all other hooks to restore configuration defaults. Here is an example with send-hook and the my_hdr directive:
Message Matching in HooksHooks that act upon messages ( Mutt allows the use of the search pattern language for matching messages in hook commands. This works in exactly the same way as it would when limiting or searching the mailbox, except that you are restricted to those operators which match information mutt extracts from the header of the message (i.e. from, to, cc, date, subject, etc.). For example, if you wanted to set your return address based upon sending mail to a specific address, you could do something like:
which would execute the given command when sending mail to
me@cs.hmc.edu.
However, it is not required that you write the pattern to match using the full searching language. You can still specify a simple regular expression like the other hooks, in which case Mutt will translate your pattern into the full language, using the translation specified by the $default_hook variable. The pattern is translated at the time the hook is declared, so the value of $default_hook that is in effect at that time will be used. 4.5 External Address QueriesMutt supports connecting to external directory databases such as LDAP, ph/qi, bbdb, or NIS through a wrapper script which connects to mutt using a simple interface. Using the $query_command variable, you specify the wrapper command to use. For example:
The wrapper script should accept the query on the command-line. It should return a one line message, then each matching response on a single line, each line containing a tab separated address then name then some other optional information. On error, or if there are no matching addresses, return a non-zero exit code and a one line error message. An example multiple response output:
There are two mechanisms for accessing the query function of mutt. One is to do a query from the index menu using the query function (default: Q). This will prompt for a query, then bring up the query menu which will list the matching responses. From the query menu, you can select addresses to create aliases, or to mail. You can tag multiple messages to mail, start a new query, or have a new query appended to the current responses. The other mechanism for accessing the query function is for address completion, similar to the alias completion. In any prompt for address entry, you can use the complete-query function (default: ^T) to run a query based on the current address you have typed. Like aliases, mutt will look for what you have typed back to the last space or comma. If there is a single response for that query, mutt will expand the address in place. If there are multiple responses, mutt will activate the query menu. At the query menu, you can select one or more addresses to be added to the prompt. 4.6 Mailbox FormatsMutt supports reading and writing of four different mailbox formats: mbox, MMDF, MH and Maildir. The mailbox type is autodetected, so there is no need to use a flag for different mailbox types. When creating new mailboxes, Mutt uses the default specified with the $mbox_type variable. mbox. This is the most widely used mailbox format for UNIX. All messages are stored in a single file. Each message has a line of the form:
to denote the start of a new message (this is often referred to as the ``From_'' line). MMDF. This is a variant of the mbox format. Each message is surrounded by lines containing ``^A^A^A^A'' (four control-A's). MH. A radical departure from mbox and MMDF, a mailbox
consists of a directory and each message is stored in a separate file.
The filename indicates the message number (however, this is may not
correspond to the message number Mutt displays). Deleted messages are
renamed with a comma (,) prepended to the filename. Note: Mutt
detects this type of mailbox by looking for either Maildir. The newest of the mailbox formats, used by the Qmail MTA (a replacement for sendmail). Similar to MH, except that it adds three subdirectories of the mailbox: tmp, new and cur. Filenames for the messages are chosen in such a way they are unique, even when two programs are writing the mailbox over NFS, which means that no file locking is needed. 4.7 Mailbox ShortcutsThere are a number of built in shortcuts which refer to specific mailboxes. These shortcuts can be used anywhere you are prompted for a file or mailbox path.
4.8 Handling Mailing ListsMutt has a few configuration options that make dealing with large amounts of mail easier. The first thing you must do is to let Mutt know what addresses you consider to be mailing lists (technically this does not have to be a mailing list, but that is what it is most often used for), and what lists you are subscribed to. This is accomplished through the use of the lists and subscribe commands in your muttrc. Now that Mutt knows what your mailing lists are, it can do several things, the first of which is the ability to show the name of a list through which you received a message (i.e., of a subscribed list) in the index menu display. This is useful to distinguish between personal and list mail in the same mailbox. In the $index_format variable, the escape ``%L'' will return the string ``To <list>'' when ``list'' appears in the ``To'' field, and ``Cc <list>'' when it appears in the ``Cc'' field (otherwise it returns the name of the author). Often times the ``To'' and ``Cc'' fields in mailing list messages
tend to get quite large. Most people do not bother to remove the
author of the message they are reply to from the list, resulting in
two or more copies being sent to that person. The ``list-reply''
function, which by default is bound to ``L'' in the index menu
and pager, helps reduce the clutter by only replying to the
known mailing list addresses instead of all recipients (except as
specified by Mutt also supports the Conversely, when group-replying or list-replying to a message which
has a Note that, when header editing is enabled, you can create a
The other method some mailing list admins use is to generate a ``Reply-To'' field which points back to the mailing list address rather than the author of the message. This can create problems when trying to reply directly to the author in private, since most mail clients will automatically reply to the address given in the ``Reply-To'' field. Mutt uses the $reply_to variable to help decide which address to use. If set, you will be prompted as to whether or not you would like to use the address given in the ``Reply-To'' field, or reply directly to the address given in the ``From'' field. When unset, the ``Reply-To'' field will be used when present. The ``X-Label:'' header field can be used to further identify mailing lists or list subject matter (or just to annotate messages individually). The $index_format variable's ``%y'' and ``%Y'' escapes can be used to expand ``X-Label:'' fields in the index, and Mutt's pattern-matcher can match regular expressions to ``X-Label:'' fields with the `` y'' selector. ``X-Label:'' is not a standard message header field, but it can easily be inserted by procmail and other mail filtering agents. Lastly, Mutt has the ability to sort the mailbox into threads. A thread is a group of messages which all relate to the same subject. This is usually organized into a tree-like structure where a message and all of its replies are represented graphically. If you've ever used a threaded news client, this is the same concept. It makes dealing with large volume mailing lists easier because you can easily delete uninteresting threads and quickly find topics of value. 4.9 Editing threadsMutt has the ability to dynamically restructure threads that are broken either by misconfigured software or bad behaviour from some correspondents. This allows to clean your mailboxes (mbox and mmdf formats) from these annoyances which make it hard to follow a discussion. Linking threadsSome mailers tend to "forget" to correctly set the "In-Reply-To:" and "References:" headers when replying to a message. This results in broken discussions because Mutt has not enough information to guess the correct threading. You can fix this by tagging the reply to a mail, then go onto this mail and use the ``link-threads'' function (bound to & by default). The reply will then be connected to its "parent" message. You can also connect multiple childs at once, tagging them and using the tag-prefix command (';') or the auto_tag option. Breaking threadsOn mailing lists, some people are in the bad habit of starting a new discussion by hitting "reply" to any message from the list and changing the subject to a totally unrelated one. You can fix such threads by using the ``break-thread'' function (bound by default to #), which will turn the subthread starting from the current message into a whole different thread. 4.10 Delivery Status Notification (DSN) SupportRFC1894 defines a set of MIME content types for relaying information about the status of electronic mail messages. These can be thought of as ``return receipts.'' Berkeley sendmail 8.8.x currently has some command line options in which the mail client can make requests as to what type of status messages should be returned. To support this, there are two variables. $dsn_notify is used to request receipts for different results (such as failed message, message delivered, etc.). $dsn_return requests how much of your message should be returned with the receipt (headers or full message). Refer to the man page on sendmail for more details on DSN. 4.11 POP3 Support (OPTIONAL)If Mutt was compiled with POP3 support (by running the configure script with the --enable-pop flag), it has the ability to work with mailboxes located on a remote POP3 server and fetch mail for local browsing. You can access the remote POP3 mailbox by selecting the folder
You can select an alternative port by specifying it with the server, ie:
You can also specify different username for each folder, ie:
Polling for new mail is more expensive over POP3 than locally. For this reason the frequency at which Mutt will check for mail remotely can be controlled by the $pop_checkinterval variable, which defaults to every 60 seconds. If Mutt was compiled with SSL support (by running the configure
script with the --with-ssl flag), connections to POP3 servers
can be encrypted. This naturally requires that the server supports
SSL encrypted connections. To access a folder with POP3/SSL, you should
use pops: prefix, ie:
Another way to access your POP3 mail is the fetch-mail function (default: G). It allows to connect to pop_host, fetch all your new mail and place it in the local spoolfile. After this point, Mutt runs exactly as if the mail had always been local. Note: If you only need to fetch all messages to local mailbox you should consider using a specialized program, such as fetchmail 4.12 IMAP Support (OPTIONAL)If Mutt was compiled with IMAP support (by running the configure script with the --enable-imap flag), it has the ability to work with folders located on a remote IMAP server. You can access the remote inbox by selecting the folder
You can select an alternative port by specifying it with the server, ie:
You can also specify different username for each folder, ie:
If Mutt was compiled with SSL support (by running the configure
script with the --with-ssl flag), connections to IMAP servers
can be encrypted. This naturally requires that the server supports
SSL encrypted connections. To access a folder with IMAP/SSL, you should
use Pine-compatible notation is also supported, ie
Note that not all servers use / as the hierarchy separator. Mutt should correctly notice which separator is being used by the server and convert paths accordingly. When browsing folders on an IMAP server, you can toggle whether to look at only the folders you are subscribed to, or all folders with the toggle-subscribed command. See also the $imap_list_subscribed variable. Polling for new mail on an IMAP server can cause noticeable delays. So, you'll want to carefully tune the $mail_check and $timeout variables. Personally I use
with relatively good results over my slow modem line.
Note that if you are using mbox as the mail store on UW servers prior to v12.250, the server has been reported to disconnect a client if another client selects the same folder. The Folder BrowserAs of version 1.2, mutt supports browsing mailboxes on an IMAP server. This is mostly the same as the local file browser, with the following differences:
AuthenticationMutt supports four authentication methods with IMAP servers: SASL, GSSAPI, CRAM-MD5, and LOGIN (there is a patch by Grant Edwards to add NTLM authentication for you poor exchange users out there, but it has yet to be integrated into the main tree). There is also support for the pseudo-protocol ANONYMOUS, which allows you to log in to a public IMAP server without having an account. To use ANONYMOUS, simply make your username blank or "anonymous". SASL is a special super-authenticator, which selects among several protocols (including GSSAPI, CRAM-MD5, ANONYMOUS, and DIGEST-MD5) the most secure method available on your host and the server. Using some of these methods (including DIGEST-MD5 and possibly GSSAPI), your entire session will be encrypted and invisible to those teeming network snoops. It is the best option if you have it. To use it, you must have the Cyrus SASL library installed on your system and compile mutt with the --with-sasl flag. Mutt will try whichever methods are compiled in and available on the server, in the following order: SASL, ANONYMOUS, GSSAPI, CRAM-MD5, LOGIN. There are a few variables which control authentication:
4.13 Managing multiple IMAP/POP accounts (OPTIONAL)If you happen to have accounts on multiple IMAP and/or POP servers, you may find managing all the authentication settings inconvenient and error-prone. The account-hook command may help. This hook works like folder-hook but is invoked whenever you access a remote mailbox (including inside the folder browser), not just when you open the mailbox. Some examples:
4.14 Start a WWW Browser on URLs (EXTERNAL)If a message contains URLs (unified ressource locator = address in the WWW space like http://www.mutt.org/), it is efficient to get a menu with all the URLs and start a WWW browser on one of them. This functionality is provided by the external urlview program which can be retrieved at ftp://ftp.guug.de/pub/mutt/contrib/ and the configuration commands:
4.15 Compressed folders Support (OPTIONAL)If Mutt was compiled with compressed folders support (by running the configure script with the --enable-compressed flag), Mutt can open folders stored in an arbitrary format, provided that the user has a script to convert from/to this format to one of the accepted. The most common use is to open compressed archived folders e.g. with gzip. In addition, the user can provide a script that gets a folder in an accepted format and appends its context to the folder in the user-defined format, which may be faster than converting the entire folder to the accepted format, appending to it and converting back to the user-defined format. There are three hooks defined ( open-hook, close-hook and append-hook) which define commands to uncompress and compress a folder and to append messages to an existing compressed folder respectively. For example:
You do not have to specify all of the commands. If you omit append-hook, the folder will be open and closed again each time you will add to it. If you omit close-hook (or give empty command) , the folder will be open in the mode. If you specify append-hook though you'll be able to append to the folder. Note that Mutt will only try to use hooks if the file is not in one of the accepted formats. In particular, if the file is empty, mutt supposes it is not compressed. This is important because it allows the use of programs that do not have well defined extensions. Just use "." as a regexp. But this may be surprising if your compressing script produces empty files. In this situation, unset $save_empty, so that the compressed file will be removed if you delete all of the messages. Open a compressed mailbox for readingUsage: The command is the command that can be used for opening the folders whose names match regexp. The command string is the printf-like format string, and it should accept two parameters: %f, which is replaced with the (compressed) folder name, and %t which is replaced with the name of the temporary folder to which to write. %f and %t can be repeated any number of times in the command string, and all of the entries are replaced with the appropriate folder name. In addition, %% is replaced by %, as in printf, and any other %anything is left as is. The command should not remove the original compressed file. The command should return non-zero exit status if it fails, so mutt knows something's wrong. Example:
If the command is empty, this operation is disabled for this file type. Write a compressed mailboxUsage: This is used to close the folder that was open with the open-hook command after some changes were made to it. The command string is the command that can be used for closing the folders whose names match regexp. It has the same format as in the open-hook command. Temporary folder in this case is the folder previously produced by the open-hook command. The command should not remove the decompressed file. The command should return non-zero exit status if it fails, so mutt knows something's wrong. Example:
If the command is empty, this operation is disabled for this file type, and the file can only be open in the read-only mode. close-hook is not called when you exit from the folder if the folder was not changed. Append a message to a compressed mailboxUsage: This command is used for saving to an existing compressed folder. The command is the command that can be used for appending to the folders whose names match regexp. It has the same format as in the open-hook command. The temporary folder in this case contains the messages that are being appended. The command should not remove the decompressed file. The command should return non-zero exit status if it fails, so mutt knows something's wrong. Example:
When append-hook is used, the folder is not opened, which saves time, but this means that we can not find out what the folder type is. Thus the default ( $mbox_type) type is always supposed (i.e. this is the format used for the temporary folder). If the file does not exist when you save to it, close-hook is called, and not append-hook. append-hook is only for appending to existing folders. If the command is empty, this operation is disabled for this file type. In this case, the folder will be open and closed again (using open-hook and close-hookrespectively) each time you will add to it. Encrypted foldersThe compressed folders support can also be used to handle encrypted folders. If you want to encrypt a folder with PGP, you may want to use the following hooks:
Please note, that PGP does not support appending to an encrypted folder, so there is no append-hook defined. If you are using GnuPG instead of PGP, you may use the following hooks instead:
Note: the folder is temporary stored decrypted in the /tmp directory, where it can be read by your system administrator. So think about the security aspects of this. Next Previous Contents |