Mutt is a very powerful email client, mainly because it’s terminal-based and because it has a vast array of terse commands reminiscient of the terse command power of vim. Much like vim, it’s not possible to remember all possible commands. Here are two commands that I use often enough for them to be useful, however seldom enough so that I forget the exact invocation.
Save multiple messages to a folder in mutt
At work I get a lot of automated email. Some of this comes from our ticket system, some from our monitoring systems, but most of it comes from our servers directly in the form of Logwatch emails. Logwatch analyses Unix system logs and provides a report based on events found therein, for instance disk partion usage, accesses via ssh, out-of-the-ordinary kernel messages, etc. Of course, such a system is really only useful if one has a small number of heterogeneous servers: if you have hundreds or thousands of similar servers, then you’ll need a more sophisticated monitoring solution. However, for a small company it can do the job.
Logwatch is usually set up to run via cron once per day and to send the
report via email. This is where the problem appears: the emails pile up
over time. Sure, you can delete them (which is the easy option I use,
because a simple
d is much easier than saving the messages into a specific
folder), however that just moves them into the “Trash” folder and they
continue to accumlate there.
These old messages aren’t worthless: they contain information which can be useful when trying to debug an issue with a server. For instance, you can answer questions such as: “when did this issue first appear in the logs?”. I’ve found a quick search in my Logwatch emails gives me an idea of when a problem began to appear which means that I can more quickly home in on the relevant log file which then contains the (very!) detailed information.
Saving each message into (say) a
Logwatch folder every day is actually a
fair bit of work (e.g.
s for save, then specify the folder, then hit
enter, repeating the process for each message), hence why I just hit
delete the messages.
So, the situation is that I have lots of messages in my
Trash folder that
I’d actually rather have saved somewhere else. The question then becomes:
how does one perform a bulk-move of messages in mutt?
Here are the steps in their most terse form:
T<search-pattern> ; s =<mailbox-name>
This needs some explanation. Here are the gory details:
T(capital ‘t’) command tags all messages in the current folder according to the given search pattern. For instance, to tag all Logwatch messages, one would use the string
Logwatch forsince this is sufficient to match the subject line of all Logwatch messages.
;(semicolon) is the
tag-prefixcommand, which tells mutt to run the following command on all tagged messages.
s(lower case ‘s’) is the
save-messagecommand which will then save the tagged messages into the folder specified by the user in the next step.
=(equals sign) is the folder prefix (i.e. the base path to where your email folders are located on your system) and saves having to type in the full path to where you want your messages to be saved. One simply follows
=with the name of the folder to save the messages into; in the example discussed here, this is simply
- now hit enter to execute the save command. Hit enter again to accept the default option to append the messages to the given folder.
By the way: I adapted these instructions from the more general information given on the Mutt FAQ, so if you want more mutt-related tips have a look at that excellent resource.
Selecting messages by recipient address
Spam has been a part of email ever since I got my first email address at university in the early 90’s (yes, I’m that old). These days the spam defense one can get at almost any email service provider is significantly more sophisticated than back then. Nevertheless, some messages still slip through the gaps and land in my inbox. My email service provider allows users to let them know about spam emails by using a “spamreport” address. As a user, I just need to forward the offending email to this special address and the service provider can use this information to update their spam filter rules.
Of course, after having forwarded the spam email to
delete the email. But this just moves the message from the
INBOX into the
Trash folder and I don’t want to keep such messages around, hence I
periodically clean up my
Trash folder by deleting all messages sent to the
It isn’t intuitively obvious how to do this in mutt, since it’s not possible
delete-pattern) and then the recipient address, as the
field isn’t matched directly by the
delete-pattern search. The solution,
however, is fairly easy: use the
modifier to match messages
addressed to the given expression. In its terse form, this is:
D ~t <to-address>
or more explicitly:
:exec delete-pattern ~t <to-address>
As is hopefully evident from the more explicit form,
D (capital ‘d’) is
delete-pattern command. This command accepts a pattern which is used
to match messages; this pattern matches by default things such as the
From: address name and the subject field. To match the
To: field, one
needs to use the
~t modifier and then an expression to match the given
Therefore, to purge my outbox of unnecessary spam messages, I navigate
Sent folder and enter
D ~t firstname.lastname@example.org
which moves the messages into the
Trash. I then navigate into the
Trash folder and run this command again to remove the messages
permanently. Although I probably could find a way to shorten this process,
it isn’t necessary for me to do this all that often, so I haven’t yet put
any effort into reducing the number of keystrokes here.
Mutt is a powerful and fast email client. It does take some getting used to, but then again, I migrated to mutt from elm, so it wasn’t such a big step for me. And if you like vim, then it’s definitely the email client for you!
Do you have any favourite mutt shortcuts and tips? If so, please share them in the comments section below; I’m always interested in learning cool new commands to speed up my workflow.