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`
Your script was very helpful. I changed "subscribed" to just "folders", but otherwise I'm using it as-is!