Systems Aligned Logo Open Source. Open Business.
Call: +1-905-791-8015
 
Home
About Us
Services
Technology
Learning Centre
Contact Us
 
Maildir to mbox Conversion Utility PDF  | Print |  E-mail
Written by Brian Zammit   
Monday, 27 September 2004

Convert your qmail-style Maildir email folders into standard *nix style mbox files with ease.

There are a number of utilities to convert from mbox to Maildir, but only one working utility to convert from Maildir to mbox. Qmail itself comes with the working Maildir to mbox conversion utility, intuitively named maildir2mbox.  However, it is limited when working with non-standard Maildir's.  At the moment the process of converting subdirectories of Maildir's for a large number of users is very time consuming and clumsy at best.

Recently, one of our clients asked Systems Aligned to convert a number of non-standard Maildir's with subdirectories. Since an easy to use, reliable tool was not available, I wrote this script to help speed up the conversion process. With the hopes more individuals and organizations will benefit from Systems Aligned's work in the private sector, we are releasing the script to the public under the GPL.

This utility uses the Qmail maildir2mbox program as a base, and adds simple intelligence to automatically convert all the Maildir folders in a given users directory into mbox format. Credit goes to Charles Cazabon from the This e-mail address is being protected from spam bots, you need JavaScript enabled to view it mailing list for getting the script started.

This script was used on a production server running Red Hat Linux 9. The script should work unmodified on all Red Hat versions with /var/spool/mail/ as the default mbox mail spool, and on most other Linux distributions with little modification. A precompiled maildir2mbox executable is included with this how-to in case the system you are working on doesn't have qmail already installed. In this case, you would have to compile and install qmail to get the maildir2mbox executable.

DISCAIMER
The script has worked very well for Systems Aligned, but it may not work for you. We can not be held responsible for any damage it may inflict on your systems. As always, review the script before you use it to make sure it does not do anything harmful on your systems.

Instructions
  1. Download the mbox-auto conversion program and the maildir2mbox executable from the links on this article.
  2. Save both files in the /usr/local/bin directory. You can also save the files to any directory included in your user's path.
  3. Ensure regular users can access these files by running the following command as the root user (this is all entered on one line):

    # chmod +x /usr/local/bin/maildir2mbox /usr/local/bin/mbox-auto

  4. Change to the user with the Maildir's you want to convert (replace [username] with the login :

    # su - [username]

  5. Run the conversion utility:

    $ mbox-auto

    The mailboxes being converted and the location of where the mbox files have been created are displayed. Since this was written on Red Hat Linux 9, the default mail location of /var/spool/mail is used for the main Inbox. The users ~$HOME directory is used for any extra folders which may be found during the conversion process.

  6. Follow the instructions from the output of the conversion program. Exit from the user account to the root user, and change the permissions on the /var/spool/mail/user file:

    $ exit

    # chown [username]:mail /var/spool/mail/[username]
You're done!

Future enhancements may include modifying the script to convert the Maildirs within every user's ~$HOME directory, and automatically setting permissions of the mbox files.

I hope you find this script useful, and it saves you some time and sleep! Please contact me if you have any suggestions for improvement, code fixes, or questions.

Resources

Web Sites
  • Qmail web site
  • Going the other way: Mbox2maildir script from the Qmail site (no idea if this works, but included here for completeness).
  • Another Mbox2maildir script.  This one is by Juri Haberland (again, no idea if this works, but included here for completeness).
Downloadable Files
Last Updated ( Saturday, 23 April 2005 )
 
Client Login





Lost Password?