This commit is contained in:
Nick Bebout 2011-03-12 02:44:19 +00:00
parent 3895b22b0a
commit 05cda6e79b
9 changed files with 273 additions and 12 deletions

11
CREDITS
View file

@ -1,9 +1,20 @@
#!/bin/cat #!/bin/cat
Arnaud Launay
Bug about --expunge12 (no option code)
Kirk Averett
Bug about --subscribed option. I stupidly
commented a map line in release 1.138
Here are the persons who helped me to develop imapsync. Here are the persons who helped me to develop imapsync.
Feel free to tell me if a name is missing or if you want Feel free to tell me if a name is missing or if you want
to remove one. to remove one.
Evert Mouw
Gave the "Term::ReadKey" module dependency problem.
Roy Hoobler Roy Hoobler
Problems with big folders. Problems with big folders.
Bug about message sizes. Bug about message sizes.

View file

@ -1,15 +1,25 @@
RCS file: RCS/imapsync,v RCS file: RCS/imapsync,v
Working file: imapsync Working file: imapsync
head: 1.140 head: 1.142
branch: branch:
locks: strict locks: strict
gilles: 1.142
access list: access list:
symbolic names: symbolic names:
keyword substitution: kv keyword substitution: kv
total revisions: 140; selected revisions: 140 total revisions: 142; selected revisions: 142
description: description:
---------------------------- ----------------------------
revision 1.142 locked by: gilles;
date: 2005/11/16 01:08:49; author: gilles; state: Exp; lines: +7 -5
Added expunge1 and expunge2 getoption code
----------------------------
revision 1.141
date: 2005/11/16 01:05:16; author: gilles; state: Exp; lines: +6 -6
fixed bug about subscribed folders. Was introduced
by a line commented in 1.137
----------------------------
revision 1.140 revision 1.140
date: 2005/10/30 10:16:52; author: gilles; state: Exp; lines: +21 -8 date: 2005/10/30 10:16:52; author: gilles; state: Exp; lines: +21 -8
Added --expunge1 --expunge2 options Added --expunge1 --expunge2 options

View file

@ -1,4 +1,4 @@
# $Id: INSTALL,v 1.8 2005/06/21 01:29:55 gilles Exp gilles $ # $Id: INSTALL,v 1.9 2005/11/16 01:14:18 gilles Exp gilles $
# #
# INSTALL file for imapsync # INSTALL file for imapsync
# imapsync : IMAP sync or copy tool. # imapsync : IMAP sync or copy tool.
@ -37,6 +37,8 @@ You need :
perl -mDigest::MD5 -e 'print $Digest::MD5::VERSION, "\n"' perl -mDigest::MD5 -e 'print $Digest::MD5::VERSION, "\n"'
I use 2.20 (debian package) I use 2.20 (debian package)
- Term::ReadKey
- (Option) Perl Digest::HMAC_MD5 module - (Option) Perl Digest::HMAC_MD5 module
Good for non plain text password over network. Good for non plain text password over network.

4
README
View file

@ -2,7 +2,7 @@ NAME
imapsync - IMAP synchronization, copy or migration tool. Synchronize imapsync - IMAP synchronization, copy or migration tool. Synchronize
mailboxes between two imap servers. Good at IMAP migration. mailboxes between two imap servers. Good at IMAP migration.
$Revision: 1.140 $ $Revision: 1.142 $
INSTALL INSTALL
imapsync works fine under any Unix OS. imapsync works fine under any Unix OS.
@ -261,5 +261,5 @@ AUTHOR
teaching free open and gratis softwares. Don't hesitate to pay him for teaching free open and gratis softwares. Don't hesitate to pay him for
that services. that services.
$Id: imapsync,v 1.140 2005/10/30 10:16:52 gilles Exp $ $Id: imapsync,v 1.142 2005/11/16 01:08:49 gilles Exp gilles $

9
RECORD Normal file
View file

