1 (edited by LordOfLA 2010-03-08 15:29:41)

Topic: [FreeBSD] Export cPanel domains/mailboxes/aliases to iRedMail-0.6.0

I recently converted a cPanel machine used only for email to an iRedMail-0.6.0-beta3 setup. To save myself time I knocked up a small command line PHP script to run on the cPanel server to export cPanel domains, mailboxes and aliases/forwarders to the iRedMail MySQL layout.

The code is not perfect (typing this up I've just noticed that I've worked around a bug in my own code tongue ) and I intend to modify it to allow a switch between exporting for primary MX and backup MX data generation (which I will post here), but it works and certainly on FreeBSD > FreeBSD migrations mailboxes don't need new passwords setting!

To filter out cPanel's weird aliases and strip all catch-all mail aliases I use email validation code by:

Michael Rushton which you can get at http://squiloople.com/ as well as the attached file.

Enjoy!

Edit: changed from 7zip to normal zip

Post's attachments

cpanel_mail_to_sql.zip 1.84 kb, 27 downloads since 2010-03-08 

You don't have the permssions to download the attachments of this post.

2

Re: [FreeBSD] Export cPanel domains/mailboxes/aliases to iRedMail-0.6.0

Looks pretty cool. Any comment about how to use it?

3

Re: [FreeBSD] Export cPanel domains/mailboxes/aliases to iRedMail-0.6.0

sure, just upload the two php files to the same folder on your cpanel server, check that the files I use (defined at the bottom after"// Main script code starts here") are the same on your cpanel machine as they are on my FreeBSD one. Edit accordingly, then run the script with the following command:

php cpanel_mail_to_sql.php

This should give you a file called "mail_sql_file.sql" in /root/ if you leave at defaults which you can then use with phpmyadmin to import in to the vmail database created by the iRedMail installer.

It will replace existing data in the domain, alias and mailbox tables. Some modification will be needed to have it add to existing data.

4

Re: [FreeBSD] Export cPanel domains/mailboxes/aliases to iRedMail-0.6.0

Can you upload a zip file instead of 7zip? sad

5

Re: [FreeBSD] Export cPanel domains/mailboxes/aliases to iRedMail-0.6.0

Zip file attached in first post as requested.

6

Re: [FreeBSD] Export cPanel domains/mailboxes/aliases to iRedMail-0.6.0

LordOfLA wrote:

Zip file attached in first post as requested.

Thanks smile

Some suggestions/questions:

  • Since it will drop exist databases/tables, it's better to warn users before continue.

  • Why not use 'SOURCE' command to create necessary tables with iRedMail SQL structure template file instaed of hard-code SQL statements in PHP?

  • Use command line position arguments instead of hard-code file locations, names.

  • It would be great if you can describe cPanel SQL structure here. Maybe i should describe iRedMail SQL structure so that others can migrate accounts from any other mail server.

  • You didn't have table 'mailbox', column 'mailbox.basestoragedirectory', etc.

I'm not a PHP programmer, please correct me if i'm wrong. smile

7

Re: [FreeBSD] Export cPanel domains/mailboxes/aliases to iRedMail-0.6.0

1. Since it only generates a SQL file - the user can edit it and pull out the DROP and CREATE TABLE lines since they will be at the top.

2. This script was run on a totally different machine than the one iRedMaill was installed on, I wouldn't suggest installing iRedMail directly on to a cPanel machine uless you really like challenges.

3.  With the exception of storagebasedirectory all locations can be changed by editing variables as needed.

4. cPanel doesn't use SQL it uses flat-textfiles. I will be able to post examples later in the day.

5. For the mailbox data take a look at the following:

VALUES ('$username', '$password', '$name', '/usr/vmail/vmail01', '$home', 0,

The last 2 values (except the 0) are storagebasedirectory and maildir respectively.

Also I'm not the worlds best PHP programmer myself I'm sure it's not a perfect example of how the conversion could be done.