Home » Random Goodies » Importing a mbox export as a cPanel maildir

Importing a mbox export as a cPanel maildir

Have an mbox export that’s too big to use Horde import/fetchmail options? No worries, mb2md was successfully tested with MacMail and Thunderbird mbox exports.
Please note, the script requires the TimeDate Perl library to function.

Now for some output 🙂

[email protected] [/home/tooltest]# perl -MCPAN -e 'install Date::Parse'
[email protected] [/home/tooltest]# wget -q http://batleth.sapienti-sat.org/projects/mb2md/mb2md-3.20.pl.gz
[email protected] [/home/tooltest]# gzip -d mb2md-3.20.pl.gz
[email protected] [/home/tooltest]# chmod +x mb2md-3.20.pl
[email protected] [/home/tooltest]# ./mb2md-3.20.pl
Usage:
mb2md -h
mb2md [-c] -m [-d destdir]
mb2md [-c] -s sourcefile [-d destdir]
mb2md [-c] -s sourcedir [-l wu-mailboxlist] [-R|-f somefolder] [-d destdir] [-r strip_extension]
[email protected] [/home/tooltest]# ls INBOX.mbox
./ ../ Info.plist .lock mbox table_of_contents
[email protected] [/home/tooltest]# ./mb2md-3.20.pl -s /home/tooltest/INBOX.mbox/mbox -d /home/tooltest/mail/tooltest.com/test
Converting /home/tooltest/INBOX.mbox/mbox to maildir: /home/tooltest/mail/tooltest.com/test
Source Mbox is /home/tooltest/INBOX.mbox/mbox
Target Maildir is /home/tooltest/mail/tooltest.com/test
3081 messages.
[email protected] [/home/tooltest]# find /home/tooltest/mail/tooltest.com/test/cur -type f|wc -l
3081
[email protected] [/home/tooltest]#

Voila! We have successfully imported the mailbox, now for ownership and permissions…

[email protected] [/home/tooltest]# chown -R tooltest:tooltest mail/tooltest.com/test/{cur,new,tmp}/*
chown: cannot access `mail/tooltest.com/test/new/*': No such file or directory
chown: cannot access `mail/tooltest.com/test/tmp/*': No such file or directory
[email protected] [/home/tooltest]# chmod -R 660 mail/tooltest.com/test/{cur,new,tmp}/*
chmod: cannot access `mail/tooltest.com/test/new/*': No such file or directory
chmod: cannot access `mail/tooltest.com/test/tmp/*': No such file or directory
[email protected] [/home/tooltest]#

No worries on the “errors” as they are only present if the folders are empty. At this point, you can refresh your webmail client and view the successfully imported emails considering you replaced the user ‘tooltest’ with the one in question.