From 7371bedc8352bb0efa003a0537314bd3444f7879 Mon Sep 17 00:00:00 2001 From: Nick Bebout Date: Sat, 12 Mar 2011 02:44:22 +0000 Subject: [PATCH] 1.161 --- CREDITS | 1 + ChangeLog | 16 +++++- Makefile | 6 +- README | 6 +- VERSION | 2 +- freshmeat_submition | 20 ++----- freshmeat_submition2 | 8 --- imapsync | 133 ++++++++++++++++++++++++++----------------- memo | 4 +- zzz | 31 ---------- 10 files changed, 110 insertions(+), 117 deletions(-) delete mode 100644 freshmeat_submition2 delete mode 100644 zzz diff --git a/CREDITS b/CREDITS index 05e2246..36d7b33 100644 --- a/CREDITS +++ b/CREDITS @@ -11,6 +11,7 @@ See FAQ. Vincent Deffontaines Made me talk about --exclude 'fold1|fold2|f3' +Gave a patch for multiple --exclude Jim Rosenberg Had problems with dbmail 2.0.7. diff --git a/ChangeLog b/ChangeLog index cc187fc..fc71551 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,15 +1,27 @@ RCS file: RCS/imapsync,v Working file: imapsync -head: 1.159 +head: 1.161 branch: locks: strict access list: symbolic names: keyword substitution: kv -total revisions: 159; selected revisions: 159 +total revisions: 161; selected revisions: 161 description: ---------------------------- +revision 1.161 +date: 2006/03/20 00:09:41; author: gilles; state: Exp; lines: +12 -42 +Fixed default auth to CRAM-MD5 +unless not told to. +---------------------------- +revision 1.160 +date: 2006/03/19 23:54:48; author: gilles; state: Exp; lines: +82 -23 +Added SSL support. +Added options --ssl1 --ssl2 +Added PLAIN auth support +Added options --authmech1 --authmech2 +---------------------------- revision 1.159 date: 2006/03/11 13:00:52; author: gilles; state: Exp; lines: +11 -8 Added failure story dkimap diff --git a/Makefile b/Makefile index d023e18..ff3cce1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -# $Id: Makefile,v 1.8 2006/02/28 03:55:01 gilles Exp gilles $ +# $Id: Makefile,v 1.10 2006/03/20 00:35:47 gilles Exp gilles $ TARGET=imapsync @@ -19,11 +19,11 @@ all: ChangeLog README VERSION .PHONY: test testp testf .test: $(TARGET) tests.sh - sh tests.sh 1>/dev/null + nice -40 sh tests.sh 1>/dev/null touch .test testv: - sh -x tests.sh + nice -40 sh -x tests.sh test: .test diff --git a/README b/README index aec23cd..5d47472 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME imapsync - IMAP synchronization, copy or migration tool. Synchronize mailboxes between two imap servers. Good at IMAP migration. - $Revision: 1.159 $ + $Revision: 1.161 $ INSTALL imapsync works fine under any Unix OS. @@ -32,6 +32,8 @@ SYNOPSIS [--user1 ] [--passfile1 ] [--host2 server2] [--port2 ] [--user2 ] [--passfile2 ] + [--ssl1] [--ssl2] + [--authmech1 ] [--authmech2 ] [--noauthmd5] [--folder --folder ...] [--include ] [--exclude ] @@ -275,5 +277,5 @@ AUTHOR teaching free open and gratis softwares. Don't hesitate to pay him for that services. - $Id: imapsync,v 1.159 2006/03/11 13:00:52 gilles Exp $ + $Id: imapsync,v 1.161 2006/03/20 00:09:41 gilles Exp $ diff --git a/VERSION b/VERSION index f0182d7..de6f6fa 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.159 +1.161 diff --git a/freshmeat_submition b/freshmeat_submition index 607d276..6a21cfa 100644 --- a/freshmeat_submition +++ b/freshmeat_submition @@ -1,20 +1,8 @@ Project: imapsync -Version: 1.155 -Release-Focus: Major feature enhancements -Hide: N +Version: 1.159 +Release-Focus: Major bugfixes +Hide: Y Home-Page-URL: http://www.linux-france.org/prj/imapsync/ Gzipped-Tar-URL: http://www.linux-france.org/prj/imapsync/dist/ -From imapsync version 1.121 to 1.153, the following options have been added: ---buffersize ---expunge1 --expunge2 ---fastio1 --fastio2 ---minage ---useheader ---prefix1 ---foldersizes - -The documentation has been updated. -Also, imapsync is now "IMAP4 Namespace" RFC 2342 compliant. -More than 20 different IMAP server softwares have -successfully migrate or been synchronised with imapsync. +Code cleanup. diff --git a/freshmeat_submition2 b/freshmeat_submition2 deleted file mode 100644 index 0099b0b..0000000 --- a/freshmeat_submition2 +++ /dev/null @@ -1,8 +0,0 @@ -Project: imapsync -Version: 1.158 -Release-Focus: Code cleanup -Hide: Y -Home-Page-URL: http://www.linux-france.org/prj/imapsync/ -Gzipped-Tar-URL: http://www.linux-france.org/prj/imapsync/dist/ - -Code cleanup. diff --git a/imapsync b/imapsync index a41e889..1779f91 100755 --- a/imapsync +++ b/imapsync @@ -6,7 +6,7 @@ imapsync - IMAP synchronization, copy or migration tool. Synchronize mailboxes between two imap servers. Good at IMAP migration. -$Revision: 1.159 $ +$Revision: 1.161 $ =head1 INSTALL @@ -38,6 +38,8 @@ $Revision: 1.159 $ [--user1 ] [--passfile1 ] [--host2 server2] [--port2 ] [--user2 ] [--passfile2 ] + [--ssl1] [--ssl2] + [--authmech1 ] [--authmech2 ] [--noauthmd5] [--folder --folder ...] [--include ] [--exclude ] @@ -323,7 +325,7 @@ Gilles LAMIRAL earn his living writing, installing, configuring and teaching free open and gratis softwares. Don't hesitate to pay him for that services. -$Id: imapsync,v 1.159 2006/03/11 13:00:52 gilles Exp $ +$Id: imapsync,v 1.161 2006/03/20 00:09:41 gilles Exp $ =cut @@ -335,6 +337,9 @@ use Mail::IMAPClient; 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' }; @@ -366,12 +371,15 @@ my( $timeout, # whr (ESS/PRW) $timestart, $timeend, $timediff, $timesize, $timebefore, + $ssl1, $ssl2, + $authusing1, $authusing2, + $authmech1, $authmech2, ); use vars qw ($opt_G); # missing code for this will be option. -$rcs = ' $Id: imapsync,v 1.159 2006/03/11 13:00:52 gilles Exp $ '; +$rcs = ' $Id: imapsync,v 1.161 2006/03/20 00:09:41 gilles Exp $ '; $rcs =~ m/,v (\d+\.\d+)/; $VERSION = ($1) ? $1 : "UNKNOWN"; @@ -408,8 +416,8 @@ $error=0; my $banner = join("", '$RCSfile: imapsync,v $ ', - '$Revision: 1.159 $ ', - '$Date: 2006/03/11 13:00:52 $ ', + '$Revision: 1.161 $ ', + '$Date: 2006/03/20 00:09:41 $ ', "\n", "Mail::IMAPClient version used here is ", $VERSION_IMAPClient,"\n" @@ -429,10 +437,12 @@ sub missing_option { } $host1 || missing_option("--host1") ; -$port1 = (defined($port1)) ? $port1 : 143; +# $port1 = (defined($port1)) ? $port1 : 143; +$port1 ||= defined $ssl1 ? 993 : 143; $host2 || missing_option("--host2") ; -$port2 = (defined($port2)) ? $port2 : 143; +# $port2 = (defined($port2)) ? $port2 : 143; +$port2 ||= defined $ssl2 ? 993 : 143; sub connect_imap { my($host, $port, $debugimap) = @_; @@ -458,12 +468,20 @@ if ($justconnect) { $to->logout(); exit(0); } - $user1 || missing_option("--user1"); $user2 || missing_option("--user2"); -$authmd5 = (defined($authmd5)) ? $authmd5 : 1; +if(defined($authmd5) and not($authmd5)) { + $authmech1 ||= 'PLAIN'; + $authmech2 ||= 'PLAIN'; +}else{ + $authmech1 ||= 'CRAM-MD5'; + $authmech2 ||= 'CRAM-MD5'; +} + +print "will try to use $authmech1 authentication on host1\n"; +print "will try to use $authmech2 authentication on host2\n"; $syncacls = (defined($syncacls)) ? $syncacls : 0; $foldersizes = (defined($foldersizes)) ? $foldersizes : 1; @@ -497,9 +515,6 @@ $password2 = (defined($passfile2)) ? firstline ($passfile2) : $password2; my $from = (); my $to = (); -my $authmech = "CRAM-MD5"; - - $timestart = time(); $timebefore = $timestart; @@ -507,10 +522,12 @@ $fastio1 = 1; $fastio2 = 1; $debugimap and print "From connection\n"; -$from = login_imap($host1, $port1, $user1, $password1, $debugimap, $timeout, $fastio1); +$from = login_imap($host1, $port1, $user1, $password1, + $debugimap, $timeout, $fastio1, $ssl1, $authmech1); $debugimap and print "To connection\n"; -$to = login_imap($host2, $port2, $user2, $password2, $debugimap, $timeout, $fastio2); +$to = login_imap($host2, $port2, $user2, $password2, + $debugimap, $timeout, $fastio2, $ssl2, $authmech2); # No history $from->Clear(2); @@ -523,8 +540,20 @@ $debug and print "To Buffer I/O : ", $to->Buffer(), "\n"; sub login_imap { my($host, $port, $user, $password, - $debugimap, $timeout, $fastio) = @_; - my $imap = Mail::IMAPClient->new(); + $debugimap, $timeout, $fastio, $ssl, $authmech) = @_; + my ($imap); + if ($ssl) { + my $socssl = new IO::Socket::SSL("$host:$port"); + die "Error connecting to $host:$port: $@\n" unless $socssl; + $socssl->autoflush(1); + + $imap = Mail::IMAPClient->new( + Socket => $socssl, + Server => $host, + ); + } else { + $imap = Mail::IMAPClient->new(); + } $imap->Server($host); $imap->Port($port); $imap->Fast_io($fastio); @@ -532,51 +561,42 @@ sub login_imap { $imap->Uid(1); $imap->Peek(1); $imap->Debug($debugimap); - $imap->connect() + if ($ssl) { + $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"; - } + } + $timeout and $imap->Timeout($timeout); + if ($authmech eq "LOGIN") { + # Default mode for Mail::IMAPClient, so don't do anything. + } elsif ($imap->has_capability("AUTH=$authmech") + or $imap->has_capability($authmech)) { + $imap->Authmechanism($authmech); + $imap->Authcallback(\&plainauth) if $authmech eq "PLAIN"; + } else { + printf("%s: no support for AUTHENTICATE %s, using LOGIN\n", + $imap->Server, $authmech); + } $imap->User($user); $imap->Password($password); - md5auth($imap); + #md5auth($imap); $imap->login() or die "Error login : [$host] with user [$user] : $@"; return($imap); } +sub plainauth() { + my $code = shift; + my $imap = shift; -sub md5auth() { - my ($imap) = @_; - - unless ($authmd5) { - print "$authmech not wanted by you\n"; - return; - } - if ($imap->has_capability($authmech) - or $imap->has_capability("AUTH=$authmech")) { - print "Server [", $imap->Server, - "] has capability $authmech\n"; - }else{ - print "Server [", $imap->Server, - "] has NOT capability $authmech\n"; - return; - } - #print "EE", $imap->Authmechanism(), "\n"; - if ($imap->Authmechanism($authmech)) { - print "Using $authmech authentification\n"; - }else{ - $imap->Authmechanism(undef); - print "Can NOT use $authmech authentification, using plain\n"; - } - return; + my $string = sprintf("%s\x00%s\x00%s", $imap->User, + $imap->User, $imap->Password); + return encode_base64("$string"); } - print "From software : ", ($from->Report())[0]; print "To software : ", ($to->Report())[0]; @@ -1174,6 +1194,10 @@ sub get_options "skipsize!" => \$skipsize, "fastio1!" => \$fastio1, "fastio2!" => \$fastio2, + "ssl1!" => \$ssl1, + "ssl2!" => \$ssl2, + "authmech1=s" => \$authmech1, + "authmech2=s" => \$authmech2, ); $debug and print "get options: [$opt_ret]\n"; @@ -1258,17 +1282,22 @@ usage: $0 [options] Several options are mandatory. --host1 : "from" imap server. Mandatory. ---port1 : port to connect. Default is 143. ---user1 : user to login. Mandatory. +--port1 : port to connect on host1. Default is 143. +--user1 : user to login on host1. Mandatory. --password1 : password for the user1. Dangerous, use --passfile1 --passfile1 : password file for the user1. Contains the password. --host2 : "destination" imap server. Mandatory. ---port2 : port to connect. Default is 143. ---user2 : user to login. Mandatory. +--port2 : port to connect on host2. Default is 143. +--user2 : user to login on host2. Mandatory. --password2 : password for the user2. Dangerous, use --passfile2 --passfile2 : password file for the user2. Contains the password. --noauthmd5 : don't use MD5 authentification. --authmd5 : use MD5 authentification. +--authmech1 : auth mechanism to use with host1: + PLAIN, LOGIN, CRAM-MD5 etc. +--authmech2 : auth mechanism to use with host2. See --authmech1 +--ssl1 : use an SSL connection on host1. +--ssl2 : use an SSL connection on host2. --folder : sync only this folder. --folder : and this one. --folder : and this one, etc. diff --git a/memo b/memo index a876ae4..a02154b 100644 --- a/memo +++ b/memo @@ -37,14 +37,14 @@ niouzes_compil fm_announce() { software_version -NEWS_FILE_FM="/home/gilles/public_html/imapsync/freshmeat_submition2" +NEWS_FILE_FM="/home/gilles/public_html/imapsync/freshmeat_submition" if ! newer VERSION $NEWS_FILE_FM; then echo "$VERSION already announced" else cat > $NEWS_FILE_FM << EOF Project: imapsync Version: $VERSION -Release-Focus: Major bugfixe +Release-Focus: Major bugfixes Hide: Y Home-Page-URL: http://www.linux-france.org/prj/imapsync/ Gzipped-Tar-URL: http://www.linux-france.org/prj/imapsync/dist/ diff --git a/zzz b/zzz deleted file mode 100644 index 62cf6b3..0000000 --- a/zzz +++ /dev/null @@ -1,31 +0,0 @@ -$RCSfile: imapsync,v $ $Revision: 1.158 $ $Date: 2006/03/02 06:28:30 $ -Mail::IMAPClient version used here is 2.2.9 -From imap server [loul] port [143] user [tata] -To imap server [plume] port [143] user [tata] -Server [loul] has NOT capability CRAM-MD5 -Server [plume] has NOT capability CRAM-MD5 -From software : 2 CAPABILITY -To software : 2 CAPABILITY -From capability : QUOTA X-NETSCAPE NAMESPACE X-NON-HIERARCHICAL-RENAME ACL UNSELECT LITERAL+ NO_ATOMIC_RENAME UIDPLUS IMAP4 IMAP4REV1 -To capability : ACL AUTH=LOGIN NAMESPACE IMAP4REV1 IMAP4 -From separator and prefix : [.][INBOX.] -To separator and prefix : [/][] -++++ Calculating sizes ++++ -From Folder [INBOX] Size: 5703203 Messages: 1432 -Total size: 5703203 -Total messages: 1432 -Time : 0 s -++++ Calculating sizes ++++ -To Folder [INBOX] Size: 17108791 Messages: 4294 -Total size: 17108791 -Total messages: 4294 -Time : 0 s -From folders : [INBOX] -To folders : [INBOX] -From subscribed folders : [INBOX.yop.yap] -From Folder [INBOX] -To Folder [INBOX] -++++ From [INBOX] Parse 1 ++++ -++++ To [INBOX] Parse 1 ++++ -++++ Verifying [INBOX] -> [INBOX] ++++ -Time : 11 s