Saturday, August 8, 2009

Configuring Mutt with Multiple IMAP Accounts

So I've been taken in by the console/screen camp. This may be
fallacious, but I've seen a marked increase in my productivity through the
bind/macro flexibility and all around customization available in many of the
console based programs to which I've switched. Flexibility I was unable to find to the same extent in many of their GUI alternatives.

Obviously, this particular article is about Mutt, which I've selected to replace my use of thunderbird/gmail website as an e-mail client.

For information on Mutt, you can check the webpage at www.mutt.org
If you've read their introduction and you're still interested, read on.


So the purpose of this post is to explain some of the bits of configuring IMAP
for multiple accounts that didn't present itself plainly in all of the guides I
stumbled upon while customizing my Mutt configuration. I'll run through the gist
of what I found, and then explain what I did in addition to get a configuration
that was comfortable for me.

When specifying multiple IMAP accounts, you'll want to leverage the
account-hook and folder-hook configuration options in you're
~/.muttrc file.

first, you'll want to set a baseline for your account-hooks:
account-hook . 'unset imap_user imap_pass tunnel'
Then you'll want to configure your two (or more) servers:
account-hook imap://server/ 'set imap_user=username \
imap_pass=password'
folder-hook imap://server/ 'set folder=imap://server/ \
record="+Sent" \
postponed="+Drafts" \
from="Real Name <email@address>"'

account-hook imap://server1/ 'set imap_user=username1 \
imap_pass=password1'
folder-hook imap://server1/ 'set folder=imap://server1 \
record="+Sent" \
postponed="+Drafts" \
from="Real Name <email1@address1>"'
Clearly, you'll want these settings to match the expected configuration for the server to which you're connecting , but this represents fairly general defaults. If your imap server is using SSL/TLS you'll want to change your imap://server specification to imaps://server. Additionally, you should append any non-standard port specifications to the root folder specification e.g. set folder=imaps://server:port/

Also, be advised that record and postponed as defined are relative paths, indicating that the full folder is the relative appended to the end of the string specified for folder. The proper setting for these variables are dependant on the particulars of the server to which you are connecting.

For an explanation of what each of these variables do, and for more information on how to tailor them to your needs, take a look at: man muttrc

One last thing that you may want to do is inform Mutt of folders you're interested in polling for received mail. This can be accomplished via the mailboxes command. Using our configuration above, and assuming your incoming mail is dumped into INBOX, you'd want the following:
mailboxes imap://server/INBOX imap://server1/INBOX
Now I wanted to be able to start mutt, then, through a keystroke, bring up a list of my configured accounts, and select one, yielding an index of the appropriate folder. this can be accomplished with the following
macro index,page y '<change-folder>?<toggle-mailboxes>'
Another beneficial modification is to actually bind imap-fetch-mail to something. The usual fetch-mail will do nothing for you here
bind index G imap-fetch-mail

All of the above is fairly readily available with a modicum of googling and manual reading. However, the last bit took me a little while to realize. A really crucial element that I felt was missing was a really obvious way of interacting with my imap folders. I wanted to be able to connect to an account using the y key as specified above, but that I also wanted a way to effortlessly list folders in that account once connected. The most present issue was that my selecting an account did not change the list directory to the appropriate imap folder, thereby forcing me to input the imap server I was connected to before I would be greeted with a list of my folders. To implement comfortable functionality, I augmented the above configuration with the following:
folder-hook . 'macro index,page i "<change-folder>?<toggle-mailboxes>"'


This bit placed directly following the account-hook of the same regex (account-hook .) specified above. Its function is to set a sensible default bind for the i key. My default is that if I haven't yet specified an account to connect to (thus am connected to nothing as I use only IMAP), I want it to act exactly like the y key, informing me that I am not connected by presenting me with my choices of accounts.

We then append macro index,page i "<change-folder>?c^A^K=^M" to each of the folder-hooks specified for our accounts. For example:
folder-hook imap://server/ 'set folder=imap://server/ \
...
from="Real Name <email@address>"; \
macro index,page i "<change-folder>?c^A^K=^M"'
This makes it so that hitting i once you've connected to an account will automatically ensure that your list directory is the top level of the appropriate account, properly listing its top level subfolders. The last bit is to allow i to properly show you the current level of folders, following you appropriately through your depth in the IMAP folder tree. To do this we add a line directly following each account folder-hook:
folder-hook imap://server/.+/.+ 'macro index,page i "<change-folder>?"'
directly follows the extant folder-hook imap://server/ entry, and a similarly formatted entry follows the folder-hook imap://server1/ entry, substituting server1 for server

This provides the wanted behavior where i will operate as a sensible folder-list, and y will operate as an account list. Please comment with any modifications or approaches that would reduce the complexity/stupidity of my approach. Hope this helps someone trying to accomplish a similar goal.

Saturday, August 1, 2009

Got bored with the Brown. Went Jet Blue.



Not sure how I feel about it yet, but hey, what the hell. Again, fluxbox. Conky at the bottom. GTK theme unseen, but also similar.

Monday, July 20, 2009

New chocolate theme, say whaaaaa!

So, I got bored with all of my themes, and really really really exhausted with super low contrast grey on grey combinations. So I decided to make this theme.

This is Fluxbox with Gtk.

E-mail me if you're interested in the files. They're not 100% finished in my eyes yet, so I haven't posted them anywhere.

Monday, May 11, 2009

Wow, first post... it feels so fresh!

Figured that this may be a good place to collect random thoughts for my own perusal at a later date.

You know... random thoughts, recipes, lalalalala.