Converting Mbox mailboxes to Maildir format

From PeTechWiki
Jump to navigationJump to search

Overview

Maildir is a structure for directories of incoming mail messages that solves the reliability problems that plague mbox files. A directory in maildir format has three subdirectories, all on the same filesystem: tmp, new, and cur.

Each file in new is a newly delivered mail message. Files in cur are just like files in new. The big difference is that files in cur are no longer new mail: they have been seen by the user's mail-reading program. The tmp directory is used to ensure reliable delivery. For a new user who does not have existing mail messages in mbox format, all that is required is to create the ~/Maildir directory and its tmp, new, and cur subdirectories all owned by the user.

The mb2md conversion script

For an existing user who has mail messages in mbox format, the mb2md script is useful for converting the messages to maildir format.

Download

Download from http://www.akadia.com. Version: mb2md-3.10 (requires TimeDate!)

Download from mirror at https://petech.com. Version: mb2md-3.10 (requires TimeDate!)

Installation

Extract the mb2md script and copy it to the file mb2md somewhere in your path. Set the mb2md file permissions +x.

To install the TimeDate perl library, extract the files from the archive to a temporary location. Change the current directory to the extracted folder and run the following commands:

perl Makefile.PL
make
make test
make install

Example Usage

For detailed usage and examples, see the comments at the beginning of the mb2md script. For usage summary type mb2md -h.

We have a bunch of directories of Mbox mailboxes located at: /home/blah/oldmail/. We also have the mailspool Inbox at: /var/spool/mail/blah.

To convert these, as user blah, we give the first command:

mb2md -m

The main Maildir directory will be created if it does not exist. (This is true of any argument options, not just "-m".)

/home/blah/Maildir/

It has the following subdirectories:

/home/blah/Maildir/tmp/
/home/blah/Maildir/new/
/home/blah/Maildir/cur/

Then /var/spool/blah file is read, split into individual files and written into /home/blah/Maildir/new/.

Now we give the second command:

mb2md  -s oldmail -R

This reads recursively all Mbox mailboxes and writes folders and files in Maildir format into /home/blah/Maildir.

Reference: Converting Mbox mailboxes to Maildir format

Configuring mail servers for Maildir delivery

Configuring procmail for Maildir

Create the configuration file /etc/procmailrc for global implementation or you may create per user basis file in $HOME/.procmailrc.

Add the following contents to it:

PATH=/usr/local/bin:/usr/bin:/bin
MAILDIR=$HOME/Maildir
DEFAULT=$MAILDIR/new   #completely optional
# LOGFILE=$MAILDIR/log   #recommended
LOGFILE=/var/log/procmail   #or this

Reference: Sendmail with MAILDIR format delivery

Configuring sendmail to use procmail

To setup sendmail to handle mail delivery by procmail, in /etc/mail/sendmail.mc file edit the following line:
Existing settings:

dnl # FEATURE(local_procmail, `', `procmail -t -Y -a $h -d $u')dnl

Modified Settings:

FEATURE(local_procmail)dnl
MAILER(procmail)dnl

Make and restart sendmail.

Reference: Sendmail with MAILDIR format delivery

Configuring postfix to use procmail

Edit the configuration file /etc/postfix/main.cf to contain the following line:

mailbox_command = /usr/bin/procmail -a "$EXTENSION"

Restart postfix.

Configuring dovecot for Maildir

Edit the configuration file /etc/dovecot/conf.d/10-mail.conf to contain the following line:

mail_location = maildir:~/Maildir

Restart dovecot.