Living the Command Line Dream With Mutt

Read­ing Time: 6 min­utes

It prob­a­bly stems from how long I have been using com­put­ers, and what my first com­put­er inter­faces looked like, but I have been enam­ored of com­mand line inter­faces since, well, for­ev­er. There have been the occa­sion­al graph­ics dal­liances: the Ami­ga, NeXTSTEP, the Enlight­en­ment win­dow man­ag­er, some aspects of the cur­rent OS X GUI. By and large, how­ev­er, in any envi­ron­ment I can think of, I pre­fer a com­mand line inter­face.

The chal­lenge in today’s world is that many oper­at­ing sys­tems, and an increas­ing num­ber of net­work, stor­age, and oth­er enter­prise-lev­el devices, all make it at dif­fi­cult to use the com­mand line. I do have valid rea­sons, in my own mind at least, for pre­fer­ring a text-based inter­face: I can be more pro­fi­cient when I do not have to remem­ber where all the lit­tle pic­tures and menus are, and what man­ner of click­ety-click­ing I need to per­form in order to accom­plish reg­u­lar, mun­dane, should-be-easy tasks; my brain is hard­wired to remem­ber words more than pic­tures, and as a gen­er­al rule the com­mand line offers more pow­er and flex­i­bil­i­ty than does the GUI. Of course, if you’re not accus­tomed to the com­mand line, or you’re not a lud­dite, you may scoff at the idea of using an archa­ic inter­face method, but I do find that most pow­er users I know—and this is pure­ly anecdotal—prefer a text inter­face as well: the Unix shell, Win­dows Pow­er­Shell, Cis­co IOS, what­ev­er. That said, I do man­age to claw my way back into the com­mand-line world where I can, a piece at a time, and the small vic­to­ries keep me sati­at­ed, for the most part.

One area where I find, almost with­out excep­tion, the GUI com­plete­ly hor­rif­ic and lack­ing is in today’s email clients. The appli­ca­tions seem to be mas­sive­ly bloat­ed, tak­ing much more mem­o­ry and pro­cess­ing pow­er than their func­tions would sug­gest. The lay­outs of most, while famil­iar, are only accept­able because we have all become used to them, not because they are use­ful. The great­est sin, though, is that the search­ing capa­bil­i­ties are almost uni­ver­sal­ly hor­rid, inef­fec­tu­al, and slow. I want­ed bet­ter, and I final­ly did some­thing about it: I went to Mutt. Actu­al­ly, I went to Neo­Mutt.

Mutt has been around for­ev­er as an email client, like the much vaunt­ed Pine—still avail­able, by the way—and Neo­Mutt is noth­ing more than Mutt pre-built with sev­er­al of the most com­mon Mutt patch­es. Mutt is an infi­nite­ly flex­i­ble email client that is built in the old vein of clients, and fol­lows the Unix ethos of doing one thing only, and doing that one thing well. While you can set it up to native­ly han­dle many things from gath­er­ing email, sort­ing, etc., it works best when you leave those func­tions to oth­er appli­ca­tions.

The chal­lenge with Mutt, and oth­er sup­port appli­ca­tions in what you might call its ecosys­tem, is that they aren’t always as intu­itive to set up as might be ide­al, and less so in today’s com­pli­cat­ed cli­mate of pro­pri­etary for­mats (EWS,) cloud-host­ed ser­vices, IMAP, POP, SNTP, GPG, etc. It took me a while to get my set­up dialed in, or at least close to dialed in (there are always tweaks being made), and in the hopes that some­one else can use what I have built, I’m putting it all out for pub­lic con­sump­tion.

I would be remiss if I did not point out that while I cre­at­ed much of what is in these con­fig­u­ra­tion files, oth­er peo­ple cre­at­ed much more. As is the tra­di­tion in the open source world, I bor­rowed the best bits from a mul­ti­tude of peo­ple, sites, man­u­als, DIY guides, my whiskey col­lec­tion, and ran­dom deities to land at what is a fair­ly ser­vice­able set of files. I would expect noth­ing less than for the read­er to take all of this mess and make it his own. Just con­tribute back some­how if you find a bet­ter way of doing things.

So, with­out fur­ther ado, the con­fig­u­ra­tions are below.

In order to get mail flow­ing into my sys­tem I have to use two pro­grams: davmail, and mbsync. I have three accounts I reg­u­lar­ly use, two of which are IMAP, and one which is my cor­po­rate Exchange serv­er using EWS. The IMAP accounts are not too dif­fi­cult to get work­ing, but the Exchange account was a tad chal­leng­ing at first.

Mbsync is a pro­gram that just runs in the back­ground, col­lect­ing email from my accounts at a set inter­val: five min­utes at home, one minute on my cor­po­rate machine. Just to get it out of the way now, I use cron to keep that pro­gram going (I know, I know, dep­re­cat­ed on OS X, but I’ll keep using it until the last pos­si­ble sec­ond it is in the OS.) I hope if you are going down this road you know how to use cron, but if not, just type: crontab –e from a ter­mi­nal and put the fol­low­ing line in:

