2005-12-22 18:06:25 +00:00
|
|
|
#! /usr/bin/perl -w
|
2006-02-11 19:48:44 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2006 Oswald Buddenhagen <ossi@users.sf.net>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2011-04-10 17:34:36 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-02-11 19:48:44 +00:00
|
|
|
#
|
2005-12-22 18:06:25 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use File::Path;
|
|
|
|
|
|
|
|
-d "tmp" or mkdir "tmp";
|
|
|
|
chdir "tmp" or die "Cannot enter temp direcory.\n";
|
|
|
|
|
|
|
|
sub show($$@);
|
|
|
|
sub test($$);
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
2005-12-26 16:01:42 +00:00
|
|
|
# generic syncing tests
|
2005-12-22 18:06:25 +00:00
|
|
|
my @x01 = (
|
|
|
|
[ 8,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "F", 7, 7, "FT", 9, 0, "" ],
|
|
|
|
[ 8,
|
|
|
|
1, 1, "", 2, 2, "F", 3, 3, "F", 4, 4, "", 5, 5, "", 7, 7, "", 8, 8, "", 10, 0, "" ],
|
|
|
|
[ 8, 0, 0,
|
|
|
|
1, 1, "", 2, 2, "", 3, 3, "", 4, 4, "", 5, 5, "", 6, 6, "", 7, 7, "", 8, 8, "" ],
|
|
|
|
);
|
|
|
|
|
|
|
|
#show("01", "01", "", "", "");
|
|
|
|
my @X01 = (
|
2005-12-23 10:22:47 +00:00
|
|
|
[ "", "", "" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
[ 10,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "FT", 7, 7, "FT", 9, 9, "", 10, 10, "" ],
|
|
|
|
[ 10,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 7, 7, "FT", 8, 8, "T", 9, 10, "", 10, 9, "" ],
|
|
|
|
[ 9, 0, 9,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 0, "", 7, 7, "FT", 0, 8, "", 10, 9, "", 9, 10, "" ],
|
|
|
|
);
|
|
|
|
test(\@x01, \@X01);
|
|
|
|
|
|
|
|
#show("01", "02", "", "", "Expunge Both\n");
|
|
|
|
my @X02 = (
|
2005-12-23 10:22:47 +00:00
|
|
|
[ "", "", "Expunge Both\n" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
[ 10,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 9, 9, "", 10, 10, "" ],
|
|
|
|
[ 10,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 9, 10, "", 10, 9, "" ],
|
|
|
|
[ 9, 0, 9,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 10, 9, "", 9, 10, "" ],
|
|
|
|
);
|
|
|
|
test(\@x01, \@X02);
|
|
|
|
|
|
|
|
#show("01", "03", "", "", "Expunge Slave\n");
|
|
|
|
my @X03 = (
|
2005-12-23 10:22:47 +00:00
|
|
|
[ "", "", "Expunge Slave\n" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
[ 10,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "FT", 7, 7, "FT", 9, 9, "", 10, 10, "" ],
|
|
|
|
[ 10,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 9, 10, "", 10, 9, "" ],
|
|
|
|
[ 9, 0, 9,
|
2006-02-02 10:04:05 +00:00
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 0, "T", 6, 0, "", 7, 0, "T", 10, 9, "", 9, 10, "" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
);
|
|
|
|
test(\@x01, \@X03);
|
|
|
|
|
|
|
|
#show("01", "04", "", "", "Sync Pull\n");
|
|
|
|
my @X04 = (
|
2005-12-23 10:22:47 +00:00
|
|
|
[ "", "", "Sync Pull\n" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
[ 9,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "F", 7, 7, "FT", 9, 9, "" ],
|
|
|
|
[ 9,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 7, 7, "FT", 8, 8, "T", 9, 9, "", 10, 0, "" ],
|
|
|
|
[ 9, 0, 0,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "", 7, 7, "FT", 0, 8, "", 9, 9, "" ],
|
|
|
|
);
|
|
|
|
test(\@x01, \@X04);
|
|
|
|
|
|
|
|
#show("01", "05", "", "", "Sync Flags\n");
|
|
|
|
my @X05 = (
|
2005-12-23 10:22:47 +00:00
|
|
|
[ "", "", "Sync Flags\n" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
[ 8,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "F", 7, 7, "FT", 9, 0, "" ],
|
|
|
|
[ 8,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 7, 7, "FT", 8, 8, "", 10, 0, "" ],
|
|
|
|
[ 8, 0, 0,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "", 7, 7, "FT", 8, 8, "" ],
|
|
|
|
);
|
|
|
|
test(\@x01, \@X05);
|
|
|
|
|
|
|
|
#show("01", "06", "", "", "Sync Delete\n");
|
|
|
|
my @X06 = (
|
2005-12-23 10:22:47 +00:00
|
|
|
[ "", "", "Sync Delete\n" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
[ 8,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "FT", 7, 7, "FT", 9, 0, "" ],
|
|
|
|
[ 8,
|
|
|
|
1, 1, "", 2, 2, "F", 3, 3, "F", 4, 4, "", 5, 5, "", 7, 7, "", 8, 8, "T", 10, 0, "" ],
|
|
|
|
[ 8, 0, 0,
|
|
|
|
1, 1, "", 2, 2, "", 3, 3, "", 4, 4, "", 5, 5, "", 6, 0, "", 7, 7, "", 0, 8, "" ],
|
|
|
|
);
|
|
|
|
test(\@x01, \@X06);
|
|
|
|
|
|
|
|
#show("01", "07", "", "", "Sync New\n");
|
|
|
|
my @X07 = (
|
2005-12-23 10:22:47 +00:00
|
|
|
[ "", "", "Sync New\n" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
[ 10,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "F", 7, 7, "FT", 9, 9, "", 10, 10, "" ],
|
|
|
|
[ 10,
|
|
|
|
1, 1, "", 2, 2, "F", 3, 3, "F", 4, 4, "", 5, 5, "", 7, 7, "", 8, 8, "", 9, 10, "", 10, 9, "" ],
|
|
|
|
[ 9, 0, 9,
|
|
|
|
1, 1, "", 2, 2, "", 3, 3, "", 4, 4, "", 5, 5, "", 6, 6, "", 7, 7, "", 8, 8, "", 10, 9, "", 9, 10, "" ],
|
|
|
|
);
|
|
|
|
test(\@x01, \@X07);
|
|
|
|
|
|
|
|
#show("01", "08", "", "", "Sync PushFlags PullDelete\n");
|
|
|
|
my @X08 = (
|
2005-12-23 10:22:47 +00:00
|
|
|
[ "", "", "Sync PushFlags PullDelete\n" ],
|
2005-12-22 18:06:25 +00:00
|
|
|
[ 8,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "FS", 4, 4, "", 5, 5, "T", 6, 6, "F", 7, 7, "FT", 9, 0, "" ],
|
|
|
|
[ 8,
|
|
|
|
1, 1, "", 2, 2, "F", 3, 3, "F", 4, 4, "", 5, 5, "", 7, 7, "", 8, 8, "T", 10, 0, "" ],
|
|
|
|
[ 8, 0, 0,
|
|
|
|
1, 1, "", 2, 2, "F", 3, 3, "F", 4, 4, "", 5, 5, "", 6, 6, "", 7, 7, "", 0, 8, "" ],
|
|
|
|
);
|
|
|
|
test(\@x01, \@X08);
|
|
|
|
|
2005-12-26 16:01:42 +00:00
|
|
|
# size restriction tests
|
|
|
|
|
|
|
|
my @x10 = (
|
|
|
|
[ 0,
|
|
|
|
1, 0, "", 2, 0, "*" ],
|
|
|
|
[ 0,
|
|
|
|
3, 0, "*" ],
|
|
|
|
[ 0, 0, 0,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
#show("10", "11", "MaxSize 1k\n", "MaxSize 1k\n", "");
|
|
|
|
my @X11 = (
|
|
|
|
[ "MaxSize 1k\n", "MaxSize 1k\n", "" ],
|
|
|
|
[ 2,
|
|
|
|
1, 1, "", 2, 2, "*" ],
|
|
|
|
[ 2,
|
|
|
|
3, 1, "*", 1, 2, "" ],
|
|
|
|
[ 2, 0, 1,
|
|
|
|
-1, 1, "", 1, 2, "", 2, -1, "" ],
|
|
|
|
);
|
|
|
|
test(\@x10, \@X11);
|
|
|
|
|
|
|
|
my @x20 = @X11[1,2,3];
|
|
|
|
|
|
|
|
#show("20", "11", "MaxSize 1k\n", "MaxSize 1k\n", ""); # sic! - 11
|
|
|
|
test(\@x20, \@X11);
|
|
|
|
|
|
|
|
#show("20", "22", "", "MaxSize 1k\n", "");
|
|
|
|
my @X22 = (
|
|
|
|
[ "", "MaxSize 1k\n", "" ],
|
|
|
|
[ 3,
|
|
|
|
1, 1, "", 2, 2, "*", 3, 3, "*" ],
|
|
|
|
[ 2,
|
|
|
|
3, 1, "*", 1, 2, "" ],
|
|
|
|
[ 2, 0, 1,
|
|
|
|
3, 1, "", 1, 2, "", 2, -1, "" ],
|
|
|
|
);
|
|
|
|
test(\@x20, \@X22);
|
|
|
|
|
2005-12-26 16:02:08 +00:00
|
|
|
# expiration tests
|
|
|
|
|
|
|
|
my @x30 = (
|
|
|
|
[ 0,
|
|
|
|
1, 0, "F", 2, 0, "", 3, 0, "", 4, 0, "", 5, 0, "" ],
|
|
|
|
[ 0,
|
|
|
|
],
|
|
|
|
[ 0, 0, 0,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
#show("30", "31", "", "", "MaxMessages 3\n");
|
|
|
|
my @X31 = (
|
|
|
|
[ "", "", "MaxMessages 3\n" ],
|
|
|
|
[ 5,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
[ 5,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
[ 5, 0, 0,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
);
|
|
|
|
test(\@x30, \@X31);
|
|
|
|
|
|
|
|
my @x40 = @X31[1,2,3];
|
|
|
|
|
|
|
|
#show("40", "41", "", "", "MaxMessages 3\nExpunge Both\n");
|
|
|
|
my @X41 = (
|
|
|
|
[ "", "", "MaxMessages 3\nExpunge Both\n" ],
|
|
|
|
[ 5,
|
|
|
|
1, 1, "F", 2, 2, "", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
[ 5,
|
|
|
|
1, 1, "F", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
[ 5, 2, 0,
|
|
|
|
1, 1, "F", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
);
|
|
|
|
test(\@x40, \@X41);
|
|
|
|
|
|
|
|
my @x50 = (
|
|
|
|
[ 5,
|
|
|
|
1, 1, "F", 2, 2, "F", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
[ 5,
|
|
|
|
1, 1, " ", 2, 2, "T", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
[ 5, 2, 0,
|
|
|
|
1, 1, "F", 2, 2, "X", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
);
|
|
|
|
|
|
|
|
#show("50", "51", "", "", "MaxMessages 3\nExpunge Both\n");
|
|
|
|
my @X51 = (
|
|
|
|
[ "", "", "MaxMessages 3\nExpunge Both\n" ],
|
|
|
|
[ 5,
|
|
|
|
1, 1, "", 2, 2, "F", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
[ 5,
|
|
|
|
2, 2, "F", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
[ 5, 2, 0,
|
|
|
|
2, 2, "F", 3, 3, "", 4, 4, "", 5, 5, "" ],
|
|
|
|
);
|
|
|
|
test(\@x50, \@X51);
|
|
|
|
|
|
|
|
|
2005-12-22 18:06:25 +00:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
chdir "..";
|
|
|
|
rmdir "tmp";
|
|
|
|
print "OK.\n";
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
|
|
|
|
sub qm($)
|
|
|
|
{
|
|
|
|
shift;
|
|
|
|
s/\\/\\\\/g;
|
|
|
|
s/\"/\\"/g;
|
|
|
|
s/\"/\\"/g;
|
|
|
|
s/\n/\\n/g;
|
|
|
|
return $_;
|
|
|
|
}
|
|
|
|
|
2006-02-02 10:25:07 +00:00
|
|
|
# $global, $master, $slave
|
|
|
|
sub writecfg($$$)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
|
|
|
open(FILE, ">", ".mbsyncrc") or
|
|
|
|
die "Cannot open .mbsyncrc.\n";
|
|
|
|
print FILE
|
2012-09-15 13:15:22 +00:00
|
|
|
"FSync None
|
|
|
|
|
|
|
|
MaildirStore master
|
2005-12-22 18:06:25 +00:00
|
|
|
Path ./
|
|
|
|
Inbox ./master
|
|
|
|
".shift()."
|
|
|
|
MaildirStore slave
|
|
|
|
Path ./
|
|
|
|
Inbox ./slave
|
|
|
|
".shift()."
|
|
|
|
Channel test
|
|
|
|
Master :master:
|
|
|
|
Slave :slave:
|
|
|
|
SyncState *
|
|
|
|
".shift();
|
|
|
|
close FILE;
|
2006-02-02 10:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub killcfg()
|
|
|
|
{
|
2005-12-22 18:06:25 +00:00
|
|
|
unlink ".mbsyncrc";
|
2006-02-02 10:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $options
|
|
|
|
sub runsync($)
|
|
|
|
{
|
2006-12-09 10:38:11 +00:00
|
|
|
# open FILE, "valgrind -q --log-fd=3 ../mbsync ".shift()." -c .mbsyncrc test 3>&2 2>&1 |";
|
2012-08-25 13:29:16 +00:00
|
|
|
open FILE, "../mbsync -D -Z ".shift()." -c .mbsyncrc test 2>&1 |";
|
2006-02-02 10:25:07 +00:00
|
|
|
my @out = <FILE>;
|
|
|
|
close FILE or push(@out, $! ? "*** error closing mbsync: $!\n" : "*** mbsync exited with signal ".($?&127).", code ".($?>>8)."\n");
|
2006-12-09 10:38:11 +00:00
|
|
|
return $?, @out;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-02 10:25:07 +00:00
|
|
|
|
2005-12-22 18:06:25 +00:00
|
|
|
# $path
|
|
|
|
sub readbox($)
|
|
|
|
{
|
|
|
|
my $bn = shift;
|
|
|
|
|
|
|
|
(-d $bn) or
|
|
|
|
die "No mailbox '$bn'.\n";
|
|
|
|
(-d $bn."/tmp" and -d $bn."/new" and -d $bn."/cur") or
|
|
|
|
die "Invalid mailbox '$bn'.\n";
|
|
|
|
open(FILE, "<", $bn."/.uidvalidity") or die "Cannot read UID validity of mailbox '$bn'.\n";
|
|
|
|
my $dummy = <FILE>;
|
|
|
|
chomp(my $mu = <FILE>);
|
|
|
|
close FILE;
|
|
|
|
my %ms = ();
|
|
|
|
for my $d ("cur", "new") {
|
|
|
|
opendir(DIR, $bn."/".$d) or next;
|
|
|
|
for my $f (grep(!/^\.\.?$/, readdir(DIR))) {
|
|
|
|
my ($uid, $flg, $num);
|
|
|
|
if ($f =~ /^\d+\.\d+_\d+\.[-[:alnum:]]+,U=(\d+):2,(.*)$/) {
|
|
|
|
($uid, $flg) = ($1, $2);
|
|
|
|
} elsif ($f =~ /^\d+\.\d+_(\d+)\.[-[:alnum:]]+:2,(.*)$/) {
|
|
|
|
($uid, $flg) = (0, $2);
|
|
|
|
} else {
|
|
|
|
print STDERR "unrecognided file name '$f' in '$bn'.\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
open(FILE, "<", $bn."/".$d."/".$f) or die "Cannot read message '$f' in '$bn'.\n";
|
2005-12-26 16:01:42 +00:00
|
|
|
my $sz = 0;
|
2005-12-22 18:06:25 +00:00
|
|
|
while (<FILE>) {
|
|
|
|
/^Subject: (\d+)$/ && ($num = $1);
|
2005-12-26 16:01:42 +00:00
|
|
|
$sz += length($_);
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
close FILE;
|
|
|
|
if (!defined($num)) {
|
|
|
|
print STDERR "message '$f' in '$bn' has no identifier.\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
2005-12-26 16:01:42 +00:00
|
|
|
@{ $ms{$num} } = ($uid, $flg.($sz>1000?"*":""));
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ($mu, %ms);
|
|
|
|
}
|
|
|
|
|
2005-12-27 17:31:04 +00:00
|
|
|
# $boxname
|
|
|
|
sub showbox($)
|
|
|
|
{
|
|
|
|
my ($bn) = @_;
|
|
|
|
|
|
|
|
my ($mu, %ms) = readbox($bn);
|
|
|
|
print " [ $mu,\n ";
|
|
|
|
my $frst = 1;
|
2013-11-02 15:43:23 +00:00
|
|
|
for my $num (sort { $a <=> $b } keys %ms) {
|
2005-12-27 17:31:04 +00:00
|
|
|
if ($frst) {
|
|
|
|
$frst = 0;
|
|
|
|
} else {
|
|
|
|
print ", ";
|
|
|
|
}
|
|
|
|
print "$num, $ms{$num}[0], \"$ms{$num}[1]\"";
|
|
|
|
}
|
|
|
|
print " ],\n";
|
|
|
|
}
|
|
|
|
|
2006-02-02 10:25:07 +00:00
|
|
|
# $filename
|
|
|
|
sub showstate($)
|
2005-12-27 17:31:04 +00:00
|
|
|
{
|
2006-02-02 10:25:07 +00:00
|
|
|
my ($fn) = @_;
|
|
|
|
|
|
|
|
if (!open(FILE, "<", $fn)) {
|
|
|
|
print STDERR " Cannot read sync state $fn: $!\n";
|
|
|
|
return;
|
|
|
|
}
|
2005-12-27 17:31:04 +00:00
|
|
|
$_ = <FILE>;
|
2006-02-02 10:25:07 +00:00
|
|
|
if (!defined $_) {
|
|
|
|
print STDERR " Missing sync state header.\n";
|
|
|
|
close FILE;
|
|
|
|
return;
|
|
|
|
}
|
2013-03-30 15:27:11 +00:00
|
|
|
if (!/^1:(\d+) 1:(\d+):(\d+)\n$/) {
|
2013-11-02 14:42:34 +00:00
|
|
|
chomp;
|
2006-02-02 10:25:07 +00:00
|
|
|
print STDERR " Malformed sync state header '$_'.\n";
|
|
|
|
close FILE;
|
|
|
|
return;
|
|
|
|
}
|
2005-12-27 17:31:04 +00:00
|
|
|
print " [ $1, $2, $3,\n ";
|
|
|
|
my $frst = 1;
|
|
|
|
for (<FILE>) {
|
|
|
|
if ($frst) {
|
|
|
|
$frst = 0;
|
|
|
|
} else {
|
|
|
|
print ", ";
|
|
|
|
}
|
2006-02-02 10:25:07 +00:00
|
|
|
if (!/^(-?\d+) (-?\d+) (.*)\n$/) {
|
|
|
|
print "??, ??, \"??\"";
|
|
|
|
} else {
|
|
|
|
print "$1, $2, \"$3\"";
|
|
|
|
}
|
2005-12-27 17:31:04 +00:00
|
|
|
}
|
|
|
|
print " ],\n";
|
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
|
2006-02-02 10:25:07 +00:00
|
|
|
# $filename
|
|
|
|
sub showchan($)
|
|
|
|
{
|
|
|
|
my ($fn) = @_;
|
|
|
|
|
|
|
|
showbox("master");
|
|
|
|
showbox("slave");
|
|
|
|
showstate($fn);
|
|
|
|
}
|
|
|
|
|
2005-12-27 17:31:04 +00:00
|
|
|
sub show($$@)
|
|
|
|
{
|
|
|
|
my ($sx, $tx, @sfx) = @_;
|
|
|
|
my @sp;
|
|
|
|
eval "\@sp = \@x$sx";
|
|
|
|
mkchan($sp[0], $sp[1], @{ $sp[2] });
|
|
|
|
print "my \@x$sx = (\n";
|
2006-02-02 10:25:07 +00:00
|
|
|
showchan("slave/.mbsyncstate");
|
2005-12-27 17:31:04 +00:00
|
|
|
print ");\n";
|
2006-02-02 10:25:07 +00:00
|
|
|
&writecfg(@sfx);
|
|
|
|
runsync("");
|
|
|
|
killcfg();
|
2005-12-27 17:31:04 +00:00
|
|
|
print "my \@X$tx = (\n";
|
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @sfx))." ],\n";
|
2006-02-02 10:25:07 +00:00
|
|
|
showchan("slave/.mbsyncstate");
|
2005-12-27 17:31:04 +00:00
|
|
|
print ");\n";
|
|
|
|
print "test(\\\@x$sx, \\\@X$tx);\n\n";
|
|
|
|
rmtree "slave";
|
|
|
|
rmtree "master";
|
|
|
|
}
|
|
|
|
|
2005-12-22 18:06:25 +00:00
|
|
|
# $boxname, $maxuid, @msgs
|
|
|
|
sub mkbox($$@)
|
|
|
|
{
|
|
|
|
my ($bn, $mu, @ms) = @_;
|
|
|
|
|
|
|
|
rmtree($bn);
|
|
|
|
(mkdir($bn) and mkdir($bn."/tmp") and mkdir($bn."/new") and mkdir($bn."/cur")) or
|
|
|
|
die "Cannot create mailbox $bn.\n";
|
|
|
|
open(FILE, ">", $bn."/.uidvalidity") or die "Cannot create UID validity for mailbox $bn.\n";
|
|
|
|
print FILE "1\n$mu\n";
|
|
|
|
close FILE;
|
|
|
|
while (@ms) {
|
|
|
|
my ($num, $uid, $flg) = (shift @ms, shift @ms, shift @ms);
|
|
|
|
if ($uid) {
|
|
|
|
$uid = ",U=".$uid;
|
|
|
|
} else {
|
|
|
|
$uid = "";
|
|
|
|
}
|
2005-12-26 16:01:42 +00:00
|
|
|
my $big = $flg =~ s/\*//;
|
2005-12-22 18:06:25 +00:00
|
|
|
open(FILE, ">", $bn."/cur/0.1_".$num.".local".$uid.":2,".$flg) or
|
|
|
|
die "Cannot create message $num in mailbox $bn.\n";
|
2005-12-26 16:01:42 +00:00
|
|
|
print FILE "From: foo\nTo: bar\nDate: Thu, 1 Jan 1970 00:00:00 +0000\nSubject: $num\n\n".(("A"x50)."\n")x($big*30);
|
2005-12-22 18:06:25 +00:00
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# \@master, \@slave, @syncstate
|
|
|
|
sub mkchan($$@)
|
|
|
|
{
|
|
|
|
my ($m, $s, @t) = @_;
|
|
|
|
&mkbox("master", @{ $m });
|
|
|
|
&mkbox("slave", @{ $s });
|
|
|
|
open(FILE, ">", "slave/.mbsyncstate") or
|
|
|
|
die "Cannot create sync state.\n";
|
|
|
|
print FILE "1:".shift(@t)." 1:".shift(@t).":".shift(@t)."\n";
|
|
|
|
while (@t) {
|
|
|
|
print FILE shift(@t)." ".shift(@t)." ".shift(@t)."\n";
|
|
|
|
}
|
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
# $config, $boxname, $maxuid, @msgs
|
|
|
|
sub ckbox($$$@)
|
|
|
|
{
|
2005-12-27 17:31:04 +00:00
|
|
|
my ($bn, $MU, @MS) = @_;
|
2005-12-22 18:06:25 +00:00
|
|
|
|
|
|
|
my ($mu, %ms) = readbox($bn);
|
|
|
|
if ($mu != $MU) {
|
2005-12-27 17:31:04 +00:00
|
|
|
print STDERR "MAXUID mismatch for '$bn'.\n";
|
|
|
|
return 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
while (@MS) {
|
|
|
|
my ($num, $uid, $flg) = (shift @MS, shift @MS, shift @MS);
|
|
|
|
if (!defined $ms{$num}) {
|
2005-12-27 17:31:04 +00:00
|
|
|
print STDERR "No message $bn:$num.\n";
|
|
|
|
return 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
if ($ms{$num}[0] ne $uid) {
|
2005-12-27 17:31:04 +00:00
|
|
|
print STDERR "UID mismatch for $bn:$num.\n";
|
|
|
|
return 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
if ($ms{$num}[1] ne $flg) {
|
2005-12-27 17:31:04 +00:00
|
|
|
print STDERR "Flag mismatch for $bn:$num.\n";
|
|
|
|
return 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2005-12-26 15:58:12 +00:00
|
|
|
delete $ms{$num};
|
|
|
|
}
|
|
|
|
if (%ms) {
|
2005-12-27 17:31:04 +00:00
|
|
|
print STDERR "Excess messages in '$bn': ".join(", ", sort({$a <=> $b } keys(%ms))).".\n";
|
|
|
|
return 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2005-12-27 17:31:04 +00:00
|
|
|
return 0;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-02 10:25:07 +00:00
|
|
|
# $filename, @syncstate
|
|
|
|
sub ckstate($@)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2006-02-02 10:25:07 +00:00
|
|
|
my ($fn, @T) = @_;
|
|
|
|
open(FILE, "<", $fn) or die "Cannot read sync state $fn.\n";
|
|
|
|
my $l = <FILE>;
|
2005-12-27 17:31:04 +00:00
|
|
|
chomp(my @ls = <FILE>);
|
2005-12-22 18:06:25 +00:00
|
|
|
close FILE;
|
2006-02-02 10:25:07 +00:00
|
|
|
if (!defined $l) {
|
|
|
|
print STDERR "Sync state header missing.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
chomp($l);
|
2013-03-30 15:27:11 +00:00
|
|
|
my $xl = "1:".shift(@T)." 1:".shift(@T).":".shift(@T);
|
2005-12-22 18:06:25 +00:00
|
|
|
if ($l ne $xl) {
|
2005-12-27 17:31:04 +00:00
|
|
|
print STDERR "Sync state header mismatch: '$l' instead of '$xl'.\n";
|
2006-02-02 10:25:07 +00:00
|
|
|
return 1;
|
2005-12-27 17:31:04 +00:00
|
|
|
} else {
|
|
|
|
for $l (@ls) {
|
|
|
|
$xl = shift(@T)." ".shift(@T)." ".shift(@T);
|
|
|
|
if ($l ne $xl) {
|
|
|
|
print STDERR "Sync state entry mismatch: '$l' instead of '$xl'.\n";
|
2006-02-02 10:25:07 +00:00
|
|
|
return 1;
|
2005-12-27 17:31:04 +00:00
|
|
|
}
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-02 10:25:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# \@master, \@slave, @syncstate
|
|
|
|
sub ckchan($$@)
|
|
|
|
{
|
|
|
|
my ($M, $S, @T) = @_;
|
|
|
|
my $rslt = ckstate("slave/.mbsyncstate.new", @T);
|
2005-12-27 17:31:04 +00:00
|
|
|
$rslt |= &ckbox("master", @{ $M });
|
|
|
|
$rslt |= &ckbox("slave", @{ $S });
|
|
|
|
return $rslt;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2005-12-27 17:31:04 +00:00
|
|
|
sub printbox($$@)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2005-12-27 17:31:04 +00:00
|
|
|
my ($bn, $mu, @ms) = @_;
|
2005-12-22 18:06:25 +00:00
|
|
|
|
2005-12-26 15:54:09 +00:00
|
|
|
print " [ $mu,\n ";
|
2005-12-22 18:06:25 +00:00
|
|
|
my $frst = 1;
|
2005-12-27 17:31:04 +00:00
|
|
|
while (@ms) {
|
2005-12-22 18:06:25 +00:00
|
|
|
if ($frst) {
|
|
|
|
$frst = 0;
|
|
|
|
} else {
|
|
|
|
print ", ";
|
|
|
|
}
|
2005-12-27 17:31:04 +00:00
|
|
|
print shift(@ms).", ".shift(@ms).", \"".shift(@ms)."\"";
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
print " ],\n";
|
|
|
|
}
|
|
|
|
|
2006-02-02 10:25:07 +00:00
|
|
|
# @syncstate
|
|
|
|
sub printstate(@)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2006-02-02 10:25:07 +00:00
|
|
|
my (@t) = @_;
|
2005-12-27 17:31:04 +00:00
|
|
|
|
|
|
|
print " [ ".shift(@t).", ".shift(@t).", ".shift(@t).",\n ";
|
2005-12-22 18:06:25 +00:00
|
|
|
my $frst = 1;
|
2005-12-27 17:31:04 +00:00
|
|
|
while (@t) {
|
2005-12-22 18:06:25 +00:00
|
|
|
if ($frst) {
|
|
|
|
$frst = 0;
|
|
|
|
} else {
|
|
|
|
print ", ";
|
|
|
|
}
|
2005-12-27 17:31:04 +00:00
|
|
|
print shift(@t).", ".shift(@t).", \"".shift(@t)."\"";
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
print " ],\n";
|
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
|
2006-02-02 10:25:07 +00:00
|
|
|
# \@master, \@slave, @syncstate
|
|
|
|
sub printchan($$@)
|
|
|
|
{
|
|
|
|
my ($m, $s, @t) = @_;
|
|
|
|
|
|
|
|
&printbox("master", @{ $m });
|
|
|
|
&printbox("slave", @{ $s });
|
|
|
|
printstate(@t);
|
|
|
|
}
|
|
|
|
|
2005-12-27 17:31:04 +00:00
|
|
|
sub test($$)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2005-12-27 17:31:04 +00:00
|
|
|
my ($sx, $tx) = @_;
|
|
|
|
|
|
|
|
mkchan($$sx[0], $$sx[1], @{ $$sx[2] });
|
2006-02-02 10:25:07 +00:00
|
|
|
&writecfg(@{ $$tx[0] });
|
2006-12-09 10:38:11 +00:00
|
|
|
my ($xc, @ret) = runsync("-J");
|
|
|
|
if ($xc) {
|
|
|
|
print "Input:\n";
|
|
|
|
printchan($$sx[0], $$sx[1], @{ $$sx[2] });
|
|
|
|
print "Options:\n";
|
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @{ $$tx[0] }))." ]\n";
|
|
|
|
print "Expected result:\n";
|
|
|
|
printchan($$tx[1], $$tx[2], @{ $$tx[3] });
|
|
|
|
print "Debug output:\n";
|
|
|
|
print @ret;
|
|
|
|
exit 1;
|
|
|
|
}
|
2006-02-02 10:25:07 +00:00
|
|
|
if (ckchan($$tx[1], $$tx[2], @{ $$tx[3] })) {
|
2005-12-27 17:31:04 +00:00
|
|
|
print "Input:\n";
|
|
|
|
printchan($$sx[0], $$sx[1], @{ $$sx[2] });
|
|
|
|
print "Options:\n";
|
2006-02-02 10:25:07 +00:00
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @{ $$tx[0] }))." ]\n";
|
2005-12-27 17:31:04 +00:00
|
|
|
print "Expected result:\n";
|
|
|
|
printchan($$tx[1], $$tx[2], @{ $$tx[3] });
|
|
|
|
print "Actual result:\n";
|
2006-02-02 10:25:07 +00:00
|
|
|
showchan("slave/.mbsyncstate.new");
|
|
|
|
print "Debug output:\n";
|
|
|
|
print @ret;
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
open(FILE, "<", "slave/.mbsyncstate.journal") or
|
|
|
|
die "Cannot read journal.\n";
|
|
|
|
my @nj = <FILE>;
|
|
|
|
close FILE;
|
2013-11-03 11:59:35 +00:00
|
|
|
($xc, @ret) = runsync("-0 --no-expunge");
|
2006-02-02 10:25:07 +00:00
|
|
|
killcfg();
|
2013-11-03 11:59:35 +00:00
|
|
|
if ($xc) {
|
|
|
|
print "Journal replay failed.\n";
|
|
|
|
print "Input == Expected result:\n";
|
|
|
|
printchan($$tx[1], $$tx[2], @{ $$tx[3] });
|
|
|
|
print "Options:\n";
|
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @{ $$tx[0] }))." ], [ \"-0\", \"--no-expunge\" ]\n";
|
|
|
|
print "Debug output:\n";
|
|
|
|
print @ret;
|
|
|
|
exit 1;
|
|
|
|
}
|
2006-02-02 10:25:07 +00:00
|
|
|
if (ckstate("slave/.mbsyncstate", @{ $$tx[3] })) {
|
|
|
|
print "Options:\n";
|
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @{ $$tx[0] }))." ]\n";
|
|
|
|
print "Old State:\n";
|
|
|
|
printstate(@{ $$sx[2] });
|
|
|
|
print "Journal:\n".join("", @nj)."\n";
|
|
|
|
print "Expected New State:\n";
|
|
|
|
printstate(@{ $$tx[3] });
|
|
|
|
print "New State:\n";
|
|
|
|
showstate("slave/.mbsyncstate");
|
2005-12-27 17:44:31 +00:00
|
|
|
print "Debug output:\n";
|
|
|
|
print @ret;
|
2005-12-27 17:31:04 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2005-12-22 18:06:25 +00:00
|
|
|
rmtree "slave";
|
|
|
|
rmtree "master";
|
|
|
|
}
|