Migrating MBOX to MAILDIR

While the option to use MAILDIR has been around for nearly two years, cPanel/WHM has only recently made MAILDIR the default. Until v11 (approx, sorry, I can’t remember the exact version number), the default has been to use cPanel’s own POP3 server with MBOX, but this isn’t always the best solution.

The problem is that MBOX stores all mails in one file, which can get very large, very fast, which in turn can be a resource hog and slow things down. This file is also locked when the user is downloading mail, so if they collect mail frequently and/or have a slow connection, delivery can be delayed.

MAILDIR on the other hand, stores each e-mail in a separate file, which means that reading individual mails is faster, and there is no delay in mail delivery, and is generally less resource hungry. A side effect of this is that webmail should also be faster to use.

As for converting from MBOX to MAILDIR, cPanel has provided a script called "covert2maildir", which will do just about all of the work for you.

To start, you will need to log in as root and run /scripts/convert2maildir, you’ll then be presented with some output similar to this: 

 

NOTE: For users using POP accounts, converted messages will appear as new and will download twice. Users should re-download their messages after the conversion completes.

maildir is not active, this system is using mbox

Mail Directory (maildir) Conversion System

1) Restore system to mbox (non-maildir) state.
2) Request Technical Support
3) Convert partially converted mail accounts
*) Exit

If it says "maildir is enabled", then you do not have to do anything further (perhaps you only recently installed cPanel).

The first thing you should do (perhaps obviously) is to select option 1, and to backup user’s mail boxes (you may have to select a backup destination in WHM’s backup options first). You don’t absolutely have to do this, but it’s always better to err on the safe side.

When the backup has completed, you can then select option 3, and let the script get on with converting the mail boxes. You will have to be patient – if you have many users with a lot of, or large, mail boxes, it can take many hours to complete. If you want to leave it to get on and disconnect from the server, you can use the screen utility to launch the script (however, I do not advise leaving screen installed as it can be a security risk, but it is handy to use on occasion).

Once the script has started, it will give you the path and name of the log file, which you should tail and check to see if any errors have occurred. During the migration, mail will not be delivered and will be held in the mail queue until the script has finished, so no new incoming mail should be lost.