Created
October 29, 2014 14:02
-
-
Save sblmasta/e139c2f7abf07a01ce68 to your computer and use it in GitHub Desktop.
Convert mailboxes from ISPConfig postfix to Postfixadmin structure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$db = new PDO('mysql:host=localhost;dbname=postfix;charset=utf8', 'root', 'admin'); | |
$stmt = $db->query("SELECT * FROM mail_user"); | |
foreach( $stmt->fetchAll(PDO::FETCH_ASSOC) as $row ) | |
{ | |
$email = $row['email']; | |
$login = explode('@',$email)[0]; | |
$domain = explode('@',$email)[1]; | |
$quota = $row['quota']; | |
$name = $row['name']; | |
$passwd = $row['password']; | |
$query = $db->prepare("INSERT INTO mailbox(username, password, name, maildir, quota, local_part, domain) VALUES(:username, :password, :name, :maildir, :quota, :local_part, :domain)"); | |
$query->execute(array(':username' => $email, ':password' => $passwd, ':name' => $name, ':maildir' => $domain.'/'.$login.'/Maildir/', ':quota' => $quota, ':local_part' => $login, ':domain' => $domain)); | |
$query = $db->prepare("INSERT INTO alias(address, goto, domain) VALUES(?,?,?)"); | |
$query->execute(array($email, $email, $domain)); | |
} | |
$stmt = $db->query("SELECT * FROM mail_forwarding"); | |
foreach( $stmt->fetchAll(PDO::FETCH_ASSOC) as $row ) | |
{ | |
$source = $row['source']; | |
$destination = $row['destination']; | |
$domain = explode('@', $source)[1]; | |
$dst = rtrim(implode(',', explode("\n", $destination)), ','); | |
$dst = str_replace("\n", "", $dst); | |
$dst = str_replace("\r", "", $dst); | |
$query = $db->prepare("INSERT INTO alias(address, goto, domain) VALUES(?,?,?)"); | |
$query->execute(array($source, $dst, $domain)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment