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 require_mods(qw(DBD::SQLite Email::Address::XS||Mail::Address));
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');
38 my ($host, $port) = ($sock->sockhost, $sock->sockport);
42 mkpath([map { "$tmpdir/oimapdir/$_" } qw(cur new tmp)]);
43 my $oimap = which('offlineimap') or skip 'no offlineimap(1)', 1;
44 open my $fh, '>', "$tmpdir/.offlineimaprc" or BAIL_OUT "open: $!";
45 print $fh <<EOF or BAIL_OUT "print: $!";
52 localrepository = l.test
53 remoterepository = r.test
57 localfolders = ~/oimapdir
64 remoteuser = anonymous
67 # python-imaplib2 times out on select/poll when compression is enabled
68 # <https://bugs.debian.org/961713>
71 close $fh or BAIL_OUT "close: $!";
72 my $cmd = [ $oimap, qw(-o -q -u quiet) ];
73 my $pid = spawn($cmd, { HOME => $tmpdir }, { 1 => 2 });
78 mkpath([map { "$tmpdir/mbsyncdir/test/$_" } qw(cur new tmp)]);
79 my $mbsync = which('mbsync') or skip 'no mbsync(1)', 1;
80 open my $fh, '>', "$tmpdir/.mbsyncrc" or BAIL_OUT "open: $!";
81 print $fh <<EOF or BAIL_OUT "print: $!";
89 Inbox ~/mbsyncdir/test
99 # DisableExtension COMPRESS=DEFLATE
102 Master ":remote:INBOX"
108 close $fh or BAIL_OUT "close: $!";
109 my $cmd = [ $mbsync, qw(-aqq) ];
110 my $pid = spawn($cmd, { HOME => $tmpdir }, { 1 => 2 });
114 while (scalar keys %pids) {
115 my $pid = waitpid(-1, 0) or next;
116 my $cmd = delete $pids{$pid} or next;
117 is($?, 0, join(' ', @$cmd, 'done'));
120 my $sec = $ENV{TEST_PERSIST} // 0;
121 diag "TEST_PERSIST=$sec";
123 diag "sleeping ${sec}s, imap://$host:$port/$mailbox available";
124 diag "tmpdir=$tmpdir (Maildirs available)";
127 diag "pid=$td->{pid}";
132 is($?, 0, 'no error on -imapd exit');