2 # Copyright (C) 2020-2021 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 require_mods(qw(-imapd));
11 my $inboxdir = $ENV{GIANT_INBOX_DIR};
12 (defined($inboxdir) && -d $inboxdir) or
13 plan skip_all => "GIANT_INBOX_DIR not defined for $0";
14 plan skip_all => "bad characters in $inboxdir" if $inboxdir =~ m![^\w\.\-/]!;
15 my ($tmpdir, $for_destroy) = tmpdir();
16 my $cfg = "$tmpdir/cfg";
17 my $newsgroup = 'inbox.test';
18 my $mailbox = "$newsgroup.0";
20 open my $fh, '>', $cfg or BAIL_OUT "open: $!";
21 print $fh <<EOF or BAIL_OUT "print: $!";
23 newsgroup = $newsgroup
24 address = oimap\@example.com
27 close $fh or BAIL_OUT "close: $!";
29 my ($out, $err) = ("$tmpdir/stdout.log", "$tmpdir/stderr.log");
30 my $sock = tcp_server();
31 my $cmd = [ '-imapd', '-W0', "--stdout=$out", "--stderr=$err" ];
32 my $env = { PI_CONFIG => $cfg };
33 my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT "-imapd: $?";
35 my $c = tcp_connect($sock);
36 like(readline($c), qr/CAPABILITY /, 'got greeting');
39 my $host_port = tcp_host_port($sock);
40 my ($host, $port) = ($sock->sockhost, $sock->sockport);
44 mkpath([map { "$tmpdir/oimapdir/$_" } qw(cur new tmp)]);
45 my $oimap = which('offlineimap') or skip 'no offlineimap(1)', 1;
46 open my $fh, '>', "$tmpdir/.offlineimaprc" or BAIL_OUT "open: $!";
47 print $fh <<EOF or BAIL_OUT "print: $!";
54 localrepository = l.test
55 remoterepository = r.test
59 localfolders = ~/oimapdir
66 remoteuser = anonymous
69 # python-imaplib2 times out on select/poll when compression is enabled
70 # <https://bugs.debian.org/961713>
73 close $fh or BAIL_OUT "close: $!";
74 my $cmd = [ $oimap, qw(-o -q -u quiet) ];
75 my $pid = spawn($cmd, { HOME => $tmpdir }, { 1 => 2 });
80 mkpath([map { "$tmpdir/mbsyncdir/test/$_" } qw(cur new tmp)]);
81 my $mbsync = which('mbsync') or skip 'no mbsync(1)', 1;
82 open my $fh, '>', "$tmpdir/.mbsyncrc" or BAIL_OUT "open: $!";
83 print $fh <<EOF or BAIL_OUT "print: $!";
91 Inbox ~/mbsyncdir/test
101 # DisableExtension COMPRESS=DEFLATE
104 Master ":remote:INBOX"
110 close $fh or BAIL_OUT "close: $!";
111 my $cmd = [ $mbsync, qw(-aqq) ];
112 my $pid = spawn($cmd, { HOME => $tmpdir }, { 1 => 2 });
116 while (scalar keys %pids) {
117 my $pid = waitpid(-1, 0) or next;
118 my $cmd = delete $pids{$pid} or next;
119 is($?, 0, join(' ', @$cmd, 'done'));
122 my $sec = $ENV{TEST_PERSIST} // 0;
123 diag "TEST_PERSIST=$sec";
125 diag "sleeping ${sec}s, imap://$host_port/$mailbox available";
126 diag "tmpdir=$tmpdir (Maildirs available)";
129 diag "pid=$td->{pid}";
134 is($?, 0, 'no error on -imapd exit');