This commit is contained in:
Nick Bebout 2011-03-12 02:44:20 +00:00
parent f2bb3aabe8
commit 02b830ba86
5 changed files with 71 additions and 20 deletions

View file

@ -1,5 +1,10 @@
#!/bin/cat #!/bin/cat
Nicolai Rasmussen
Suggested the --minage option and asked
a friend of him to code it.
I made it compatible with --maxage too.
Marcos Sungaila Marcos Sungaila
Reported the "do not consider namespace" bug Reported the "do not consider namespace" bug
once again. And I fixed it. I think. once again. And I fixed it. I think.

View file

@ -1,17 +1,20 @@
RCS file: RCS/imapsync,v RCS file: RCS/imapsync,v
Working file: imapsync Working file: imapsync
head: 1.144 head: 1.145
branch: branch:
locks: strict locks: strict
gilles: 1.144
access list: access list:
symbolic names: symbolic names:
keyword substitution: kv keyword substitution: kv
total revisions: 144; selected revisions: 144 total revisions: 145; selected revisions: 145
description: description:
---------------------------- ----------------------------
revision 1.144 locked by: gilles; revision 1.145
date: 2005/12/04 01:58:54; author: gilles; state: Exp; lines: +54 -12
Added --minage option
----------------------------
revision 1.144
date: 2005/11/28 00:32:05; author: gilles; state: Exp; lines: +60 -17 date: 2005/11/28 00:32:05; author: gilles; state: Exp; lines: +60 -17
Added RFC compliance about NAMESPACE prefixes. Added RFC compliance about NAMESPACE prefixes.
Added --prefix1 option. Added --prefix1 option.

7
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.144 $ $Revision: 1.145 $
INSTALL INSTALL
imapsync works fine under any Unix OS. imapsync works fine under any Unix OS.
@ -46,6 +46,7 @@ SYNOPSIS
[--regexmess <regex>] [--regexmess <regex>] [--regexmess <regex>] [--regexmess <regex>]
[--maxsize <int>] [--maxsize <int>]
[--maxage <int>] [--maxage <int>]
[--minage <int>]
[--skipheader <regex>] [--skipheader <regex>]
[--useheader <string>] [--useheader <string>] [--useheader <string>] [--useheader <string>]
[--skipsize] [--skipsize]
@ -215,7 +216,7 @@ IMAP SERVERS
HUGE MIGRATION HUGE MIGRATION
Have a special attention on options --subscribed --subscribe --delete Have a special attention on options --subscribed --subscribe --delete
--expunge --expunge1 --expunge2 --maxage --maxsize --useheader --expunge --expunge1 --expunge2 --maxage --minage --maxsize --useheader
If you have many mailboxes to migrate think about a little shell If you have many mailboxes to migrate think about a little shell
program. Write a file called file.csv (for example) containing users and program. Write a file called file.csv (for example) containing users and
@ -262,5 +263,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.144 2005/11/28 00:32:05 gilles Exp gilles $ $Id: imapsync,v 1.145 2005/12/04 01:58:54 gilles Exp $

View file

@ -1 +1 @@
1.144 1.145

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.144 $ $Revision: 1.145 $
=head1 INSTALL =head1 INSTALL
@ -52,6 +52,7 @@ $Revision: 1.144 $
[--regexmess <regex>] [--regexmess <regex>] [--regexmess <regex>] [--regexmess <regex>]
[--maxsize <int>] [--maxsize <int>]
[--maxage <int>] [--maxage <int>]
[--minage <int>]
[--skipheader <regex>] [--skipheader <regex>]
[--useheader <string>] [--useheader <string>] [--useheader <string>] [--useheader <string>]
[--skipsize] [--skipsize]
@ -250,6 +251,7 @@ Have a special attention on options
--expunge1 --expunge1
--expunge2 --expunge2
--maxage --maxage
--minage
--maxsize --maxsize
--useheader --useheader
@ -306,7 +308,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.144 2005/11/28 00:32:05 gilles Exp gilles $ $Id: imapsync,v 1.145 2005/12/04 01:58:54 gilles Exp $
=cut =cut
@ -332,7 +334,7 @@ my(
$sep1, $sep2, $sep1, $sep2,
$syncinternaldates, $syncacls, $syncinternaldates, $syncacls,
$fastio1, $fastio2, $fastio1, $fastio2,
$maxsize, $maxage, $maxsize, $maxage, $minage,
$skipheader, @useheader, $skipheader, @useheader,
$skipsize, $foldersizes, $buffersize, $skipsize, $foldersizes, $buffersize,
$delete, $expunge, $expunge1, $expunge2, $dry, $delete, $expunge, $expunge1, $expunge2, $dry,
@ -353,7 +355,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.144 2005/11/28 00:32:05 gilles Exp gilles $ '; $rcs = ' $Id: imapsync,v 1.145 2005/12/04 01:58:54 gilles Exp $ ';
$rcs =~ m/,v (\d+\.\d+)/; $rcs =~ m/,v (\d+\.\d+)/;
$VERSION = ($1) ? $1 : "UNKNOWN"; $VERSION = ($1) ? $1 : "UNKNOWN";
@ -390,8 +392,8 @@ $error=0;
my $banner = join("", my $banner = join("",
'$RCSfile: imapsync,v $ ', '$RCSfile: imapsync,v $ ',
'$Revision: 1.144 $ ', '$Revision: 1.145 $ ',
'$Date: 2005/11/28 00:32:05 $ ', '$Date: 2005/12/04 01:58:54 $ ',
"\n", "\n",
"Mail::IMAPClient version used here is ", "Mail::IMAPClient version used here is ",
$VERSION_IMAPClient,"\n" $VERSION_IMAPClient,"\n"
@ -657,12 +659,10 @@ sub foldersizes {
$error++; $error++;
next; next;
} }
if ($maxage) { if (defined($maxage) or defined($minage)) {
# The pb is fetch_hash() can only be applied on ALL messages # The pb is fetch_hash() can only be applied on ALL messages
my @msgs = select_msgs($imap);
my @msgs = $imap->since(time - 86400 * $maxage);
$smess = scalar(@msgs); $smess = scalar(@msgs);
#print "maxage smess $smess " ;
foreach my $m (@msgs) { foreach my $m (@msgs) {
my $s = $imap->size($m) my $s = $imap->size($m)
or warn "Could not find size of message $m: $@\n"; or warn "Could not find size of message $m: $@\n";
@ -817,11 +817,16 @@ FOLDER: foreach my $f_fold (@f_folders) {
next FOLDER if ($justfolders); next FOLDER if ($justfolders);
my @f_msgs = $maxage ? $from->since(time - 86400 * $maxage) : $from->search("ALL");
my @f_msgs = select_msgs($from);
$debug and print "LIST FROM : @f_msgs\n"; $debug and print "LIST FROM : @f_msgs\n";
# internal dates on "TO" are after the ones on "FROM" # internal dates on "TO" are after the ones on "FROM"
# normally... # normally...
my @t_msgs = $maxage ? $to->since(time - 86400 * $maxage) : $to->search("ALL"); my @t_msgs = select_msgs($to);
$debug and print "LIST TO : @t_msgs\n"; $debug and print "LIST TO : @t_msgs\n";
my %f_hash = (); my %f_hash = ();
@ -1017,6 +1022,35 @@ stats();
exit(1) if($error); exit(1) if($error);
sub select_msgs {
my ($imap) = @_;
my (@msgs,@max,@min,@union,@inter);
unless (defined($maxage) or defined($minage)) {
@msgs = $imap->search("ALL");
return(@msgs);
}
if (defined($maxage)) {
@max = $imap->since(time - 86400 * $maxage);
}
if (defined($minage)) {
@min = $imap->before(time - 86400 * $minage);
}
SWITCH: {
unless(defined($minage)) {@msgs = @max; last SWITCH};
unless(defined($maxage)) {@msgs = @min; last SWITCH};
my (%union, %inter);
foreach my $m (@min, @max) {$union{$m}++ && $inter{$m}++}
# normal case
if ($minage <= $maxage) {@msgs = @inter; last SWITCH};
# just exclude messages between
if ($minage > $maxage) {@msgs = @union; last SWITCH};
}
return(@msgs);
}
sub stats { sub stats {
print "++++ Statistics ++++\n"; print "++++ Statistics ++++\n";
print "Time : $timediff sec\n"; print "Time : $timediff sec\n";
@ -1063,6 +1097,7 @@ sub get_options
"syncacls!" => \$syncacls, "syncacls!" => \$syncacls,
"maxsize=i" => \$maxsize, "maxsize=i" => \$maxsize,
"maxage=i" => \$maxage, "maxage=i" => \$maxage,
"minage=i" => \$minage,
"buffersize=i" => \$buffersize, "buffersize=i" => \$buffersize,
"foldersizes!" => \$foldersizes, "foldersizes!" => \$foldersizes,
"dry!" => \$dry, "dry!" => \$dry,
@ -1221,6 +1256,13 @@ Several options are mandatory.
--maxsize <int> : skip messages larger than <int> bytes --maxsize <int> : skip messages larger than <int> bytes
--maxage <int> : skip messages older than <int> days. --maxage <int> : skip messages older than <int> days.
final stats (skipped) don't count older messages final stats (skipped) don't count older messages
--minage <int> : skip messages newer than <int> days.
final stats (skipped) don't count newer messages
You can do (+ are the messages selected):
------maxage+++++++++++++++++++|now
+++++++++++++++++++minage------|now
------maxage+++++++minage------|now intersection
++++++minage-------maxage++++++|now union
--skipheader <regex> : Don't take into account header keyword --skipheader <regex> : Don't take into account header keyword
matching <string> ex: --skipheader 'X.*' matching <string> ex: --skipheader 'X.*'
--useheader <string> : Use this header to compare messages on both sides. --useheader <string> : Use this header to compare messages on both sides.