Created
June 28, 2013 04:24
-
-
Save pixline/5882456 to your computer and use it in GitHub Desktop.
IMAP to IMAP batch mailbox migration. Requires imapsync (http://imapsync.lamiral.info/)
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
#!/usr/bin/php | |
# | |
# Usage: ./imapsync.sh accounts.csv | |
# | |
# CSV account schema: | |
# old_username;old_password;new_username;new_password | |
# | |
<?php | |
define('HOST_FROM', 'imap.example.com'); | |
define('HOST_TO', 'imap.example.org'); | |
define('DOMAIN', 'example.com'); | |
if(!$argv[1]) die("USAGE: ".$argv[0]." <csv_file>\n\n"); | |
$fh = fopen($argv[1], 'r+'); | |
$contents = fread($fh, filesize($argv[1])); | |
fclose($fh); | |
$cn = explode("\n",$contents); | |
foreach($cn as $c): | |
$n = explode(";",$c); | |
if($n[0]!=""): | |
$cmd = "/usr/bin/imapsync \ | |
--host1 ".HOST_FROM." --user1 ".$n[0]." --password1 ".$n[1]." \ | |
--host2 ".HOST_TO." --user2 ".$n[2]."@".DOMAIN." --password2 ".$n[3]." \ | |
--subscribed --subscribe --useheader Message-ID --idatefromheader --authmech1 LOGIN --authmech2 LOGIN --ssl2 \ | |
--buffersize 614400000 --skipsize"; | |
passthru($cmd); | |
endif; | |
endforeach; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Debian setup:
Perl CPAN setup: