From bf62e181cad2c9c4dc53a35b5192e44e35775e05 Mon Sep 17 00:00:00 2001 From: Nick Bebout Date: Sat, 12 Mar 2011 02:44:40 +0000 Subject: [PATCH] 1.261 --- ChangeLog | 14 ++++++++--- FAQ | 25 ++++++++++++++++--- README | 4 +-- VERSION | 2 +- imapsync | 73 ++++++++++++++++++++++++------------------------------- tests.sh | 44 ++++++++++++++++++++++++++++++++- 6 files changed, 109 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 469020c..81ab0ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,17 +1,23 @@ RCS file: RCS/imapsync,v Working file: imapsync -head: 1.260 +head: 1.261 branch: locks: strict - gilles: 1.260 + gilles: 1.261 access list: symbolic names: keyword substitution: kv -total revisions: 260; selected revisions: 260 +total revisions: 261; selected revisions: 261 description: ---------------------------- -revision 1.260 locked by: gilles; +revision 1.261 locked by: gilles; +date: 2008/08/16 15:56:00; author: gilles; state: Exp; lines: +32 -41 +- Fixed bug about ssl and justconnect option +- Cleaned connect code. +- Started gmail support. +---------------------------- +revision 1.260 date: 2008/08/13 03:14:14; author: gilles; state: Exp; lines: +54 -13 - Added option --idatefromheader : sets the internal dates on host2 same as the "Date:" headers. diff --git a/FAQ b/FAQ index f90274e..2ecb2c2 100644 --- a/FAQ +++ b/FAQ @@ -214,9 +214,9 @@ c) or use stunnel on inetd imaps stream tcp nowait cyrus /usr/sbin/stunnel -s cyrus -p /etc/ssl/certs/imapd.pem -r localhost:imap2 ======================================================================= -Q: I'm trying to use imapsync for gmail, but it requires ssl, or at least -claims to. Imapsync appears to require io-socket-ssl, which doesn't seem -to be available on win32. Are there any other options? +Q: I'm trying to use imapsync on win32 for gmail, but it requires ssl, +or at least claims to. Imapsync appears to require io-socket-ssl, +which doesn't seem to be available on win32. Are there any other options? R: (Q and R come as is from Bryce Walter) I think I'm having success using cygwin perl instead of @@ -512,7 +512,6 @@ imapsync --syncinternaldates \ --user1 my_email@oldhost.com \ --password1 password \ --host2 imap.gmail.com --port2 993 --ssl2 \ - --authmech2 LOGIN \ --user2 my_email@gmail.com \ --password2 password \ --prefix2 '[Gmail]/' \ @@ -521,6 +520,24 @@ imapsync --syncinternaldates \ The same goes for the "All Mail" archive psuedo-folder. +======================================================================= +Q. Synchronysing from Gmail to XXX + +R. Gmail needs ssl. + +./imapsync \ + --host1 imap.gmail.com --ssl1 \ + --user1 gilles.lamiral@gmail.com \ + --passfile1 /var/tmp/secret.gilles_gmail \ + --host2 localhost + --user2 tata@est.belle \ + --passfile2 /var/tmp/secret.tata \ + --useheader 'Message-Id' --skipsize + +If your destination imap server doesn't like "[Gmail]" name, just add +option: + --regextrans2 's/\[Gmail\]/Gmail/' + ======================================================================= Q. I'm migrating from WU to Cyrus, and the mail folders are diff --git a/README b/README index c770f9b..a581e3c 100644 --- a/README +++ b/README @@ -3,7 +3,7 @@ NAME Synchronise mailboxes between two imap servers. Good at IMAP migration. More than 32 different IMAP server softwares supported with success. - $Revision: 1.260 $ + $Revision: 1.261 $ INSTALL imapsync works fine under any Unix OS with perl. @@ -364,5 +364,5 @@ SIMILAR SOFTWARES Feedback (good or bad) will be always welcome. - $Id: imapsync,v 1.260 2008/08/13 03:14:14 gilles Exp gilles $ + $Id: imapsync,v 1.261 2008/08/16 15:56:00 gilles Exp gilles $ diff --git a/VERSION b/VERSION index 31d9c58..56b21f3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.260 +1.261 diff --git a/imapsync b/imapsync index 27e4a92..193800a 100755 --- a/imapsync +++ b/imapsync @@ -9,7 +9,7 @@ tool. Synchronise mailboxes between two imap servers. Good at IMAP migration. More than 32 different IMAP server softwares supported with success. -$Revision: 1.260 $ +$Revision: 1.261 $ =head1 INSTALL @@ -422,7 +422,7 @@ Entries for imapsync: Feedback (good or bad) will be always welcome. -$Id: imapsync,v 1.260 2008/08/13 03:14:14 gilles Exp gilles $ +$Id: imapsync,v 1.261 2008/08/16 15:56:00 gilles Exp gilles $ @@ -489,7 +489,7 @@ my( use vars qw ($opt_G); # missing code for this will be option. -$rcs = '$Id: imapsync,v 1.260 2008/08/13 03:14:14 gilles Exp gilles $ '; +$rcs = '$Id: imapsync,v 1.261 2008/08/16 15:56:00 gilles Exp gilles $ '; $rcs =~ m/,v (\d+\.\d+)/; $VERSION = ($1) ? $1 : "UNKNOWN"; @@ -523,8 +523,8 @@ $error=0; my $banner = join("", '$RCSfile: imapsync,v $ ', - '$Revision: 1.260 $ ', - '$Date: 2008/08/13 03:14:14 $ ', + '$Revision: 1.261 $ ', + '$Date: 2008/08/16 15:56:00 $ ', "\n",localhost_info(), " and the module Mail::IMAPClient version used here is ", $VERSION_IMAPClient,"\n", @@ -556,11 +556,12 @@ $host2 || missing_option("--host2") ; $port2 ||= defined $ssl2 ? 993 : 143; sub connect_imap { - my($host, $port, $debugimap) = @_; + my($host, $port, $debugimap, $ssl) = @_; my $imap = Mail::IMAPClient->new(); $imap->Server($host); $imap->Port($port); $imap->Debug($debugimap); + $imap->Ssl($ssl); $imap->connect() or die "Can not open imap connection on [$host] : $@\n"; } @@ -583,10 +584,10 @@ if ($justconnect) { my $from = (); my $to = (); - $from = connect_imap($host1, $port1); + $from = connect_imap($host1, $port1, $debugimap, $ssl1); print "From software : ", server_banner($from); print "From capability : ", join(" ", $from->capability()), "\n"; - $to = connect_imap($host2, $port2); + $to = connect_imap($host2, $port2, $debugimap, $ssl2); print "To software : ", server_banner($to); print "To capability : ", join(" ", $to->capability()), "\n"; $from->logout(); @@ -711,20 +712,10 @@ sub login_imap { $debugimap, $timeout, $fastio, $ssl, $authmech, $authuser) = @_; my ($imap); - if ($ssl) { - require IO::Socket::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 = Mail::IMAPClient->new(); + + $imap->Ssl($ssl); $imap->Clear(20); $imap->Server($host); $imap->Port($port); @@ -735,13 +726,9 @@ sub login_imap { $imap->Debug($debugimap); $timeout and $imap->Timeout($timeout); - if ($ssl) { - $imap->State(Mail::IMAPClient::Connected); - } - else { - $imap->connect() + $imap->connect() or die "Can not open imap connection on [$host] with user [$user] : $@\n"; - } + print "Banner : ", server_banner($imap); if ($imap->has_capability("AUTH=$authmech") @@ -1100,7 +1087,7 @@ sub foldersizes { warn "$side Folder $folder : Could not select ", $imap->LastError, "\n"; - $error++; + #$error++; next; } if (defined($maxage) or defined($minage)) { @@ -1259,7 +1246,7 @@ FOLDER: foreach my $f_fold (@f_folders) { warn "From Folder $f_fold : Could not select ", $from->LastError, "\n"; - $error++; + #$error++; next FOLDER; } @@ -1285,7 +1272,7 @@ FOLDER: foreach my $f_fold (@f_folders) { warn "To Folder $t_fold : Could not select ", $to->LastError, "\n"; - $error++; + #$error++; next FOLDER; } @@ -2462,6 +2449,7 @@ use constant NonFolderArg => 1; # Value to pass to Massage to until ($code) { $output = $self->_read_line or return undef; + foreach my $o (@$output) { $self->_record($count,$o); # $o is a ref ($code) = $o->[DATA] =~ /^\+(.*)$/ ; @@ -2469,11 +2457,12 @@ use constant NonFolderArg => 1; # Value to pass to Massage to $self->State(Unconnected); return undef ; } + if ($o->[DATA]=~ /^\d+\s+(NO|BAD)/i) { + return undef ; + } } } - return undef if $code =~ /^BAD|^NO/ ; - if ('CRAM-MD5' eq $scheme && ! $response) { if ($Mail::IMAPClient::_CRAM_MD5_ERR) { $self->LastError($Mail::IMAPClient::_CRAM_MD5_ERR); @@ -2559,6 +2548,12 @@ use constant NonFolderArg => 1; # Value to pass to Massage to return $string; }; +*Mail::IMAPClient::Ssl = sub { + my $self = shift; + + if (@_) { $self->{SSL} = shift } + return $self->{SSL}; +}; *Mail::IMAPClient::connect = sub { @@ -2569,9 +2564,10 @@ use constant NonFolderArg => 1; # Value to pass to Massage to and $IO::Socket::INET::VERSION eq '1.25' and !$self->Port; %$self = (%$self, @_); - my $sock = IO::Socket::INET->new; - my $dp = 'imap(143)'; - #print "i01\n"; + + my $sock = ($self->Ssl ? IO::Socket::SSL->new : IO::Socket::INET->new); + my $dp = ($self->Ssl ? 'imaps(993)' : 'imap(143)'); + my $ret = $sock->configure({ PeerAddr => $self->Server , PeerPort => $self->Port||$dp , @@ -2579,7 +2575,6 @@ use constant NonFolderArg => 1; # Value to pass to Massage to Timeout => $self->Timeout||0 , Debug => $self->Debug , }); - #print "i02\n"; unless ( defined($ret) ) { $self->LastError( "$@\n"); $@ = "$@"; @@ -2587,19 +2582,15 @@ use constant NonFolderArg => 1; # Value to pass to Massage to unless defined wantarray; return undef; } - #print "i03\n"; $self->Socket($sock); $self->State(Connected); - #print "i04\n"; $sock->autoflush(1) ; my ($code, $output); $output = ""; - #print "i05\n"; until ( $code ) { $output = $self->_read_line or return undef; - #print "i06\n"; for my $o (@$output) { $self->_debug("Connect: Received this from readline: " . join("/",@$o) . "\n"); diff --git a/tests.sh b/tests.sh index 96326c6..ad86b6e 100644 --- a/tests.sh +++ b/tests.sh @@ -1,6 +1,6 @@ #!/bin/sh -# $Id: tests.sh,v 1.77 2008/08/13 23:33:18 gilles Exp gilles $ +# $Id: tests.sh,v 1.78 2008/08/16 15:54:40 gilles Exp gilles $ #### Shell pragmas @@ -648,6 +648,20 @@ ll_regex_flag() } +ssl_justconnect() { + if test X`hostname` = X"plume"; then + echo3 Here is plume + $CMD_PERL ./imapsync \ + --host1 localhost \ + --host2 localhost \ + --ssl1 --ssl2 \ + --justconnect + else + : + fi + +} + ll_ssl() { if test X`hostname` = X"plume"; then echo3 Here is plume @@ -756,6 +770,8 @@ ll_bigmail() { } + + msw() { sendtestmessage toto@est.belle scp imapsync Admin@192.168.68.77:'C:/msys/1.0/home/Admin/imapsync/imapsync' @@ -764,6 +780,30 @@ msw() { + +gmail() { + if test X`hostname` = X"plume"; then + echo3 Here is plume + $CMD_PERL ./imapsync \ + --host1 imap.gmail.com \ + --ssl1 \ + --user1 gilles.lamiral@gmail.com \ + --passfile1 /var/tmp/secret.gilles_gmail \ + --host2 localhost \ + --ssl2 \ + --user2 tata@est.belle \ + --passfile2 /var/tmp/secret.tata \ + --useheader 'Message-Id' --skipsize \ + --regextrans2 's/\[Gmail\]/Gmail/' \ + #--dry # --debug --debugimap # --authmech1 LOGIN + + else + : + fi + +} + + ########################## # specific tests ########################## @@ -1033,6 +1073,8 @@ test $# -eq 0 && run_tests \ ll_delete2 \ ll_folderrec \ ll_bigmail \ + gmail \ + ssl_justconnect \ # msw