Bringing Mutt and IMAP a little closer together

Recently I decided to tinker with my email paradigm on my network here at home. I used to run fetchmail on my main machine to gather all the email from my various accounts (passing it through procmail of course). Unfortunately, when I boot into Windows, I completely lose access to my mail. So, I installed dovecot on my extra/server machine, and copied over my fetchmail/procmail setup. Now I can access my email in both operating systems, and using practically any mail client I feel like using (usually mutt, but sometimes evolution or thunderbird).

Unfortunately, the little trick I used to let mutt know about all the mailboxes my procmail recipies create no longer works, as the folders are not physically located on my machine. I could do it manually, but IMAP already allows for something like this with its folder subscibing feature. Mutt supports this somewhat, but not to the extent that I would like (i.e. it can list subscribed folders, but it will not look for new mail in them, which is what I really want). So, I took a few minutes and threw together a quick perl script to list all my subsctibed folders in a mutt-compatible format.

Here's the code:

#!/usr/bin/perl

use Mail::IMAPClient;

my $server = shift;
my $user = shift;
my $pass = shift;

my $imap = Mail::IMAPClient->new (
    Server => $server, 
    User => $user, 
    Password => $pass,
    ) or die "Cannot connect to $server as $user: $@";

my @subscribedFolders = $imap->subscribed
                or warn "Could not find subscribed folders: $@\n";

map { print " =$_"; } @subscribedFolders;

It is certainly not robust, but it gets the job done for the time being. And besides, it gave me a good excuse to play around with Mail::IMAPClient.

Here is the line in my ~/.muttrc file that uses the script:

mailboxes `/usr/bin/perl ~/imapFolders.pl server rayners mypassword`

1 Comment

Your script was very helpful. I changed "subscribed" to just "folders", but otherwise I'm using it as-is!

Leave a comment

Recent Entries

  • Plugin Writing 101

    So, I’m planning on writing up some entries about various aspects of plugin development. While I have a couple topics already in mind, I thought...

  • The Olympics Make Me Want To Compete Again

    Every time the Olympics come around (most the summer ones) I always start to delude myself into thinking I could complete once again in the...

  • Minimalist plugins are fun!

    Last night I whipped up one of the smallest plugins I’ve ever written. It is so small in fact that I was able to stuff...

  • Feedburner Widget on MT News

    Movable Type News A WordPress 2.5 Upgrade Guide: And of course there are lots of third-party plugins for the MT dashboard, to integrate statistics and...

  • AD&D Monster Stats for the Presidential Canditates

    Charles Stross (scifi author, D&D nerd, and former perl columnist) posted Politics as she is Played with 3d6: The recent death of Gary Gygax, who...

Close