@ -0,0 +1,9 @@
-------------------------------------------------------------------------------
Olivier Morel:
Nous avons terminé notre migration et récupéré l'ensemble des boites aux lettres grace à votre outil, tout s'est déroulé à merveille (18 heures de traitement)
- 2200 Boites aux lettres
- 18 Go
- récupération via .bat

3
TODO
View file

@ -1,6 +1,9 @@
TODO file for imapsync TODO file for imapsync
---------------------- ----------------------
Add an --exactsync option to remove target messages
that are not on source.
Read the IMAP RFC http://www.faqs.org/rfcs/rfc3501.html Read the IMAP RFC http://www.faqs.org/rfcs/rfc3501.html
Respect the NAMESPACE behavior like the RFC. Respect the NAMESPACE behavior like the RFC.

View file

@ -1 +1 @@
1.140 1.142

View file

@ -6,7 +6,7 @@ imapsync - IMAP synchronization, copy or migration
tool. Synchronize mailboxes between two imap servers. Good tool. Synchronize mailboxes between two imap servers. Good
at IMAP migration. at IMAP migration.
$Revision: 1.140 $ $Revision: 1.142 $
=head1 INSTALL =head1 INSTALL
@ -305,7 +305,7 @@ Gilles LAMIRAL earn his living writing, installing,
configuring and teaching free open and gratis configuring and teaching free open and gratis
softwares. Don't hesitate to pay him for that services. softwares. Don't hesitate to pay him for that services.
$Id: imapsync,v 1.140 2005/10/30 10:16:52 gilles Exp $ $Id: imapsync,v 1.142 2005/11/16 01:08:49 gilles Exp gilles $
=cut =cut
@ -350,7 +350,7 @@ my(
use vars qw ($opt_G); # missing code for this will be option. use vars qw ($opt_G); # missing code for this will be option.
$rcs = ' $Id: imapsync,v 1.140 2005/10/30 10:16:52 gilles Exp $ '; $rcs = ' $Id: imapsync,v 1.142 2005/11/16 01:08:49 gilles Exp gilles $ ';
$rcs =~ m/,v (\d+\.\d+)/; $rcs =~ m/,v (\d+\.\d+)/;
$VERSION = ($1) ? $1 : "UNKNOWN"; $VERSION = ($1) ? $1 : "UNKNOWN";
@ -387,8 +387,8 @@ $error=0;
my $banner = join("", my $banner = join("",
'$RCSfile: imapsync,v $ ', '$RCSfile: imapsync,v $ ',
'$Revision: 1.140 $ ', '$Revision: 1.142 $ ',
'$Date: 2005/10/30 10:16:52 $ ', '$Date: 2005/11/16 01:08:49 $ ',
"\n", "\n",
"Mail::IMAPClient version used here is ", "Mail::IMAPClient version used here is ",
$VERSION_IMAPClient,"\n" $VERSION_IMAPClient,"\n"
@ -539,7 +539,7 @@ die unless $to->IsAuthenticated();
my (@f_folders, @t_folders, %fs_folders); my (@f_folders, @t_folders, %fs_folders);
# Make a hash of subscribed folders in source server. # Make a hash of subscribed folders in source server.
# map { $fs_folders{$_}=1 } $from->subscribed(); map { $fs_folders{$_}=1 } $from->subscribed();
@ -1029,6 +1029,8 @@ sub get_options
"foldersizes!" => \$foldersizes, "foldersizes!" => \$foldersizes,
"dry!" => \$dry, "dry!" => \$dry,
"expunge!" => \$expunge, "expunge!" => \$expunge,
"expunge1!" => \$expunge1,
"expunge2!" => \$expunge2,
"subscribed!" => \$subscribed, "subscribed!" => \$subscribed,
"subscribe!" => \$subscribe, "subscribe!" => \$subscribe,
"justconnect!"=> \$justconnect, "justconnect!"=> \$justconnect,

View file

@ -0,0 +1,224 @@
--- imapsync 2005-07-16 08:46:35.000000000 -0400
+++ ../imapsync.ssl 2005-10-05 14:46:23.000000000 -0400
@@ -38,7 +38,8 @@
[--user1 <string>] [--passfile1 <string>]
[--host2 server2] [--port2 <num>]
[--user2 <string>] [--passfile2 <string>]
- [--noauthmd5]
+ [--noauthmd5] [--authusing <string> --prefix1 <string>]
+ [--authmech <string]
[--folder <string> --folder <string> ...]
[--include <regex>] [--exclude <regex>]
[--prefix2 <string>] [--regextrans2 <regex>]
@@ -61,6 +62,7 @@
[--debug] [--debugimap]
[--timeout <int>] [--fast]
[--version] [--help]
+ [--ssl]
=cut
# comment
@@ -315,25 +317,28 @@
use Digest::MD5 qw(md5_base64);
use Term::ReadKey;
#use Digest::HMAC_MD5;
+use IO::Socket::SSL;
+use MIME::Base64;
eval { require 'usr/include/sysexits.ph' };
my(
$rcs, $debug, $debugimap, $error,
- $host1, $host2, $port1, $port2,
- $user1, $user2, $password1, $password2, $passfile1, $passfile2,
+ $host1, $host2, $port1, $port2,
+ $user1, $user2, $password1, $password2, $passfile1, $passfile2,
@folder, $include, $exclude, $prefix2, $regextrans2, @regexmess,
+ $authusing, $prefix1, $authmech,
$sep1, $sep2,
- $syncinternaldates, $syncacls,
+ $syncinternaldates, $syncacls,
$fastio1, $fastio2,
- $maxsize, $maxage,
+ $maxsize, $maxage,
$skipheader, @useheader,
$skipsize, $foldersizes, $buffersize,
- $delete, $expunge, $dry,
+ $delete, $expunge, $dry,
$authmd5,
$subscribed, $subscribe,
- $version, $VERSION, $help,
+ $version, $VERSION, $help,
$justconnect, $justfolders,
$fast,
$mess_size_total_trans,
@@ -341,8 +346,9 @@
$mess_size_total_error,
$mess_trans, $mess_skipped,
$timeout, # whr (ESS/PRW)
- $timestart, $timeend, $timediff,
+ $timestart, $timeend, $timediff,
$timesize, $timebefore,
+ $usessl
);
use vars qw ($opt_G); # missing code for this will be option.
@@ -406,11 +412,11 @@
}
$host1 || missing_option("--host1") ;
-$port1 = (defined($port1)) ? $port1 : 143;
+$port1 = (defined($port1)) ? $port1 : ((defined($usessl)) ? 993 : 143);
$user1 || missing_option("--user1");
$host2 || missing_option("--host2") ;
-$port2 = (defined($port2)) ? $port2 : 143;
+$port2 = (defined($port2)) ? $port2 : ((defined($usessl)) ? 993 : 143);
$user2 || missing_option("--user2");
$authmd5 = (defined($authmd5)) ? $authmd5 : 1;
@@ -424,8 +430,8 @@
@useheader = ("ALL") unless (@useheader);
-print "From imap server [$host1] port [$port1] user [$user1]\n";
-print "To imap server [$host2] port [$port2] user [$user2]\n";
+(defined($authusing)) ? print "From imap server [$host1] port [$port1] user [$user1] authusing [$authusing]\n" : print "From imap server [$host1] port [$port1] user [$user1]\n";
+(defined($authusing)) ? print "To imap server [$host2] port [$port2] user [$user2] authusing [$authusing]\n" : print "To imap server [$host2] port [$port2] user [$user2]\n";
$password1 || $passfile1 || do {
print "What's the password for $user1\@$host1? ";
@@ -447,8 +453,9 @@
my $from = ();
my $to = ();
-my $authmech = "CRAM-MD5";
-
+if (!defined($authmech)) {
+ $authmech = "CRAM-MD5";
+}
$timestart = time();
$timebefore = $timestart;
@@ -474,7 +481,19 @@
sub login_imap {
my($host, $port, $user, $password,
$debugimap, $timeout, $fastio) = @_;
- my $imap = Mail::IMAPClient->new();
+ my ($imap);
+ if ($usessl) {
+ my $ssl = new IO::Socket::SSL("$host:$port");
+ die ("Error connecting - $@") unless defined $ssl;
+ $ssl->autoflush(1);
+
+ $imap = Mail::IMAPClient->new(
+ Socket => $ssl,
+ Server => $host,
+ );
+ } else {
+ $imap = Mail::IMAPClient->new();
+ }
$imap->Server($host);
$imap->Port($port);
$imap->Fast_io($fastio);
@@ -482,13 +501,17 @@
$imap->Uid(1);
$imap->Peek(1);
$imap->Debug($debugimap);
- $imap->connect()
- or die "Can not open imap connection on [$host] with user [$user] : $@\n";
- if ($timeout) # whr (ESS/PRW)
- {
- $imap->Timeout($timeout);
- print "Setting imap timeout to $timeout\n";
- }
+ $imap->Authcallback(\&plainauth);
+ if ($usessl) {
+ $imap->State(Mail::IMAPClient::Connected);
+ } else {
+ $imap->connect()
+ or die "Can not open imap connection on [$host] with user [$user] : $@\n";
+ }
+ if ($timeout) { # whr (ESS/PRW)
+ $imap->Timeout($timeout);
+ print "Setting imap timeout to $timeout\n";
+ }
$imap->User($user);
$imap->Password($password);
@@ -497,6 +520,13 @@
return($imap);
}
+sub plainauth() {
+ my $code = shift;
+ my $imap = shift;
+
+ my $string = sprintf("%s\x00%s\x00%s", $imap->User, defined($authusing) ? $authusing : $imap->User, $imap->Password);
+ return encode_base64("$string");
+}
sub md5auth() {
my ($imap) = @_;
@@ -537,7 +567,7 @@
my (@f_folders, @t_folders, %fs_folders);
# Make a hash of subscribed folders in source server.
-# map { $fs_folders{$_}=1 } $from->subscribed();
+map { $fs_folders{$_}=1 } $from->subscribed($prefix1);
@@ -550,7 +580,7 @@
@f_folders = sort keys (%fs_folders);
}else {
# no option, all folders
- @f_folders = sort $from->folders();
+ @f_folders = sort $from->folders($prefix1);
# consider (optional) includes and excludes
if ($include) {
@f_folders = grep /$include/,@f_folders;
@@ -996,6 +1026,8 @@
"port2=i" => \$port2,
"user1=s" => \$user1,
"user2=s" => \$user2,
+ "authusing=s" => \$authusing,
+ "authmech=s" => \$authmech,
"password1=s" => \$password1,
"password2=s" => \$password2,
"passfile1=s" => \$passfile1,
@@ -1006,6 +1038,7 @@
"folder=s" => \@folder,
"include=s" => \$include,
"exclude=s" => \$exclude,
+ "prefix1=s" => \$prefix1,
"prefix2=s" => \$prefix2,
"regextrans2=s" => \$regextrans2,
"regexmess=s" => \@regexmess,
@@ -1031,6 +1064,7 @@
"skipsize!" => \$skipsize,
"fastio1!" => \$fastio1,
"fastio2!" => \$fastio2,
+ "ssl!" => \$usessl
);
$debug and print "get options: [$opt_ret]\n";
@@ -1122,6 +1156,9 @@
--host2 <string> : "destination" imap server. Mandatory.
--port2 <int> : port to connect. Default is 143.
--user2 <string> : user to login. Mandatory.
+--authusing <string> : user to auth with (when running on behalf of another)
+--authmech <string> : auth mechanism to use (e.g. PLAIN, LOGIN, CRAM-MD5...)
+ default CRAM-MD5
--password2 <string> : password for the user2. Dangerous, use --passfile2
--passfile2 <string> : password file for the user2. Contains the password.
--noauthmd5 : don't use MD5 authentification.
@@ -1187,6 +1224,7 @@
--nofastio1 : don't use fastio with the "from" server.
--nofastio2 : don't use fastio with the "destination" server.
--timeout <int> : imap connect timeout.
+--ssl : use SSL connections.
--help : print this.
Example: to synchronise imap account "foo" on "imap.truc.org"