Writings Photos Code Contact Resume Me
Using mutt as a mailbox converter
Submitted by msameer on Mon, 19/05/2008 - 3:31pm

I'm planning to move all my mailboxes to an IMAP server running on foolab.org, use offlineIMAP to sync between vader "my laptop" and naboo "foolab.org". It will also allow me to access my email from multiple computers at the same time.

I'm using mutt as my primary email client.

The big problem is offlineIMAP needs a local Maildir while I'm using mbox

I can upload the emails from mutt to the IMAP server but why do I have to redownlosd them again ? Beside, it's a lot of manual work.

I didn't really find a good mbox to maildir converter so I decided to use mutt.

Mutt knows how to handle such things. It's an email reader!

Thanks to the folks in #mutt for a few tips. Now here is my setup:

1) My mail is in ~/Mail
2) I don't have subdirectories
3) No white spaces in folder names.
4) You don't have a mailbox called "foo" ;-)
5) Create a directory called done. There we will place the mbox files after processing.

Now here how it goes:

1) Place this in a file, let's call it "/tmp/muttrc" and use emacs for that ;-)

macro index <F3> "<tag-pattern>~A<enter><tag-prefix><copy-message>=foo<enter>y<quit>y"
folder-hook . push <F3>

2) cd ~/Mail

3) Execute this bash snippet:

for i in `find -maxdepth 1 -type f`; do box=`basename $i`;
  echo "Processing $box" && mutt -F /tmp/muttrc  -n -m Maildir -R -f $box && mv $box done/ && mv foo  $box; done

4) Now to convert my outbox "which is an MH dir":

mutt -F /tmp/muttrc   -n -m Maildir -R -f done/outbox/

It worked fine for me. I had to interfere 2 times because I 2 had 0 sized mailboxes. Otherwise, it worked like a charm!

P.S. Don't forget to edit ~/.procmailrc and to set the default mutt mbox_type to Maildir

Syndicate content  digg  bookmark

Submitted by Emmanuel (not verified) on Tue, 20/05/2008 - 11:13pm.

And you can get mutt to delete empty mboxes with the variable: set save_empty=no

Submitted by Christian (not verified) on Tue, 20/05/2008 - 11:31pm.

I have done something similar previously.
My temporary muttrc file looks like this:

# Maildir, MH, mbox or MMDF
set mbox_type=Maildir

set my_archivedir="~/mutt_archive/$mbox_type"

set confirmcreate=no

set confirmappend=yes

set quit=yes

folder-hook . 'push <tag-pattern>~A<enter>\
<tag-prefix><copy-message><kill-line>\
$my_archivedir<enter><quit>'

Then called mutt with mutt -F ./muttrc -f mailbox
and it would convert the mailbox to the selected format below ~/mutt_archive/
(which must exist).

(I haved blogged about this in German at http://blog.256bit.org/archives/345-Mutt-als-Mailbox-Konvertierer.html)

Post new comment
(If you're a human, don't change the following field)
Your first name.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <s> <li> <ol> <u> <ul> <br> <br /> <blockquote>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options