2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # ensure mpop compatibility
6 use File::Path qw(make_path);
7 use PublicInbox::TestCommon;
8 use PublicInbox::Spawn qw(which spawn);
9 my $inboxdir = $ENV{GIANT_INBOX_DIR};
10 (defined($inboxdir) && -d $inboxdir) or
11 plan skip_all => "GIANT_INBOX_DIR not defined for $0";
12 plan skip_all => "bad characters in $inboxdir" if $inboxdir =~ m![^\w\.\-/]!;
13 my $uuidgen = which('uuidgen') or plan skip_all => 'uuidgen(1) missing';
14 require_mods(qw(DBD::SQLite));
15 require_git('2.6'); # for v2
16 require_mods(qw(File::FcntlLock)) if $^O !~ /\A(?:linux|freebsd)\z/;
18 my ($tmpdir, $for_destroy) = tmpdir();
19 my $cfg = "$tmpdir/cfg";
20 my $newsgroup = 'inbox.test';
23 open my $fh, '>', $cfg or xbail "open: $!";
24 print $fh <<EOF or xbail "print: $!";
26 pop3state = $tmpdir/p3s
28 newsgroup = $newsgroup
29 address = mpop-test\@example.com
32 close $fh or xbail "close: $!";
34 my ($out, $err) = ("$tmpdir/stdout.log", "$tmpdir/stderr.log");
35 my $sock = tcp_server();
36 my $cmd = [ '-pop3d', '-W0', "--stdout=$out", "--stderr=$err" ];
37 my $env = { PI_CONFIG => $cfg };
38 my $td = start_script($cmd, $env, { 3 => $sock }) or xbail "-xbail $?";
39 chomp(my $uuid = xqx([$uuidgen]));
41 make_path("$tmpdir/home/.config/mpop",
42 map { "$tmpdir/md/$_" } qw(new cur tmp));
45 my $mpop = which('mpop') or skip('mpop(1) missing', 1);
46 open my $fh, '>', "$tmpdir/home/.config/mpop/config"
49 print $fh <<EOM or xbail "print $!";
52 delivery maildir $tmpdir/md
54 host ${\$sock->sockhost}
55 port ${\$sock->sockport}
56 user $uuid\@$newsgroup
61 close $fh or xbail "close $!";
62 delete local $ENV{XDG_CONFIG_HOME}; # mpop uses this
63 local $ENV{HOME} = "$tmpdir/home";
64 my $cmd = [ $mpop, '-q' ];
65 my $pid = spawn($cmd, undef, { 1 => 2 });
69 while (scalar keys %pids) {
70 my $pid = waitpid(-1, 0) or next;
71 my $cmd = delete $pids{$pid} or next;
72 is($?, 0, join(' ', @$cmd, 'done'));
76 is($?, 0, 'no error on -pop3d exit');