This commit is contained in:
Nick Bebout 2011-03-12 02:44:22 +00:00
parent 475d7b9015
commit cdefaa6ccf
7 changed files with 70 additions and 49 deletions

View file

@ -6,7 +6,7 @@ imapsync - IMAP synchronization, copy or migration
tool. Synchronize mailboxes between two imap servers. Good
at IMAP migration.
$Revision: 1.156 $
$Revision: 1.158 $
=head1 INSTALL
@ -322,7 +322,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.156 2006/03/02 03:14:12 gilles Exp gilles $
$Id: imapsync,v 1.158 2006/03/02 06:28:30 gilles Exp $
=cut
@ -342,7 +342,7 @@ my(
$rcs, $debug, $debugimap, $error,
$host1, $host2, $port1, $port2,
$user1, $user2, $password1, $password2, $passfile1, $passfile2,
@folder, $include, $exclude,
@folder, @include, @exclude,
$prefix1, $prefix2,
@regextrans2, @regexmess,
$sep1, $sep2,
@ -370,7 +370,7 @@ my(
use vars qw ($opt_G); # missing code for this will be option.
$rcs = ' $Id: imapsync,v 1.156 2006/03/02 03:14:12 gilles Exp gilles $ ';
$rcs = ' $Id: imapsync,v 1.158 2006/03/02 06:28:30 gilles Exp $ ';
$rcs =~ m/,v (\d+\.\d+)/;
$VERSION = ($1) ? $1 : "UNKNOWN";
@ -407,8 +407,8 @@ $error=0;
my $banner = join("",
'$RCSfile: imapsync,v $ ',
'$Revision: 1.156 $ ',
'$Date: 2006/03/02 03:14:12 $ ',
'$Revision: 1.158 $ ',
'$Date: 2006/03/02 06:28:30 $ ',
"\n",
"Mail::IMAPClient version used here is ",
$VERSION_IMAPClient,"\n"
@ -603,11 +603,11 @@ if (scalar(@folder)) {
# no option, all folders
@f_folders = sort $from->folders();
# consider (optional) includes and excludes
if ($include) {
foreach my $include (@include) {
@f_folders = grep /$include/,@f_folders;
print "Only including folders matching pattern '$include'\n";
}
if ($exclude) {
foreach my $exclude (@exclude) {
@f_folders = grep !/$exclude/,@f_folders;
print "Excluding folders matching pattern '$exclude'\n";
}
@ -776,11 +776,9 @@ sub separator_invert {
return($t_fold);
}
FOLDER: foreach my $f_fold (@f_folders) {
my $t_fold;
print "From Folder [$f_fold]\n";
my $x_fold = $f_fold;
sub to_folder_name {
my ($t_fold);
my ($x_fold) = @_;
# first we remove the prefix
$x_fold =~ s/^$f_prefix//;
$debug and print "removed source prefix : [$x_fold]\n";
@ -795,7 +793,35 @@ FOLDER: foreach my $f_fold (@f_folders) {
$debug and print "eval \$t_fold =~ $regextrans2\n";
eval("\$t_fold =~ $regextrans2");
}
return($t_fold);
}
sub acls_sync {
my($f_fold, $t_fold) = @_;
if ($syncacls) {
my $f_hash = $from->getacl($f_fold)
or warn "Could not getacl for $f_fold: $@\n";
my $t_hash = $to->getacl($t_fold)
or warn "Could not getacl for $t_fold: $@\n";
my %users = map({ ($_, 1) } (keys(%$f_hash), keys(%$t_hash)));
foreach my $user (sort(keys(%users))) {
my $acl = $f_hash->{$user} || "none";
print "acl $user : [$acl]\n";
next if ($f_hash->{$user} && $t_hash->{$user} &&
$f_hash->{$user} eq $t_hash->{$user});
unless ($dry) {
print "setting acl $t_fold $user $acl\n";
$to->setacl($t_fold, $user, $acl)
or warn "Could not set acl: $@\n";
}
}
}
}
FOLDER: foreach my $f_fold (@f_folders) {
my $t_fold;
print "From Folder [$f_fold]\n";
$t_fold = to_folder_name($f_fold);
print "To Folder [$t_fold]\n";
unless ($from->select($f_fold)) {
@ -821,25 +847,8 @@ FOLDER: foreach my $f_fold (@f_folders) {
}
}
if ($syncacls) {
my $f_hash = $from->getacl($f_fold)
or warn "Could not getacl for $f_fold: $@\n";
my $t_hash = $to->getacl($t_fold)
or warn "Could not getacl for $t_fold: $@\n";
my %users = map({ ($_, 1) } (keys(%$f_hash), keys(%$t_hash)));
foreach my $user (sort(keys(%users))) {
my $acl = $f_hash->{$user} || "none";
print "acl $user : [$acl]\n";
next if ($f_hash->{$user} && $t_hash->{$user} &&
$f_hash->{$user} eq $t_hash->{$user});
unless ($dry) {
print "setting acl $t_fold $user $acl\n";
$to->setacl($t_fold, $user, $acl)
or warn "Could not set acl: $@\n";
}
}
}
acls_sync($f_fold, $t_fold);
unless ($to->select($t_fold)) {
warn
"To Folder $t_fold : Could not select ",
@ -1130,8 +1139,8 @@ sub get_options
"sep1=s" => \$sep1,
"sep2=s" => \$sep2,
"folder=s" => \@folder,
"include=s" => \$include,
"exclude=s" => \$exclude,
"include=s" => \@include,
"exclude=s" => \@exclude,
"prefix1=s" => \$prefix1,
"prefix2=s" => \$prefix2,
"regextrans2=s" => \@regextrans2,
@ -1262,11 +1271,15 @@ Several options are mandatory.
--folder <string> : and this one, etc.
--include <regex> : only sync folders matching this regular expression
(only effective if neither --folder nor --subscribed
is specified).
is specified).
--include <regex> : and this one, etc.
in case both --include --exclude options are
use, include is done before.
--exclude <regex> : skips folders matching this regular expression
(only effective if neither --folder nor --subscribed
is specified). Several folders to avoid:
--exclude 'fold1|fold2|f3' skips fold1, fold2 and f3.
--exclude <regex> : and this one, etc.
--prefix1 <string> : remove prefix to all destination folders
(usually INBOX. for cyrus imap servers)
use --prefix1 if your source imap server does not