The ref­er­enced mbsync file below is san­i­tized, but should give you an idea of what’s going on. The only real caveat here is that you’ll want to pay very close atten­tion to for­mat­ting. The mbsync pro­gram expects every­thing to be in a very spe­cif­ic order, and those spaces in the file are a part of that. If in doubt, con­sult the doc­u­men­ta­tion. Oh, and the “pass­cmd” I have in there is using PGP to decrypt an encrypt­ed pass­word file I have for each account. That way I don’t have plain­text pass­words lay­ing around on my sys­tem.

Oh yes, and in this con­fig­u­ra­tion I pulled cer­tifi­cates from my two IMAP accounts using openssl and stored them in an .accounts direc­to­ry that I cre­at­ed. These are my con­ven­tions, by the way, and you are free to pick your own direc­to­ry struc­tures that make sense to you.

I decid­ed against using the OS X ~/Mail loca­tion in my home direc­to­ry and instead cre­at­ed a ~/.mail fold­er. There I cre­at­ed one direc­to­ry for each account, and then cre­at­ed an inbox fold­er. Every­thing else will take care of itself once mbsync starts pulling down data. The con­fig­u­ra­tion as I have it cre­ates fold­ers as need­ed to match the serv­er struc­ture.

Now, because my Exchange admin­is­tra­tors do not have IMAP con­fig­ured for access out­side of the cor­po­rate net­work, and I did not want to VPN in every time I need­ed to check my cor­po­rate email, I chose to use a pro­gram called davmail. Davmail works by con­nect­ing to your Exchange serv­er using native pro­to­cols (either EWS or Web­dav, depend­ing on the age of the serv­er.) It then expos­es a series of local ports that you can con­nect to using indus­try stan­dard pro­to­cols like IMAP, POP, SMTP, etc. It can be con­fig­ured to start and run as long as your com­put­er is up, and if you install it via brew, you’ll get a quick lit­tle com­mand to run once it’s been installed. The con­fig­u­ra­tion that end­ed up work­ing for me is below. Note that the ports I’m using are arbi­trary, you can use dif­fer­ent ones if desired.

The meat of the con­fig­u­ra­tion is the mut­trc file itself, and there is far too much in this file to cov­er every­thing. I’ll point out just a cou­ple of details, and leave the rest for the read­er to mod­i­fy and cajole as need­ed. Again, the Google machine is your friend, as is the very good Mutt doc­u­men­ta­tion you can find with just a cur­so­ry search.

I have sep­a­rat­ed my per-account con­fig­u­ra­tion into sep­a­rate files for two rea­sons: I like things clean and easy to change, and this way I can switch between accounts in a nice man­ner. Both of these goals are met with the ini­tial bind­ing of the F1, F2, and F3 keys to source those files. I also source them at the top of the file so that they are pre-pop­u­lat­ed when I start Mutt.

I have also added some PGP con­fig­u­ra­tion because that is one of the must-have fea­tures for me in an email client. I have auto­mat­ic sign­ing of mes­sages con­fig­ured, and auto­mat­ic decrypt­ing of encrypt­ed mail. I still have to tweak the key bind­ings a bit, but that’s a small task.

I have made some changes in the file to force emails, as much as pos­si­ble, to come across as text and not HTML, to pull cal­en­dar invites out appro­pri­ate­ly, and to offer attach­ments and the HTML ver­sion of the email as options. It is not always per­fect con­sid­er­ing that almost every­one and every email client wants to send large, hor­ri­bly bloat­ed, HTML-for­mat­ted emails willy-nil­ly, but it does alle­vi­ate the prob­lem quite a bit.

I’m going to leave this as an exer­cise for the read­er, but a quick note on search­ing: Mutt uses regex as its search method of choice, and for those of you who know what this means, let the rejoic­ing com­mence. It does have oth­er ways to search and lim­it, how­ev­er, so play around with all of the search modal­i­ties includ­ed, and you’ll find some­thing that works well for you.

Much of this makes sense once you get into the pro­gram and get used to the par­a­digm, but I’d prob­a­bly just leave this file large­ly intact until you get a han­dle on all of Mutt’s func­tion­al­i­ty. None of this is gospel, and one of the best parts about Mutt is that it real­ly is infi­nite­ly flex­i­ble. You can make it as much your own as you’d like. It prob­a­bly makes sense to do a Google images search for Mutt or Neo­mutt, just to see the myr­i­ad dif­fer­ent con­fig­u­ra­tions peo­ple have put togeth­er.

Here is an exam­ple of an indi­vid­ual Mutt con­fig­u­ra­tion file. This/these file/files should only include that con­fig­u­ra­tion which is unique to the ref­er­enced account. Try not to dupli­cate func­tion­al­i­ty here, just put in what you need.

I hope this helps some­one out there who may be as in love with the com­mand line as I am. If not, maybe all of this work serves as a warn­ing: there be drag­ons on the voy­age to com­mand line nir­vana. In the next chap­ter of what is like­ly going to be an ongo­ing saga in com­mand line shenani­gans, I’ll talk a bit about my home­grown com­mand line Twit­ter client: part util­i­ty, part tra­di­tion­al client writ large across the vaunt­ed ter­mi­nal.