2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # ensure mbsync and offlineimap compatibility
7 use File::Path qw(mkpath);
8 use PublicInbox::TestCommon;
9 use PublicInbox::Spawn qw(which spawn);
10 my $inboxdir = $ENV{GIANT_INBOX_DIR};
11 (defined($inboxdir) && -d $inboxdir) or
12 plan skip_all => "GIANT_INBOX_DIR not defined for $0";
13 plan skip_all => "bad characters in $inboxdir" if $inboxdir =~ m![^\w\.\-/]!;
14 my ($tmpdir, $for_destroy) = tmpdir();
15 my $cfg = "$tmpdir/cfg";
16 my $mailbox = 'inbox.test';
18 open my $fh, '>', $cfg or BAIL_OUT "open: $!";
19 print $fh <<EOF or BAIL_OUT "print: $!";
22 address = oimap\@example.com
25 close $fh or BAIL_OUT "close: $!";
27 my ($out, $err) = ("$tmpdir/stdout.log", "$tmpdir/stderr.log");
28 my $sock = tcp_server();
29 my $cmd = [ '-imapd', '-W0', "--stdout=$out", "--stderr=$err" ];
30 my $env = { PI_CONFIG => $cfg };
31 my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT "-imapd: $?";
33 my $c = tcp_connect($sock);
34 like(readline($c), qr/CAPABILITY /, 'got greeting');
36 my ($host, $port) = ($sock->sockhost, $sock->sockport);
40 mkpath([map { "$tmpdir/oimapdir/$_" } qw(cur new tmp)]);
41 my $oimap = which('offlineimap') or skip 'no offlineimap(1)', 1;
42 open my $fh, '>', "$tmpdir/.offlineimaprc" or BAIL_OUT "open: $!";
43 print $fh <<EOF or BAIL_OUT "print: $!";
50 localrepository = l.test
51 remoterepository = r.test
55 localfolders = ~/oimapdir
62 remoteuser = anonymous
65 # python-imaplib2 times out on select/poll when compression is enabled
66 # <https://bugs.debian.org/961713>
69 close $fh or BAIL_OUT "close: $!";
70 my $cmd = [ $oimap, qw(-o -q -u quiet) ];
71 my $pid = spawn($cmd, { HOME => $tmpdir }, { 1 => 2 });
76 mkpath([map { "$tmpdir/mbsyncdir/test/$_" } qw(cur new tmp)]);
77 my $mbsync = which('mbsync') or skip 'no mbsync(1)', 1;
78 open my $fh, '>', "$tmpdir/.mbsyncrc" or BAIL_OUT "open: $!";
79 print $fh <<EOF or BAIL_OUT "print: $!";
87 Inbox ~/mbsyncdir/test
97 # DisableExtension COMPRESS=DEFLATE
100 Master ":remote:inbox"
106 close $fh or BAIL_OUT "close: $!";
107 my $cmd = [ $mbsync, qw(-aqq) ];
108 my $pid = spawn($cmd, { HOME => $tmpdir }, { 1 => 2 });
112 while (scalar keys %pids) {
113 my $pid = waitpid(-1, 0) or next;
114 my $cmd = delete $pids{$pid} or next;
115 is($?, 0, join(' ', @$cmd, 'done'));
118 if (my $sec = $ENV{TEST_PERSIST}) {
119 diag "sleeping ${sec}s, imap://$host:$port/$mailbox available";
120 diag "tmpdir=$tmpdir (Maildirs available)";
123 diag "pid=$td->{pid}";
128 is($?, 0, 'no error on -imapd exit');