2005-12-22 18:06:25 +00:00
|
|
|
#! /usr/bin/perl -w
|
2006-02-11 19:48:44 +00:00
|
|
|
#
|
2022-06-16 10:44:35 +00:00
|
|
|
# SPDX-FileCopyrightText: 2006-2022 Oswald Buddenhagen <ossi@users.sf.net>
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2006-02-11 19:48:44 +00:00
|
|
|
#
|
2005-12-22 18:06:25 +00:00
|
|
|
|
2017-03-14 10:10:35 +00:00
|
|
|
use warnings;
|
2005-12-22 18:06:25 +00:00
|
|
|
use strict;
|
2022-01-25 20:45:06 +00:00
|
|
|
|
|
|
|
use Carp;
|
|
|
|
$SIG{__WARN__} = \&Carp::cluck;
|
|
|
|
$SIG{__DIE__} = \&Carp::confess;
|
|
|
|
|
2017-03-14 14:01:13 +00:00
|
|
|
use Cwd;
|
2022-02-20 12:00:55 +00:00
|
|
|
use Clone 'clone';
|
2005-12-22 18:06:25 +00:00
|
|
|
use File::Path;
|
2019-12-29 10:59:05 +00:00
|
|
|
use File::Temp 'tempdir';
|
2005-12-22 18:06:25 +00:00
|
|
|
|
2017-03-26 19:06:11 +00:00
|
|
|
my $use_vg = $ENV{USE_VALGRIND};
|
2022-04-04 19:51:16 +00:00
|
|
|
my $use_st = $ENV{USE_STRACE};
|
2017-03-14 14:01:13 +00:00
|
|
|
my $mbsync = getcwd()."/mbsync";
|
|
|
|
|
2022-01-26 17:46:58 +00:00
|
|
|
my (@match, $start);
|
|
|
|
for my $arg (@ARGV) {
|
|
|
|
if ($arg eq "+") {
|
|
|
|
$start = 1;
|
|
|
|
} else {
|
|
|
|
push @match, $arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
die("Need exactly one test name when using start syntax.\n")
|
|
|
|
if ($start && (@match != 1));
|
|
|
|
|
2019-12-29 10:59:05 +00:00
|
|
|
if (!-d "tmp") {
|
|
|
|
unlink "tmp";
|
|
|
|
my $tdir = tempdir();
|
|
|
|
symlink $tdir, "tmp" or die "Cannot symlink temp directory: $!\n";
|
|
|
|
}
|
2005-12-22 18:06:25 +00:00
|
|
|
chdir "tmp" or die "Cannot enter temp direcory.\n";
|
|
|
|
|
2020-04-02 18:39:07 +00:00
|
|
|
use enum qw(:=1 A..Z);
|
2022-01-27 13:22:29 +00:00
|
|
|
sub mn($) { my ($n) = @_; $n == 0 ? "0" : chr(64 + $n) }
|
|
|
|
sub mf($) { my ($f) = @_; length($f) ? $f : '-' }
|
2020-04-02 18:39:07 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
my $sync_flags = "<>^~DFPRST";
|
|
|
|
my $msg_flags = "DFPRST*?";
|
2019-12-29 13:37:53 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
sub process_flag_add($$$$$$)
|
|
|
|
{
|
|
|
|
my ($flgr, $add, $ok_flags, $num, $e, $what) = @_;
|
|
|
|
|
|
|
|
return if ($add eq "");
|
|
|
|
for my $flg (split('', $add)) {
|
|
|
|
die("Adding invalid flag '$flg' for $what ".mn($num)." (at $e).\n")
|
|
|
|
if (index($ok_flags, $flg) < 0);
|
|
|
|
my $i = index($$flgr, $flg);
|
|
|
|
die("Adding duplicate flag '$flg' to $what ".mn($num)." (at $e).\n")
|
|
|
|
if ($i >= 0);
|
|
|
|
$$flgr .= $flg;
|
|
|
|
}
|
|
|
|
$$flgr = $ok_flags =~ s/[^$$flgr]//gr; # sort
|
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
sub process_flag_del($$$$$)
|
|
|
|
{
|
|
|
|
my ($flgr, $del, $num, $e, $what) = @_;
|
2019-12-29 13:37:53 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
for my $flg (split('', $del)) {
|
|
|
|
my $i = index($$flgr, $flg);
|
|
|
|
die("Removing absent flag '$flg' from $what ".mn($num)." (at $e).\n")
|
|
|
|
if ($i < 0);
|
|
|
|
substr($$flgr, $i, 1) = '';
|
|
|
|
}
|
|
|
|
}
|
2019-12-29 13:37:53 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
sub process_flag_update($$$$$$$)
|
|
|
|
{
|
|
|
|
my ($flgr, $add, $del, $ok_flags, $num, $e, $what) = @_;
|
2019-12-29 13:37:53 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
process_flag_del($flgr, $del, $num, $e, $what);
|
|
|
|
process_flag_add($flgr, $add, $ok_flags, $num, $e, $what);
|
|
|
|
}
|
2005-12-26 16:01:42 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
sub parse_flags($$$$$)
|
|
|
|
{
|
|
|
|
my ($rflg, $ok_flags, $num, $e, $what) = @_;
|
2005-12-26 16:02:08 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
my $add = $$rflg;
|
|
|
|
$$rflg = "";
|
|
|
|
process_flag_add($rflg, $add, $ok_flags, $num, $e, $what);
|
|
|
|
}
|
2005-12-26 16:02:08 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
sub parse_flag_update($)
|
|
|
|
{
|
|
|
|
my ($stsr) = @_;
|
2005-12-26 16:02:08 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
my ($add, $del) = ("", "");
|
|
|
|
while ($$stsr =~ s,^([-+])([^-+]+),,) {
|
|
|
|
if ($1 eq "+") {
|
|
|
|
$add .= $2;
|
|
|
|
} else {
|
|
|
|
$del .= $2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ($add, $del);
|
|
|
|
}
|
2013-11-24 19:26:33 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
# Returns UID.
|
|
|
|
sub create_msg($$$$$)
|
|
|
|
{
|
|
|
|
my ($num, $flg, $bs, $t, $e) = @_;
|
2005-12-26 16:02:08 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
my ($mur, $msr, $n2ur) = (\$$bs{max_uid}, $$bs{messages}, $$bs{num2uid});
|
|
|
|
$$mur++;
|
|
|
|
if ($flg ne "_") {
|
|
|
|
parse_flags(\$flg, $msg_flags, $num, $e, "$t side");
|
|
|
|
$$msr{$$mur} = [ $num, $flg ];
|
|
|
|
}
|
|
|
|
push @{$$n2ur{$num}}, $$mur;
|
|
|
|
return $$mur;
|
|
|
|
}
|
2005-12-26 16:02:08 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
# Returns old UID, new UID.
|
|
|
|
sub parse_msg($$$$$)
|
|
|
|
{
|
|
|
|
my ($num, $sts, $cs, $t, $e) = @_;
|
|
|
|
|
|
|
|
my $bs = $$cs{$t};
|
|
|
|
my ($msr, $n2ur) = ($$bs{messages}, $$bs{num2uid});
|
|
|
|
|
2022-04-04 16:55:14 +00:00
|
|
|
$$cs{"${t}_trash"}{$num} = 1
|
|
|
|
if ($sts =~ s,^#,,);
|
2022-02-20 12:00:55 +00:00
|
|
|
my $ouid;
|
|
|
|
my $uids = \@{$$n2ur{$num}};
|
|
|
|
if ($sts =~ s,^&$,,) {
|
|
|
|
$ouid = 0;
|
|
|
|
} elsif ($sts =~ s,^&(\d+),,) {
|
|
|
|
my $n = int($1);
|
|
|
|
die("Referencing unrecognized instance $n of message ".mn($num)." on $t side (at $e).\n")
|
|
|
|
if (!$n || $n > @$uids);
|
|
|
|
$ouid = $$uids[$n - 1];
|
|
|
|
} else {
|
|
|
|
$ouid = @$uids ? $$uids[-1] : 0;
|
|
|
|
}
|
|
|
|
my $nuid = ($sts =~ s,^\|,,) ? 0 : $ouid;
|
|
|
|
if ($sts eq "_" or $sts =~ s,^\*,,) {
|
|
|
|
die("Adding already present message ".mn($num)." on $t side (at $e).\n")
|
|
|
|
if (defined($$msr{$ouid}));
|
|
|
|
$nuid = create_msg($num, $sts, $bs, $t, $e);
|
|
|
|
} elsif ($sts =~ s,^\^,,) {
|
|
|
|
die("Duplicating absent message ".mn($num)." on $t side (at $e).\n")
|
|
|
|
if (!defined($$msr{$ouid}));
|
|
|
|
$nuid = create_msg($num, $sts, $bs, $t, $e);
|
|
|
|
} elsif ($sts eq "/") {
|
|
|
|
# Note that we don't delete $$n2ur{$num}, as state entries may
|
|
|
|
# refer to expunged messages. Subject re-use is not supported here.
|
|
|
|
die("Deleting absent message ".mn($num)." from $t side (at $e).\n")
|
|
|
|
if (!delete $$msr{$ouid});
|
|
|
|
$nuid = 0;
|
|
|
|
} elsif ($sts ne "") {
|
|
|
|
my ($add, $del) = parse_flag_update(\$sts);
|
|
|
|
die("Unrecognized message command '$sts' for $t side (at $e).\n")
|
|
|
|
if ($sts ne "");
|
|
|
|
die("No message ".mn($num)." present on $t side (at $e).\n")
|
|
|
|
if (!defined($$msr{$ouid}));
|
|
|
|
process_flag_update(\$$msr{$ouid}[1], $add, $del, $msg_flags, $num, $e, "$t side");
|
|
|
|
}
|
|
|
|
return $ouid, $nuid;
|
|
|
|
}
|
2005-12-26 16:02:08 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
# Returns UID.
|
|
|
|
sub resolv_msg($$$)
|
|
|
|
{
|
|
|
|
my ($num, $cs, $t) = @_;
|
2005-12-22 18:06:25 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
return 0 if (!$num);
|
|
|
|
my $uids = \@{$$cs{$t}{num2uid}{$num}};
|
|
|
|
die("No message ".mn($num)." present on $t side (in header).\n")
|
|
|
|
if (!@$uids);
|
|
|
|
return $$uids[-1];
|
|
|
|
}
|
2005-12-22 18:06:25 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
# Returns index, or undef if not found.
|
|
|
|
sub find_ent($$$)
|
2022-01-23 23:33:53 +00:00
|
|
|
{
|
2022-02-20 12:00:55 +00:00
|
|
|
my ($fu, $nu, $ents) = @_;
|
2022-01-23 23:33:53 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
for (my $i = 0; $i < @$ents; $i++) {
|
|
|
|
my $ent = $$ents[$i];
|
|
|
|
return $i if ($$ent[0] == $fu and $$ent[1] == $nu);
|
2022-01-23 23:33:53 +00:00
|
|
|
}
|
2022-02-20 12:00:55 +00:00
|
|
|
return undef;
|
2022-01-23 23:33:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
sub find_ent_chk($$$$$)
|
2022-01-23 23:33:53 +00:00
|
|
|
{
|
2022-02-20 12:00:55 +00:00
|
|
|
my ($fu, $nu, $cs, $num, $e) = @_;
|
2022-01-23 23:33:53 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
my $enti = find_ent($fu, $nu, $$cs{state}{entries});
|
|
|
|
die("No state entry $fu:$nu present for ".mn($num)." (at $e).\n")
|
|
|
|
if (!defined($enti));
|
|
|
|
return $enti;
|
2022-01-23 23:33:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
sub parse_chan($;$)
|
2022-01-23 23:33:53 +00:00
|
|
|
{
|
2022-02-20 12:00:55 +00:00
|
|
|
my ($ics, $ref) = @_;
|
2022-01-23 23:33:53 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
my $cs;
|
|
|
|
if ($ref) {
|
|
|
|
$cs = clone($ref);
|
|
|
|
} else {
|
|
|
|
$cs = {
|
|
|
|
# messages: { uid => [ subject, flags ], ... }
|
|
|
|
far => { max_uid => 0, messages => {}, num2uid => {} },
|
|
|
|
near => { max_uid => 0, messages => {}, num2uid => {} },
|
2022-04-04 16:55:14 +00:00
|
|
|
# trashed messages: { subject => is_placeholder, ... }
|
|
|
|
far_trash => { },
|
|
|
|
near_trash => { },
|
2022-02-20 12:00:55 +00:00
|
|
|
# entries: [ [ far_uid, near_uid, flags ], ... ]
|
|
|
|
state => { entries => [] }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ss = $$cs{state};
|
|
|
|
my $ents = $$ss{entries};
|
|
|
|
my $enti;
|
|
|
|
for (my ($i, $e) = (3, 1); $i < @$ics; $i += 4, $e++) {
|
|
|
|
my ($num, $far, $sts, $near) = @{$ics}[$i .. $i+3];
|
|
|
|
my ($ofu, $nfu) = parse_msg($num, $far, $cs, "far", $e);
|
|
|
|
my ($onu, $nnu) = parse_msg($num, $near, $cs, "near", $e);
|
|
|
|
if ($sts =~ s,^\*,,) {
|
|
|
|
$enti = find_ent($nfu, $nnu, $ents);
|
|
|
|
die("State entry $nfu:$nnu already present for ".mn($num)." (at $e).\n")
|
|
|
|
if (defined($enti));
|
|
|
|
parse_flags(\$sts, $sync_flags, $num, $e, "sync entry");
|
|
|
|
push @$ents, [ $nfu, $nnu, $sts ];
|
|
|
|
} elsif ($sts =~ s,^\^,,) {
|
|
|
|
die("No current state entry for ".mn($num)." (at $e).\n")
|
|
|
|
if (!defined($enti));
|
|
|
|
parse_flags(\$sts, $sync_flags, $num, $e, "sync entry");
|
|
|
|
splice @$ents, $enti++, 0, ([ $nfu, $nnu, $sts ]);
|
|
|
|
} elsif ($sts eq "/") {
|
|
|
|
$enti = find_ent_chk($ofu, $onu, $cs, $num, $e);
|
|
|
|
splice @$ents, $enti, 1;
|
|
|
|
} elsif ($sts ne "") {
|
|
|
|
my $t = -1;
|
|
|
|
if ($sts =~ s,^<,,) {
|
|
|
|
$t = 0;
|
|
|
|
} elsif ($sts =~ s,^>,,) {
|
|
|
|
$t = 1;
|
|
|
|
}
|
|
|
|
my ($add, $del) = parse_flag_update(\$sts);
|
|
|
|
die("Unrecognized state command '".$sts."' for ".mn($num)." (at $e).\n")
|
|
|
|
if ($sts ne "");
|
|
|
|
$enti = find_ent_chk($ofu, $onu, $cs, $num, $e);
|
|
|
|
my $ent = $$ents[$enti++];
|
|
|
|
process_flag_update(\$$ent[2], $add, $del, $sync_flags, $num, $e, "sync entry");
|
|
|
|
if ($t >= 0) {
|
|
|
|
my $uid = $t ? $nnu : $nfu;
|
|
|
|
$$ent[$t] = ($uid && $$cs{$t ? "near" : "far"}{messages}{$uid}) ? $uid : 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$enti = undef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$$ss{max_pulled} = resolv_msg($$ics[0], $cs, "far");
|
|
|
|
$$ss{max_expired} = resolv_msg($$ics[1], $cs, "far");
|
|
|
|
$$ss{max_pushed} = resolv_msg($$ics[2], $cs, "near");
|
|
|
|
|
|
|
|
return $cs;
|
2022-01-23 23:33:53 +00:00
|
|
|
}
|
2005-12-22 18:06:25 +00:00
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
|
2005-12-22 18:06:25 +00:00
|
|
|
sub qm($)
|
|
|
|
{
|
|
|
|
shift;
|
|
|
|
s/\\/\\\\/g;
|
|
|
|
s/\"/\\"/g;
|
|
|
|
s/\"/\\"/g;
|
|
|
|
s/\n/\\n/g;
|
|
|
|
return $_;
|
|
|
|
}
|
|
|
|
|
2020-12-18 13:31:16 +00:00
|
|
|
# [ $far, $near, $channel ]
|
|
|
|
sub writecfg($)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2020-12-18 13:31:16 +00:00
|
|
|
my ($sfx) = @_;
|
|
|
|
|
2005-12-22 18:06:25 +00:00
|
|
|
open(FILE, ">", ".mbsyncrc") or
|
|
|
|
die "Cannot open .mbsyncrc.\n";
|
|
|
|
print FILE
|
2013-11-02 20:42:34 +00:00
|
|
|
"FSync no
|
2012-09-15 13:15:22 +00:00
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
MaildirStore far
|
2022-05-30 21:04:52 +00:00
|
|
|
Path \"\"
|
|
|
|
Inbox far
|
2020-12-18 13:31:16 +00:00
|
|
|
".$$sfx[0]."
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
MaildirStore near
|
2022-05-30 21:04:52 +00:00
|
|
|
Path \"\"
|
|
|
|
Inbox near
|
2020-12-18 13:31:16 +00:00
|
|
|
".$$sfx[1]."
|
2005-12-22 18:06:25 +00:00
|
|
|
Channel test
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
Far :far:
|
|
|
|
Near :near:
|
2005-12-22 18:06:25 +00:00
|
|
|
SyncState *
|
2020-12-18 13:31:16 +00:00
|
|
|
".$$sfx[2];
|
2005-12-22 18:06:25 +00:00
|
|
|
close FILE;
|
2006-02-02 10:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub killcfg()
|
|
|
|
{
|
2017-03-29 14:31:32 +00:00
|
|
|
unlink $_ for (glob("*.log"));
|
2005-12-22 18:06:25 +00:00
|
|
|
unlink ".mbsyncrc";
|
2006-02-02 10:25:07 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 22:16:01 +00:00
|
|
|
# $run_async, $mbsync_options, $log_file
|
2020-12-18 13:31:16 +00:00
|
|
|
# Return: $exit_code, \@mbsync_output
|
2020-12-14 22:16:01 +00:00
|
|
|
sub runsync($$$)
|
2006-02-02 10:25:07 +00:00
|
|
|
{
|
2020-12-14 22:16:01 +00:00
|
|
|
my ($async, $flags, $file) = @_;
|
2017-03-29 14:31:32 +00:00
|
|
|
|
2017-03-26 19:06:11 +00:00
|
|
|
my $cmd;
|
|
|
|
if ($use_vg) {
|
|
|
|
$cmd = "valgrind -q --error-exitcode=1 ";
|
2022-04-04 19:51:16 +00:00
|
|
|
} elsif ($use_st) {
|
|
|
|
$cmd = "strace ";
|
2017-03-26 19:06:11 +00:00
|
|
|
} else {
|
|
|
|
$flags .= " -D";
|
|
|
|
}
|
2022-06-01 11:54:48 +00:00
|
|
|
if ($async == 2) {
|
|
|
|
$flags .= " -TA";
|
|
|
|
} elsif ($async == 1) {
|
|
|
|
$flags .= " -Ta";
|
|
|
|
}
|
2020-12-16 12:49:27 +00:00
|
|
|
$cmd .= "$mbsync -Tz $flags -c .mbsyncrc test";
|
2017-03-26 19:06:11 +00:00
|
|
|
open FILE, "$cmd 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");
|
2017-03-29 14:31:32 +00:00
|
|
|
if ($file) {
|
|
|
|
open FILE, ">$file" or die("Cannot create $file: $!\n");
|
|
|
|
print FILE @out;
|
|
|
|
close FILE;
|
|
|
|
}
|
2020-12-18 13:31:16 +00:00
|
|
|
return $?, \@out;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-02 10:25:07 +00:00
|
|
|
|
2022-02-07 14:44:38 +00:00
|
|
|
use constant CHOMP => 1;
|
|
|
|
|
|
|
|
sub readfile($;$)
|
|
|
|
{
|
|
|
|
my ($file, $chomp) = @_;
|
|
|
|
|
|
|
|
open(FILE, $file) or return;
|
|
|
|
my @nj = <FILE>;
|
|
|
|
close FILE;
|
|
|
|
chomp(@nj) if ($chomp);
|
|
|
|
return \@nj;
|
|
|
|
}
|
|
|
|
|
2005-12-22 18:06:25 +00:00
|
|
|
# $path
|
2022-04-04 16:55:14 +00:00
|
|
|
sub readbox_impl($$)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2022-04-04 16:55:14 +00:00
|
|
|
my ($bn, $cb) = @_;
|
2005-12-22 18:06:25 +00:00
|
|
|
|
|
|
|
(-d $bn."/tmp" and -d $bn."/new" and -d $bn."/cur") or
|
|
|
|
die "Invalid mailbox '$bn'.\n";
|
|
|
|
for my $d ("cur", "new") {
|
|
|
|
opendir(DIR, $bn."/".$d) or next;
|
|
|
|
for my $f (grep(!/^\.\.?$/, readdir(DIR))) {
|
|
|
|
open(FILE, "<", $bn."/".$d."/".$f) or die "Cannot read message '$f' in '$bn'.\n";
|
2022-04-04 16:55:14 +00:00
|
|
|
my ($sz, $num, $ph) = (0);
|
2005-12-22 18:06:25 +00:00
|
|
|
while (<FILE>) {
|
2022-01-24 20:49:18 +00:00
|
|
|
/^Subject: (\[placeholder\] )?(\d+)$/ && ($ph = defined($1), $num = int($2));
|
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;
|
|
|
|
}
|
2022-04-04 16:55:14 +00:00
|
|
|
$cb->($num, $ph, $sz, $f);
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-04 16:55:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# $path
|
|
|
|
sub readbox($)
|
|
|
|
{
|
|
|
|
my $bn = shift;
|
|
|
|
|
|
|
|
(-d $bn) or
|
|
|
|
die "No mailbox '$bn'.\n";
|
|
|
|
my %ms;
|
|
|
|
readbox_impl($bn, sub {
|
|
|
|
my ($num, $ph, $sz, $f) = @_;
|
|
|
|
if ($f !~ /^\d+\.\d+_\d+\.[-[:alnum:]]+,U=(\d+):2,(.*)$/) {
|
|
|
|
print STDERR "unrecognided file name '$f' in '$bn'.\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
my ($uid, $flg) = (int($1), $2);
|
|
|
|
@{$ms{$uid}} = ($num, $flg.($sz > 1000 ? "*" : "").($ph ? "?" : ""));
|
|
|
|
});
|
|
|
|
my $uidval = readfile($bn."/.uidvalidity", CHOMP);
|
|
|
|
die "Cannot read UID validity of mailbox '$bn': $!\n" if (!$uidval);
|
|
|
|
my $mu = $$uidval[1];
|
2022-01-23 23:33:53 +00:00
|
|
|
return { max_uid => $mu, messages => \%ms };
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 16:55:14 +00:00
|
|
|
# $path
|
|
|
|
sub readtrash($)
|
|
|
|
{
|
|
|
|
my $bn = shift;
|
|
|
|
|
|
|
|
(-d $bn) or
|
|
|
|
return {};
|
|
|
|
my %ms;
|
|
|
|
readbox_impl($bn, sub {
|
|
|
|
my ($num, $ph, undef, undef) = @_;
|
|
|
|
$ms{$num} = $ph;
|
|
|
|
});
|
|
|
|
return \%ms;
|
|
|
|
}
|
|
|
|
|
2022-01-26 20:56:50 +00:00
|
|
|
# \%fallback_sync_state
|
|
|
|
sub readstate(;$)
|
2022-01-24 00:12:49 +00:00
|
|
|
{
|
2022-01-26 20:56:50 +00:00
|
|
|
my ($fbss) = @_;
|
2022-01-24 00:12:49 +00:00
|
|
|
|
2022-01-26 20:56:50 +00:00
|
|
|
my $fn = "near/.mbsyncstate";
|
|
|
|
if ($fbss) {
|
|
|
|
$fn .= ".new";
|
|
|
|
return $fbss if (!-s $fn);
|
|
|
|
}
|
2022-01-24 00:12:49 +00:00
|
|
|
my $ls = readfile($fn, CHOMP);
|
|
|
|
if (!$ls) {
|
|
|
|
print STDERR "Cannot read sync state $fn: $!\n";
|
|
|
|
return;
|
|
|
|
}
|
2022-01-23 23:33:53 +00:00
|
|
|
my @ents;
|
|
|
|
my %ss = (
|
|
|
|
max_pulled => 0,
|
|
|
|
max_expired => 0,
|
|
|
|
max_pushed => 0,
|
|
|
|
entries => \@ents
|
|
|
|
);
|
2022-01-24 00:12:49 +00:00
|
|
|
my ($far_val, $near_val) = (0, 0);
|
|
|
|
my %hdr = (
|
|
|
|
'FarUidValidity' => \$far_val,
|
|
|
|
'NearUidValidity' => \$near_val,
|
2022-01-23 23:33:53 +00:00
|
|
|
'MaxPulledUid' => \$ss{max_pulled},
|
|
|
|
'MaxPushedUid' => \$ss{max_pushed},
|
|
|
|
'MaxExpiredFarUid' => \$ss{max_expired}
|
2022-01-24 00:12:49 +00:00
|
|
|
);
|
|
|
|
OUTER: while (1) {
|
|
|
|
while (@$ls) {
|
|
|
|
$_ = shift(@$ls);
|
|
|
|
last OUTER if (!length($_));
|
|
|
|
if (!/^([^ ]+) (\d+)$/) {
|
|
|
|
print STDERR "Malformed sync state header entry: $_\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $want = delete $hdr{$1};
|
|
|
|
if (!defined($want)) {
|
|
|
|
print STDERR "Unexpected sync state header entry: $1\n";
|
|
|
|
return;
|
|
|
|
}
|
2022-01-24 20:49:18 +00:00
|
|
|
$$want = int($2);
|
2022-01-24 00:12:49 +00:00
|
|
|
}
|
|
|
|
print STDERR "Unterminated sync state header.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
delete $hdr{'MaxExpiredFarUid'}; # optional field
|
|
|
|
my @ky = keys %hdr;
|
|
|
|
if (@ky) {
|
|
|
|
print STDERR "Keys missing from sync state header: @ky\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($far_val ne '1' or $near_val ne '1') {
|
|
|
|
print STDERR "Unexpected UID validity $far_val $near_val (instead of 1 1)\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (@$ls) {
|
|
|
|
if (!/^(\d+) (\d+) (.*)$/) {
|
|
|
|
print STDERR "Malformed sync state entry: $_\n";
|
|
|
|
return;
|
|
|
|
}
|
2022-01-24 20:49:18 +00:00
|
|
|
push @ents, [ int($1), int($2), $3 ];
|
2022-01-24 00:12:49 +00:00
|
|
|
}
|
2022-01-23 23:33:53 +00:00
|
|
|
return \%ss;
|
2022-01-24 00:12:49 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 20:56:50 +00:00
|
|
|
# \%fallback_sync_state
|
|
|
|
sub readchan(;$)
|
2022-02-06 14:43:53 +00:00
|
|
|
{
|
2022-01-26 20:56:50 +00:00
|
|
|
my ($fbss) = @_;
|
2022-02-06 14:43:53 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
far => readbox("far"),
|
|
|
|
near => readbox("near"),
|
2022-04-04 16:55:14 +00:00
|
|
|
far_trash => readtrash("far_trash"),
|
|
|
|
near_trash => readtrash("near_trash"),
|
2022-01-26 20:56:50 +00:00
|
|
|
state => readstate($fbss)
|
2022-02-06 14:43:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
# $box_name, \%box_state
|
2020-12-18 13:31:16 +00:00
|
|
|
sub mkbox($$)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2020-12-18 13:31:16 +00:00
|
|
|
my ($bn, $bs) = @_;
|
2005-12-22 18:06:25 +00:00
|
|
|
|
|
|
|
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";
|
2022-01-23 23:33:53 +00:00
|
|
|
print FILE "1\n$$bs{max_uid}\n";
|
2005-12-22 18:06:25 +00:00
|
|
|
close FILE;
|
2022-01-23 23:33:53 +00:00
|
|
|
my $ms = $$bs{messages};
|
|
|
|
for my $uid (keys %$ms) {
|
|
|
|
my ($num, $flg) = @{$$ms{$uid}};
|
2005-12-26 16:01:42 +00:00
|
|
|
my $big = $flg =~ s/\*//;
|
2019-12-29 13:37:53 +00:00
|
|
|
my $ph = $flg =~ s/\?//;
|
2020-04-03 09:21:09 +00:00
|
|
|
open(FILE, ">", $bn."/".($flg =~ /S/ ? "cur" : "new")."/0.1_".$num.".local,U=".$uid.":2,".$flg) or
|
2020-04-02 18:39:07 +00:00
|
|
|
die "Cannot create message ".mn($num)." in mailbox $bn.\n";
|
2019-12-29 13:37:53 +00:00
|
|
|
print FILE "From: foo\nTo: bar\nDate: Thu, 1 Jan 1970 00:00:00 +0000\nSubject: ".($ph?"[placeholder] ":"").$num."\n\n".(("A"x50)."\n")x($big*30);
|
2005-12-22 18:06:25 +00:00
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
# \%sync_state
|
2022-02-20 19:34:36 +00:00
|
|
|
sub mkstate($)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2022-01-23 23:33:53 +00:00
|
|
|
my ($ss) = @_;
|
2022-01-23 22:19:41 +00:00
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
open(FILE, ">", "near/.mbsyncstate") or
|
2005-12-22 18:06:25 +00:00
|
|
|
die "Cannot create sync state.\n";
|
2022-01-23 23:33:53 +00:00
|
|
|
print FILE "FarUidValidity 1\nMaxPulledUid ".$$ss{max_pulled}."\n".
|
|
|
|
"NearUidValidity 1\nMaxExpiredFarUid ".$$ss{max_expired}.
|
|
|
|
"\nMaxPushedUid ".$$ss{max_pushed}."\n\n";
|
|
|
|
for my $ent (@{$$ss{entries}}) {
|
|
|
|
print FILE $$ent[0]." ".$$ent[1]." ".$$ent[2]."\n";
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
close FILE;
|
|
|
|
}
|
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
# \%chan_state
|
2022-02-20 19:34:36 +00:00
|
|
|
sub mkchan($)
|
|
|
|
{
|
|
|
|
my ($cs) = @_;
|
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
mkbox("far", $$cs{far});
|
|
|
|
mkbox("near", $$cs{near});
|
2022-04-04 16:55:14 +00:00
|
|
|
rmtree("far_trash");
|
|
|
|
rmtree("near_trash");
|
2022-01-23 23:33:53 +00:00
|
|
|
mkstate($$cs{state});
|
2022-02-20 19:34:36 +00:00
|
|
|
}
|
|
|
|
|
2022-02-06 14:43:53 +00:00
|
|
|
# $box_name, \%actual_box_state, \%reference_box_state
|
|
|
|
sub cmpbox($$$)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2022-02-06 14:43:53 +00:00
|
|
|
my ($bn, $bs, $ref_bs) = @_;
|
2005-12-22 18:06:25 +00:00
|
|
|
|
2022-01-27 13:22:29 +00:00
|
|
|
my $ret = 0;
|
2022-01-23 23:33:53 +00:00
|
|
|
my ($ref_mu, $ref_ms) = ($$ref_bs{max_uid}, $$ref_bs{messages});
|
|
|
|
my ($mu, $ms) = ($$bs{max_uid}, $$bs{messages});
|
|
|
|
if ($mu != $ref_mu) {
|
2022-01-27 13:22:29 +00:00
|
|
|
print STDERR "MAXUID mismatch for '$bn': got $mu, wanted $ref_mu\n";
|
|
|
|
$ret = 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2022-01-23 23:33:53 +00:00
|
|
|
for my $uid (sort { $a <=> $b } keys %$ref_ms) {
|
|
|
|
my ($num, $flg) = @{$$ref_ms{$uid}};
|
2022-02-06 14:43:53 +00:00
|
|
|
my $m = $$ms{$uid};
|
2020-04-03 10:18:26 +00:00
|
|
|
if (!defined $m) {
|
2022-01-27 13:22:29 +00:00
|
|
|
print STDERR "Missing message $bn:$uid:".mn($num)."\n";
|
|
|
|
$ret = 1;
|
|
|
|
next;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2022-01-24 20:49:18 +00:00
|
|
|
if ($$m[0] != $num) {
|
2022-01-27 13:22:29 +00:00
|
|
|
print STDERR "Subject mismatch for $bn:$uid:".
|
|
|
|
" got ".mn($$m[0]).", wanted ".mn($num)."\n";
|
2005-12-27 17:31:04 +00:00
|
|
|
return 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2020-04-03 10:18:26 +00:00
|
|
|
if ($$m[1] ne $flg) {
|
2022-01-27 13:22:29 +00:00
|
|
|
print STDERR "Flag mismatch for $bn:$uid:".mn($num).":".
|
|
|
|
" got ".mf($$m[1]).", wanted ".mf($flg)."\n";
|
|
|
|
$ret = 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2005-12-26 15:58:12 +00:00
|
|
|
}
|
2022-02-06 14:43:53 +00:00
|
|
|
for my $uid (sort { $a <=> $b } keys %$ms) {
|
|
|
|
if (!defined($$ref_ms{$uid})) {
|
|
|
|
print STDERR "Excess message $bn:$uid:".mn($$ms{$uid}[0])."\n";
|
2022-01-27 13:22:29 +00:00
|
|
|
$ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2022-04-04 16:55:14 +00:00
|
|
|
# $box_name, \%actual_box_state, \%reference_box_state
|
|
|
|
sub cmptrash($$$)
|
|
|
|
{
|
|
|
|
my ($bn, $ms, $ref_ms) = @_;
|
|
|
|
|
|
|
|
my $ret = 0;
|
|
|
|
for my $num (sort { $a <=> $b } keys %$ref_ms) {
|
|
|
|
my $ph = $$ms{$num};
|
|
|
|
if (!defined($ph)) {
|
|
|
|
print STDERR "Missing message $bn:".mn($num)."\n";
|
|
|
|
$ret = 1;
|
|
|
|
}
|
2022-04-04 19:41:18 +00:00
|
|
|
if ($ph) {
|
|
|
|
print STDERR "Message $bn:".mn($num)." is placeholder\n";
|
|
|
|
$ret = 1;
|
|
|
|
}
|
2022-04-04 16:55:14 +00:00
|
|
|
}
|
|
|
|
for my $num (sort { $a <=> $b } keys %$ms) {
|
|
|
|
if (!defined($$ref_ms{$num})) {
|
2022-04-04 19:41:18 +00:00
|
|
|
print STDERR "Excess message $bn:".mn($num).($$ms{$num} ? " (is placeholder)" : "")."\n";
|
2022-04-04 16:55:14 +00:00
|
|
|
$ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2022-01-27 13:22:29 +00:00
|
|
|
sub mapmsg($$)
|
|
|
|
{
|
|
|
|
my ($uid, $bs) = @_;
|
|
|
|
|
|
|
|
if ($uid) {
|
|
|
|
if (my $msg = $$bs{messages}{$uid}) {
|
|
|
|
return $$msg[0];
|
2022-02-06 14:43:53 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2022-01-27 13:22:29 +00:00
|
|
|
# \%actual_chan_state, \%reference_chan_state
|
2022-02-06 14:43:53 +00:00
|
|
|
sub cmpstate($$)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2022-01-27 13:22:29 +00:00
|
|
|
my ($cs, $ref_cs) = @_;
|
2022-01-24 00:12:49 +00:00
|
|
|
|
2022-01-27 13:22:29 +00:00
|
|
|
my ($ss, $fbs, $nbs) = ($$cs{state}, $$cs{far}, $$cs{near});
|
2022-01-24 00:12:49 +00:00
|
|
|
return 1 if (!$ss);
|
2022-01-27 13:22:29 +00:00
|
|
|
my ($ref_ss, $ref_fbs, $ref_nbs) = ($$ref_cs{state}, $$ref_cs{far}, $$ref_cs{near});
|
2022-01-26 20:56:50 +00:00
|
|
|
return 0 if ($ss == $ref_ss);
|
2022-01-27 13:22:29 +00:00
|
|
|
my $ret = 0;
|
2022-01-23 23:33:53 +00:00
|
|
|
for my $h (['MaxPulledUid', 'max_pulled'],
|
|
|
|
['MaxExpiredFarUid', 'max_expired'],
|
|
|
|
['MaxPushedUid', 'max_pushed']) {
|
|
|
|
my ($hn, $sn) = @$h;
|
|
|
|
my ($got, $want) = ($$ss{$sn}, $$ref_ss{$sn});
|
2022-01-24 20:49:18 +00:00
|
|
|
if ($got != $want) {
|
2022-01-23 23:33:53 +00:00
|
|
|
print STDERR "Sync state header entry $hn mismatch: got $got, wanted $want\n";
|
2022-01-27 13:22:29 +00:00
|
|
|
$ret = 1;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2013-11-16 12:25:31 +00:00
|
|
|
}
|
2022-01-23 23:33:53 +00:00
|
|
|
my $ref_ents = $$ref_ss{entries};
|
|
|
|
my $ents = $$ss{entries};
|
2022-01-27 13:22:29 +00:00
|
|
|
for (my $i = 0; $i < @$ents || $i < @$ref_ents; $i++) {
|
|
|
|
my ($ent, $fuid, $nuid, $num);
|
|
|
|
if ($i < @$ents) {
|
|
|
|
$ent = $$ents[$i];
|
|
|
|
($fuid, $nuid) = ($$ent[0], $$ent[1]);
|
|
|
|
my ($fnum, $nnum) = (mapmsg($fuid, $fbs), mapmsg($nuid, $nbs));
|
|
|
|
if ($fnum && $nnum && $fnum != $nnum) {
|
|
|
|
print STDERR "Invalid sync state entry $fuid:$nuid:".
|
|
|
|
" mismatched subjects (".mn($fnum).":".mn($nnum).")\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
$num = $fnum || $nnum;
|
|
|
|
}
|
2022-01-23 23:33:53 +00:00
|
|
|
if ($i == @$ref_ents) {
|
2022-01-27 13:22:29 +00:00
|
|
|
print STDERR "Excess sync state entry $fuid:$nuid (".mn($num).")\n";
|
2013-11-16 12:41:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2022-01-23 23:33:53 +00:00
|
|
|
my $rent = $$ref_ents[$i];
|
2022-01-27 13:22:29 +00:00
|
|
|
my ($rfuid, $rnuid) = ($$rent[0], $$rent[1]);
|
|
|
|
my $rnum = mapmsg($rfuid, $ref_fbs) || mapmsg($rnuid, $ref_nbs);
|
|
|
|
if ($i == @$ents) {
|
|
|
|
print STDERR "Missing sync state entry $rfuid:$rnuid (".mn($rnum).")\n";
|
2013-11-16 12:25:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2022-01-27 13:22:29 +00:00
|
|
|
if ($fuid != $rfuid || $nuid != $rnuid || $num != $rnum) {
|
|
|
|
print STDERR "Unexpected sync state entry:".
|
|
|
|
" got $fuid:$nuid (".mn($num)."), wanted $rfuid:$rnuid (".mn($rnum).")\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ($$ent[2] ne $$rent[2]) {
|
|
|
|
print STDERR "Flag mismatch in sync state entry $fuid:$nuid (".mn($rnum)."):".
|
|
|
|
" got ".mf($$ent[2]).", wanted ".mf($$rent[2])."\n";
|
|
|
|
$ret = 1;
|
|
|
|
}
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2022-01-27 13:22:29 +00:00
|
|
|
return $ret;
|
2006-02-02 10:25:07 +00:00
|
|
|
}
|
|
|
|
|
2022-02-06 14:43:53 +00:00
|
|
|
# \%actual_chan_state, \%reference_chan_state
|
|
|
|
sub cmpchan($$)
|
2006-02-02 10:25:07 +00:00
|
|
|
{
|
2022-02-06 14:43:53 +00:00
|
|
|
my ($cs, $ref_cs) = @_;
|
|
|
|
|
|
|
|
my $rslt = 0;
|
|
|
|
$rslt |= cmpbox("far", $$cs{far}, $$ref_cs{far});
|
|
|
|
$rslt |= cmpbox("near", $$cs{near}, $$ref_cs{near});
|
2022-04-04 16:55:14 +00:00
|
|
|
$rslt |= cmptrash("far_trash", $$cs{far_trash}, $$ref_cs{far_trash});
|
|
|
|
$rslt |= cmptrash("near_trash", $$cs{near_trash}, $$ref_cs{near_trash});
|
2022-01-27 13:22:29 +00:00
|
|
|
$rslt |= cmpstate($cs, $ref_cs);
|
2005-12-27 17:31:04 +00:00
|
|
|
return $rslt;
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
# \%box_state
|
2020-12-18 13:33:26 +00:00
|
|
|
sub printbox($)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2020-12-18 13:33:26 +00:00
|
|
|
my ($bs) = @_;
|
2005-12-22 18:06:25 +00:00
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
my ($mu, $ms) = ($$bs{max_uid}, $$bs{messages});
|
|
|
|
print " [ $mu,\n ";
|
2005-12-22 18:06:25 +00:00
|
|
|
my $frst = 1;
|
2022-01-23 23:33:53 +00:00
|
|
|
for my $uid (sort { $a <=> $b } keys %$ms) {
|
|
|
|
my ($num, $flg) = @{$$ms{$uid}};
|
2005-12-22 18:06:25 +00:00
|
|
|
if ($frst) {
|
|
|
|
$frst = 0;
|
|
|
|
} else {
|
|
|
|
print ", ";
|
|
|
|
}
|
2022-01-23 23:33:53 +00:00
|
|
|
print mn($num).", ".$uid.", \"".$flg."\"";
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
print " ],\n";
|
|
|
|
}
|
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
# \%sync_state
|
2020-12-18 13:31:16 +00:00
|
|
|
sub printstate($)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2022-01-23 23:33:53 +00:00
|
|
|
my ($ss) = @_;
|
2005-12-27 17:31:04 +00:00
|
|
|
|
2022-02-06 14:43:53 +00:00
|
|
|
return if (!$ss);
|
2022-01-23 23:33:53 +00:00
|
|
|
print " [ ".$$ss{max_pulled}.", ".$$ss{max_expired}.", ".$$ss{max_pushed}.",\n ";
|
2005-12-22 18:06:25 +00:00
|
|
|
my $frst = 1;
|
2022-01-23 23:33:53 +00:00
|
|
|
for my $ent (@{$$ss{entries}}) {
|
2005-12-22 18:06:25 +00:00
|
|
|
if ($frst) {
|
|
|
|
$frst = 0;
|
|
|
|
} else {
|
|
|
|
print ", ";
|
|
|
|
}
|
2022-01-23 23:33:53 +00:00
|
|
|
print(($$ent[0] // "??").", ".($$ent[1] // "??").", \"".($$ent[2] // "??")."\"");
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
|
|
|
print " ],\n";
|
|
|
|
}
|
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
# \%chan_state
|
2013-11-09 12:06:39 +00:00
|
|
|
sub printchan($)
|
2006-02-02 10:25:07 +00:00
|
|
|
{
|
2013-11-09 12:06:39 +00:00
|
|
|
my ($cs) = @_;
|
2006-02-02 10:25:07 +00:00
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
printbox($$cs{far});
|
|
|
|
printbox($$cs{near});
|
|
|
|
printstate($$cs{state});
|
2006-02-02 10:25:07 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
# $run_async, \%source_state, \%target_state, \@channel_configs
|
2020-12-18 13:31:16 +00:00
|
|
|
sub test_impl($$$$)
|
2005-12-22 18:06:25 +00:00
|
|
|
{
|
2020-12-18 13:31:16 +00:00
|
|
|
my ($async, $sx, $tx, $sfx) = @_;
|
2013-11-04 08:54:39 +00:00
|
|
|
|
2022-01-23 22:19:41 +00:00
|
|
|
mkchan($sx);
|
2017-03-19 10:53:16 +00:00
|
|
|
|
2020-12-18 13:31:16 +00:00
|
|
|
my ($xc, $ret) = runsync($async, "-Tj", "1-initial.log");
|
2022-01-26 20:56:50 +00:00
|
|
|
my $rtx = readchan($$sx{state}) if (!$xc);
|
2022-02-06 14:43:53 +00:00
|
|
|
if ($xc || cmpchan($rtx, $tx)) {
|
2006-12-09 10:38:11 +00:00
|
|
|
print "Input:\n";
|
2013-11-09 12:06:39 +00:00
|
|
|
printchan($sx);
|
2006-12-09 10:38:11 +00:00
|
|
|
print "Options:\n";
|
2020-12-18 13:31:16 +00:00
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @$sfx))." ]\n";
|
2017-03-14 13:52:22 +00:00
|
|
|
if (!$xc) {
|
|
|
|
print "Expected result:\n";
|
|
|
|
printchan($tx);
|
|
|
|
print "Actual result:\n";
|
2022-02-06 14:43:53 +00:00
|
|
|
printchan($rtx);
|
2017-03-14 13:52:22 +00:00
|
|
|
}
|
2006-02-02 10:25:07 +00:00
|
|
|
print "Debug output:\n";
|
2020-12-18 13:31:16 +00:00
|
|
|
print @$ret;
|
2006-02-02 10:25:07 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2013-11-04 08:54:39 +00:00
|
|
|
|
2022-01-26 20:56:50 +00:00
|
|
|
my ($nj, $njl) = (undef, 0);
|
|
|
|
if ($$rtx{state} != $$sx{state}) {
|
|
|
|
$nj = readfile("near/.mbsyncstate.journal");
|
|
|
|
$njl = (@$nj - 1) * 2;
|
|
|
|
|
|
|
|
my ($jxc, $jret) = runsync($async, "-0 --no-expunge", "2-replay.log");
|
|
|
|
my $jrcs = readstate() if (!$jxc);
|
2022-01-27 13:22:29 +00:00
|
|
|
if ($jxc || cmpstate({ far => $$tx{far}, near => $$tx{near}, state => $jrcs }, $tx)) {
|
2022-01-26 20:56:50 +00:00
|
|
|
print "Journal replay failed.\n";
|
|
|
|
print "Options:\n";
|
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @$sfx))." ], [ \"-0\", \"--no-expunge\" ]\n";
|
|
|
|
print "Old State:\n";
|
|
|
|
printstate($$sx{state});
|
|
|
|
print "Journal:\n".join("", @$nj)."\n";
|
|
|
|
if (!$jxc) {
|
|
|
|
print "Expected New State:\n";
|
|
|
|
printstate($$tx{state});
|
|
|
|
print "New State:\n";
|
|
|
|
printstate($jrcs);
|
|
|
|
}
|
|
|
|
print "Debug output:\n";
|
|
|
|
print @$jret;
|
|
|
|
exit 1;
|
2017-03-14 13:52:22 +00:00
|
|
|
}
|
2005-12-27 17:31:04 +00:00
|
|
|
}
|
2013-11-04 08:54:39 +00:00
|
|
|
|
2020-12-18 13:31:16 +00:00
|
|
|
my ($ixc, $iret) = runsync($async, "", "3-verify.log");
|
2022-01-26 20:56:50 +00:00
|
|
|
my $irtx = readchan() if (!$ixc);
|
2022-02-06 14:43:53 +00:00
|
|
|
if ($ixc || cmpchan($irtx, $tx)) {
|
2013-11-04 08:54:39 +00:00
|
|
|
print "Idempotence verification run failed.\n";
|
|
|
|
print "Input == Expected result:\n";
|
|
|
|
printchan($tx);
|
|
|
|
print "Options:\n";
|
2020-12-18 13:31:16 +00:00
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @$sfx))." ]\n";
|
2017-03-19 10:53:16 +00:00
|
|
|
if (!$ixc) {
|
2017-03-14 13:52:22 +00:00
|
|
|
print "Actual result:\n";
|
2022-02-06 14:43:53 +00:00
|
|
|
printchan($irtx);
|
2017-03-14 13:52:22 +00:00
|
|
|
}
|
2013-11-04 08:54:39 +00:00
|
|
|
print "Debug output:\n";
|
2020-12-18 13:31:16 +00:00
|
|
|
print @$iret;
|
2013-11-04 08:54:39 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
rmtree "near";
|
|
|
|
rmtree "far";
|
2022-04-04 16:55:14 +00:00
|
|
|
rmtree "near_trash";
|
|
|
|
rmtree "far_trash";
|
2017-03-19 10:53:16 +00:00
|
|
|
|
2019-11-25 19:55:41 +00:00
|
|
|
for (my $l = 1; $l <= $njl; $l++) {
|
2022-01-23 22:19:41 +00:00
|
|
|
mkchan($sx);
|
2017-03-19 10:53:16 +00:00
|
|
|
|
2022-03-01 13:58:51 +00:00
|
|
|
my ($nxc, $nret) = runsync($async, "-Ts$l", "4-interrupt.log");
|
2017-03-19 10:53:16 +00:00
|
|
|
if ($nxc != (100 + ($l & 1)) << 8) {
|
|
|
|
print "Interrupting at step $l/$njl failed.\n";
|
|
|
|
print "Debug output:\n";
|
2020-12-18 13:31:16 +00:00
|
|
|
print @$nret;
|
2017-03-19 10:53:16 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2020-12-18 13:31:16 +00:00
|
|
|
($nxc, $nret) = runsync($async, "-Tj", "5-resume.log");
|
2022-01-26 20:56:50 +00:00
|
|
|
my $nrtx = readchan($$sx{state}) if (!$nxc);
|
2022-02-06 14:43:53 +00:00
|
|
|
if ($nxc || cmpchan($nrtx, $tx)) {
|
2017-03-19 10:53:16 +00:00
|
|
|
print "Resuming from step $l/$njl failed.\n";
|
|
|
|
print "Input:\n";
|
|
|
|
printchan($sx);
|
|
|
|
print "Options:\n";
|
2020-12-18 13:31:16 +00:00
|
|
|
print " [ ".join(", ", map('"'.qm($_).'"', @$sfx))." ]\n";
|
|
|
|
my $nnj = readfile("near/.mbsyncstate.journal");
|
2019-11-25 19:55:41 +00:00
|
|
|
my $ln = int($l / 2);
|
2020-12-18 13:31:16 +00:00
|
|
|
print "Journal:\n".join("", @$nnj[0..$ln])."-------\n".join("", @$nnj[($ln + 1)..$#$nnj])."\n";
|
|
|
|
print "Full journal:\n".join("", @$nj)."\n";
|
2017-03-19 10:53:16 +00:00
|
|
|
if (!$nxc) {
|
|
|
|
print "Expected result:\n";
|
|
|
|
printchan($tx);
|
|
|
|
print "Actual result:\n";
|
2022-02-06 14:43:53 +00:00
|
|
|
printchan($nrtx);
|
2017-03-19 10:53:16 +00:00
|
|
|
}
|
|
|
|
print "Debug output:\n";
|
2020-12-18 13:31:16 +00:00
|
|
|
print @$nret;
|
2017-03-19 10:53:16 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
deprecate master/slave terminology
the underlying metaphor refers to an inhumane practice, so using it
casually is rightfully offensive to many people. it isn't even a
particularly apt metaphor, as it suggests a strict hierarchy that is
counter to mbsync's highly symmetrical mode of operation.
the far/near terminology has been chosen as the replacement, as it is a
natural fit for the push/pull terminology. on the downside, due to these
not being nouns, a few uses are a bit awkward, and several others had to
be amended to include 'side'. also, it's conceptually quite close to
remote/local, which matches the typical use case, but is maybe a bit too
suggestive of actually non-existing limitations.
the new f/n suffixes of the -C/-R/-X options clash with pre-existing
options, so direct concatenation of short options is even less practical
than before (some suffixes of -D already clashed), but doing that leads
to unreadable command lines anyway.
as with previous deprecations, all pre-existing command line and config
options keep working, but yield a warning. the state files are silently
upgraded.
2020-07-22 17:44:26 +00:00
|
|
|
rmtree "near";
|
|
|
|
rmtree "far";
|
2022-04-04 16:55:14 +00:00
|
|
|
rmtree "near_trash";
|
|
|
|
rmtree "far_trash";
|
2017-03-19 10:53:16 +00:00
|
|
|
}
|
2020-12-14 22:16:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 13:31:16 +00:00
|
|
|
# $title, \@source_state, \@target_state, \@channel_configs
|
|
|
|
sub test($$$$)
|
2020-12-14 22:16:01 +00:00
|
|
|
{
|
2022-01-23 23:33:53 +00:00
|
|
|
my ($ttl, $isx, $itx, $sfx) = @_;
|
2020-12-14 22:16:01 +00:00
|
|
|
|
2022-01-26 17:46:58 +00:00
|
|
|
if (@match) {
|
|
|
|
if ($start) {
|
|
|
|
return if (index($ttl, $match[0]) < 0);
|
|
|
|
@match = ();
|
|
|
|
} else {
|
|
|
|
return if (!grep { index($ttl, $_) >= 0 } @match);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 22:16:01 +00:00
|
|
|
print "Testing: ".$ttl." ...\n";
|
2020-12-18 13:31:16 +00:00
|
|
|
writecfg($sfx);
|
2020-12-14 22:16:01 +00:00
|
|
|
|
2022-01-23 23:33:53 +00:00
|
|
|
my $sx = parse_chan($isx);
|
2022-02-20 12:00:55 +00:00
|
|
|
my $tx = parse_chan($itx, $sx);
|
2022-01-23 23:33:53 +00:00
|
|
|
|
2020-12-18 13:31:16 +00:00
|
|
|
test_impl(0, $sx, $tx, $sfx);
|
|
|
|
test_impl(1, $sx, $tx, $sfx);
|
2022-06-01 11:54:48 +00:00
|
|
|
test_impl(2, $sx, $tx, $sfx);
|
2017-03-19 10:53:16 +00:00
|
|
|
|
|
|
|
killcfg();
|
2005-12-22 18:06:25 +00:00
|
|
|
}
|
2022-02-20 12:00:55 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Format of the test defs:
|
|
|
|
# ( max_pulled, max_expired, max_pushed, { subject, far, state, near }... )
|
|
|
|
# Everything is a delta; for the input, the reference is the empty state.
|
|
|
|
# Common commands:
|
|
|
|
# *f => create with flags, appending at end of list
|
|
|
|
# / => destroy
|
|
|
|
# -f, +f => remove/add flags
|
|
|
|
# Far/near:
|
|
|
|
# Special commands:
|
|
|
|
# _ => create phantom message (reserve UID for expunged message)
|
|
|
|
# ^f => create with flags, duplicating the subject
|
2022-04-04 16:55:14 +00:00
|
|
|
# # => create in trash; deletion may follow
|
2022-02-20 12:00:55 +00:00
|
|
|
# | => use zero UID for state modification, even if msg exists; cmd may follow
|
|
|
|
# & => use zero UID for state identification, even if message exists
|
|
|
|
# &n => use UID of n'th occurence of subject for state id; command may follow
|
|
|
|
# Special flag suffixes:
|
|
|
|
# * => big
|
|
|
|
# ? => placeholder
|
|
|
|
# State:
|
|
|
|
# Special commands:
|
|
|
|
# <, > => update far/near message link; flag updates may follow
|
|
|
|
# ^f => create with flags, appending right after last command's entry
|
|
|
|
# Special flag prefixes as in actual state file.
|
|
|
|
|
|
|
|
# Generic syncing tests
|
|
|
|
|
|
|
|
my @x01 = (
|
|
|
|
I, 0, 0,
|
|
|
|
A, "*F", "*", "*",
|
|
|
|
B, "*", "*", "*F",
|
|
|
|
C, "*FS", "*", "*F",
|
|
|
|
D, "*", "*", "*",
|
|
|
|
E, "*T", "*", "*",
|
|
|
|
G, "*F", "*", "_",
|
|
|
|
H, "*FT", "*", "*",
|
|
|
|
I, "_", "*", "*",
|
|
|
|
K, "*", "", "",
|
|
|
|
M, "", "", "*",
|
|
|
|
);
|
|
|
|
|
|
|
|
my @O01 = ("", "", "");
|
|
|
|
my @X01 = (
|
|
|
|
M, 0, K,
|
|
|
|
A, "", "+F", "+F",
|
|
|
|
B, "+F", "+F", "",
|
|
|
|
C, "", "+FS", "+S",
|
|
|
|
E, "", "+T", "+T",
|
|
|
|
G, "+T", ">", "",
|
|
|
|
H, "", "+FT", "+FT",
|
|
|
|
I, "", "<", "+T",
|
|
|
|
M, "*", "*", "",
|
|
|
|
K, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("full", \@x01, \@X01, \@O01);
|
|
|
|
|
|
|
|
my @O02 = ("", "", "Expunge Both\n");
|
|
|
|
my @X02 = (
|
|
|
|
M, 0, K,
|
|
|
|
A, "", "+F", "+F",
|
|
|
|
B, "+F", "+F", "",
|
|
|
|
C, "", "+FS", "+S",
|
|
|
|
E, "/", "/", "/",
|
|
|
|
G, "/", "/", "",
|
|
|
|
H, "/", "/", "/",
|
|
|
|
I, "", "/", "/",
|
|
|
|
M, "*", "*", "",
|
|
|
|
K, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("full + expunge both", \@x01, \@X02, \@O02);
|
|
|
|
|
|
|
|
my @O03 = ("", "", "Expunge Near\n");
|
|
|
|
my @X03 = (
|
|
|
|
M, 0, K,
|
|
|
|
A, "", "+F", "+F",
|
|
|
|
B, "+F", "+F", "",
|
|
|
|
C, "", "+FS", "+S",
|
|
|
|
E, "", ">+T", "/",
|
|
|
|
G, "+T", ">", "",
|
|
|
|
H, "", ">+T", "/",
|
|
|
|
I, "", "/", "/",
|
|
|
|
M, "*", "*", "",
|
|
|
|
K, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("full + expunge near side", \@x01, \@X03, \@O03);
|
|
|
|
|
|
|
|
my @O04 = ("", "", "Sync Pull\n");
|
|
|
|
my @X04 = (
|
|
|
|
K, 0, 0,
|
|
|
|
A, "", "+F", "+F",
|
|
|
|
C, "", "+FS", "+S",
|
|
|
|
E, "", "+T", "+T",
|
|
|
|
H, "", "+FT", "+FT",
|
|
|
|
I, "", "<", "+T",
|
|
|
|
K, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("pull", \@x01, \@X04, \@O04);
|
|
|
|
|
|
|
|
my @O05 = ("", "", "Sync Flags\n");
|
|
|
|
my @X05 = (
|
|
|
|
I, 0, 0,
|
|
|
|
A, "", "+F", "+F",
|
|
|
|
B, "+F", "+F", "",
|
|
|
|
C, "", "+FS", "+S",
|
|
|
|
E, "", "+T", "+T",
|
|
|
|
H, "", "+FT", "+FT",
|
|
|
|
);
|
|
|
|
test("flags", \@x01, \@X05, \@O05);
|
|
|
|
|
|
|
|
my @O06 = ("", "", "Sync Delete\n");
|
|
|
|
my @X06 = (
|
|
|
|
I, 0, 0,
|
|
|
|
G, "+T", ">", "",
|
|
|
|
I, "", "<", "+T",
|
|
|
|
);
|
|
|
|
test("deletions", \@x01, \@X06, \@O06);
|
|
|
|
|
|
|
|
my @O07 = ("", "", "Sync New\n");
|
|
|
|
my @X07 = (
|
|
|
|
M, 0, K,
|
|
|
|
M, "*", "*", "",
|
|
|
|
K, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("new", \@x01, \@X07, \@O07);
|
|
|
|
|
|
|
|
my @O08 = ("", "", "Sync PushFlags PullDelete\n");
|
|
|
|
my @X08 = (
|
|
|
|
I, 0, 0,
|
|
|
|
B, "+F", "+F", "",
|
|
|
|
C, "", "+F", "",
|
|
|
|
I, "", "<", "+T",
|
|
|
|
);
|
|
|
|
test("push flags + pull deletions", \@x01, \@X08, \@O08);
|
|
|
|
|
|
|
|
# Size restriction tests
|
|
|
|
|
|
|
|
my @x20 = (
|
|
|
|
0, 0, 0,
|
|
|
|
A, "*", "", "",
|
|
|
|
B, "**", "", "",
|
|
|
|
C, "", "", "**",
|
|
|
|
);
|
|
|
|
|
|
|
|
my @O21 = ("MaxSize 1k\n", "MaxSize 1k\n", "Expunge Near");
|
|
|
|
my @X21 = (
|
|
|
|
C, 0, B,
|
|
|
|
C, "*?", "*<", "",
|
|
|
|
A, "", "*", "*",
|
|
|
|
B, "", "*>", "*?",
|
|
|
|
);
|
|
|
|
test("max size", \@x20, \@X21, \@O21);
|
|
|
|
|
|
|
|
my @x22 = (
|
|
|
|
C, 0, B,
|
|
|
|
A, "*", "", "",
|
|
|
|
B, "**", "", "",
|
|
|
|
C, "*?", "*<", "*F*",
|
|
|
|
A, "", "*", "*",
|
|
|
|
B, "", "*>", "*F?",
|
|
|
|
);
|
|
|
|
|
|
|
|
my @X22 = (
|
|
|
|
C, 0, B,
|
|
|
|
B, "", ">->", "^*",
|
|
|
|
B, "", "", "&1/",
|
|
|
|
C, "^F*", "<-<+F", "",
|
2022-04-04 19:41:18 +00:00
|
|
|
C, "&1+T", "^", "&",
|
2022-02-20 12:00:55 +00:00
|
|
|
);
|
|
|
|
test("max size + flagging", \@x22, \@X22, \@O21);
|
|
|
|
|
|
|
|
my @x23 = (
|
|
|
|
0, 0, 0,
|
|
|
|
A, "*", "", "",
|
|
|
|
B, "*F*", "", "",
|
|
|
|
C, "", "", "*F*",
|
|
|
|
);
|
|
|
|
|
|
|
|
my @X23 = (
|
|
|
|
C, 0, B,
|
|
|
|
C, "*F*", "*F", "",
|
|
|
|
A, "", "*", "*",
|
|
|
|
B, "", "*F", "*F*",
|
|
|
|
);
|
|
|
|
test("max size + initial flagging", \@x23, \@X23, \@O21);
|
|
|
|
|
|
|
|
my @x24 = (
|
|
|
|
C, 0, A,
|
|
|
|
A, "*", "*", "*",
|
|
|
|
B, "**", "*^", "",
|
|
|
|
C, "*F*", "*^", "",
|
|
|
|
);
|
|
|
|
|
|
|
|
my @X24 = (
|
|
|
|
C, 0, C,
|
|
|
|
B, "", ">-^+>", "*?",
|
|
|
|
C, "", ">-^+F", "*F*",
|
|
|
|
);
|
|
|
|
test("max size (pre-1.4 legacy)", \@x24, \@X24, \@O21);
|
|
|
|
|
|
|
|
# Expiration tests
|
|
|
|
|
|
|
|
my @x30 = (
|
|
|
|
0, 0, 0,
|
|
|
|
A, "*F", "", "",
|
|
|
|
B, "*", "", "",
|
|
|
|
C, "*S", "", "",
|
|
|
|
D, "*", "", "",
|
|
|
|
E, "*S", "", "",
|
|
|
|
F, "*", "", "",
|
|
|
|
);
|
|
|
|
|
|
|
|
my @O31 = ("", "", "MaxMessages 3\n");
|
|
|
|
my @X31 = (
|
|
|
|
F, C, F,
|
|
|
|
A, "", "*F", "*F",
|
|
|
|
B, "", "*", "*",
|
|
|
|
D, "", "*", "*",
|
|
|
|
E, "", "*S", "*S",
|
|
|
|
F, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("max messages", \@x30, \@X31, \@O31);
|
|
|
|
|
|
|
|
my @O32 = ("", "", "MaxMessages 3\nExpireUnread yes\n");
|
|
|
|
my @X32 = (
|
|
|
|
F, C, F,
|
|
|
|
A, "", "*F", "*F",
|
|
|
|
D, "", "*", "*",
|
|
|
|
E, "", "*S", "*S",
|
|
|
|
F, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("max messages vs. unread", \@x30, \@X32, \@O32);
|
|
|
|
|
|
|
|
my @x38 = (
|
|
|
|
F, C, 0,
|
|
|
|
A, "*FS", "*FS", "*S",
|
|
|
|
B, "*FS", "*~S", "*ST",
|
|
|
|
C, "*S", "*~S", "_",
|
|
|
|
D, "*", "*", "*",
|
|
|
|
E, "*", "*", "*",
|
|
|
|
F, "*", "*", "*",
|
|
|
|
);
|
|
|
|
|
|
|
|
my @O38 = ("", "", "MaxMessages 3\nExpunge Both\n");
|
|
|
|
my @X38 = (
|
|
|
|
F, C, F,
|
|
|
|
A, "-F", "/", "/",
|
|
|
|
B, "", "-~+F", "-T+F",
|
|
|
|
C, "", "/", "",
|
|
|
|
);
|
|
|
|
test("max messages + expunge", \@x38, \@X38, \@O38);
|
|
|
|
|
2022-04-04 16:55:14 +00:00
|
|
|
# Trashing
|
|
|
|
|
|
|
|
my @x10 = (
|
2022-04-04 19:41:18 +00:00
|
|
|
K, A, K,
|
2022-04-04 16:55:14 +00:00
|
|
|
A, "*", "*~", "*T",
|
|
|
|
B, "*T", "*^", "",
|
|
|
|
C, "*T", "*", "*T",
|
|
|
|
D, "_", "*", "*",
|
|
|
|
E, "*", "*", "_",
|
2022-04-04 19:41:18 +00:00
|
|
|
F, "**", "*>", "*T?",
|
|
|
|
G, "*T?", "*<", "**",
|
|
|
|
J, "**", "*>", "*F?",
|
|
|
|
K, "*F?", "*<", "**",
|
2022-04-04 16:55:14 +00:00
|
|
|
L, "*T", "", "",
|
|
|
|
M, "", "", "*T",
|
|
|
|
R, "", "", "*", # Force maxuid in the interrupt-resume test.
|
|
|
|
S, "*", "", "",
|
|
|
|
);
|
|
|
|
|
|
|
|
my @O11 = ("Trash far_trash\n", "Trash near_trash\n",
|
|
|
|
"MaxMessages 20\nExpireUnread yes\nMaxSize 1k\nExpunge Both\n");
|
|
|
|
my @X11 = (
|
|
|
|
R, A, S,
|
|
|
|
A, "", "/", "/",
|
|
|
|
B, "#/", "/", "",
|
|
|
|
C, "#/", "/", "#/",
|
|
|
|
D, "", "/", "#/",
|
|
|
|
E, "#/", "/", "",
|
2022-04-04 19:41:18 +00:00
|
|
|
F, "#/", "/", "/",
|
|
|
|
G, "/", "/", "#/",
|
|
|
|
J, "", ">->", "^*",
|
|
|
|
J, "", "", "&1/",
|
|
|
|
K, "^*", "<-<", "",
|
|
|
|
K, "&1/", "", "",
|
2022-04-04 16:55:14 +00:00
|
|
|
L, "#/", "", "",
|
|
|
|
M, "", "", "#/",
|
|
|
|
R, "*", "*", "",
|
|
|
|
S, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("trash", \@x10, \@X11, \@O11);
|
|
|
|
|
|
|
|
my @O12 = ("Trash far_trash\n", "Trash near_trash\nTrashNewOnly true\n",
|
|
|
|
"MaxMessages 20\nExpireUnread yes\nMaxSize 1k\nExpunge Both\n");
|
|
|
|
my @X12 = (
|
|
|
|
R, A, S,
|
|
|
|
A, "", "/", "/",
|
|
|
|
B, "#/", "/", "",
|
|
|
|
C, "#/", "/", "/",
|
|
|
|
D, "", "/", "/",
|
|
|
|
E, "#/", "/", "",
|
2022-04-04 19:41:18 +00:00
|
|
|
F, "#/", "/", "/",
|
|
|
|
G, "/", "/", "#/",
|
|
|
|
J, "", ">->", "^*",
|
|
|
|
J, "", "", "&1/",
|
|
|
|
K, "^*", "<-<", "",
|
|
|
|
K, "&1/", "", "",
|
2022-04-04 16:55:14 +00:00
|
|
|
L, "#/", "", "",
|
|
|
|
M, "", "", "#/",
|
|
|
|
R, "*", "*", "",
|
|
|
|
S, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("trash only new", \@x10, \@X12, \@O12);
|
|
|
|
|
|
|
|
my @O13 = ("Trash far_trash\nTrashRemoteNew true\n", "",
|
|
|
|
"MaxMessages 20\nExpireUnread yes\nMaxSize 1k\nExpunge Both\n");
|
|
|
|
my @X13 = (
|
|
|
|
R, A, S,
|
|
|
|
A, "", "/", "/",
|
|
|
|
B, "#/", "/", "",
|
|
|
|
C, "#/", "/", "/",
|
|
|
|
D, "", "/", "/",
|
|
|
|
E, "#/", "/", "",
|
2022-04-04 19:41:18 +00:00
|
|
|
F, "#/", "/", "/",
|
|
|
|
G, "#/", "/", "/",
|
|
|
|
J, "", ">->", "^*",
|
|
|
|
J, "", "", "&1/",
|
|
|
|
K, "^*", "<-<", "",
|
|
|
|
K, "&1/", "", "",
|
2022-04-04 16:55:14 +00:00
|
|
|
L, "#/", "", "",
|
|
|
|
M, "#", "", "/",
|
|
|
|
R, "*", "*", "",
|
|
|
|
S, "", "*", "*",
|
|
|
|
);
|
|
|
|
test("trash new remotely", \@x10, \@X13, \@O13);
|
|
|
|
|
2022-02-20 12:00:55 +00:00
|
|
|
print "OK.\n";
|