Marco Fioretti shares his favorite tricks for creating and managing email profiles in Mutt.
Mutt is a venerable command line email client. Even in this era of Gmail and other highly interactive webmail interfaces, Mutt keeps a lot of very loyal followers. I am one of them. Every now and then I also use Kmail, and I try, more or less regularly, all other desktop email clients for Linux that I come across.
However, not only do I always install Mutt on all the Linux computers I use but, in 2011, I still find myself running almost exclusively this email client. Why? Novice Linux users sometimes tend to explain such preferences as some form of grumpy nostalgia for the good old times. Yeah, the times when (quoting Linus Torvalds) "men were men and wrote their own drivers", or at least were perfectly happy to do all their own computing in a character terminal, yelling "mouses are for ninnies!"
I do know a few people who use Mutt for such reasons. However, for me the main, real cause why I stick to Mutt is not some moral objection to slick, modern, and beautiful interfaces. To tell you the truth, I like the look and feel of Kmail much, much better than that of Mutt. However, Mutt makes it much easier than Kmail to maintain any number of completely unrelated email personalities, each one configured in its own, completely independent way. That's why I use Mutt. In spite of what Zuckerberg (yes, the Facebook guy) says, we still are (or should be) different personas in different contexts. Therefore, as far as I am concerned, those personas should have completely separate email addresses and configurations. In my opinion, working that way makes human interactions via email easier and, in some cases, more sincere. It also leaves less space for embarrassing oneself.
Consequently, my freelance work account has a professional signature, usually with links to my home pages or publications. Email I send on behalf of some companies I work for has address and signature of those companies. My private email has yet another address, and a signature made of random quotes that would still be okay in those companies, but not if appended to an official communication of theirs. Some of these identities must also use a different SMTP server.
Some people achieve this by running simultaneously different clients, or different instances of the same client. That feels really unproductive to me.
Mutt makes it very easy to keep many identities separated, while always running only one email client, in one window. This is possible because, when properly configured (as I'll explain in a moment), Mutt almost always switches to the right identity automatically, and in all other cases lets you decide with a couple of keystrokes. Here's how.
Inside the Mutt configuration files, which are plain text, you can set any parameter an email client may need, from selecting Reply-To addresses to specifying which SMTP server or signature generator should be used. Mutt can change its configuration on the fly, by sourcing such files. Finally, Mutt can perform automatically many actions (including sourcing!) right before sending new messages, or replying to, certain predefined email addresses. Put all these things together, and you get a client that knows by itself which configuration to use depending on who you are writing or replying to. All it takes is commands like this in the Mutt configuration file:
send-hook "big-boss\@office\.com" "source mutt_office_profile"
reply-hook "big-boss\@office\.com" "source mutt_office_profile"
send-hook "hubby\@happyfamily\.com" "source mutt_romantic_profile"
reply-hook "hubby\@happyfamily\.com" "source mutt_romantic_profile"
The details of how to write profiles are explained here and here. The two main tricks are to set all the defaults in the main Mutt configuration file, and to always define all the relevant variables in all profiles, so that no settings from one profile remain valid when you switch to a new one. What's left? Oh, yes: how do you tell Mutt which profile it should load when you write to an address not in the configuration file? And how do you permanently associate somebody who wrote to you to some profile from inside Mutt?
The answer to the first question is "use this Mutt profile chooser". Associating sender addresses to a profile, instead, means adding to the Mutt configuration lines like the ones above. Mutt can do it for you via macros like these (bind them to whatever keystrokes you like, of course):
macro pager l "<enter-command>unset wait_key\n<pipe-entry>attach_profile.sh work\n<enter-command>set wait_key\n<"
This will pass the currently open email message to a simple script (attach_profile.sh):
ADDR=$(formail -r -x "From:" /dev/stdin | cut '-d ' -f2- | sed -r 's/([@.])/\\\1/g')
echo "send-hook \"$ADDR\" \"source mutt.profile.$1\"" >> $MUTT_HOOKS_FILE
echo "reply-hook \"$ADDR\" \"source mutt.office.$1\"" >> $MUTT_HOOKS_FILE
This script uses formail and sed to extract and escape the sender email address from the message read from standard input. Then, it appends the Mutt commands that associate that address with the profile passed as first argument to a Mutt configuration file.
Try the Mutt profiles! You'll love them, if you need to switch all the time among different email identities.