public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob ff8bb5dc9d0b6abd65fa5c32e9134a0ac2663b3e 2172 bytes (raw)
$ git show HEAD:xt/pop3d-mpop.t	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
#!perl -w
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# ensure mpop compatibility
use v5.12;
use File::Path qw(make_path);
use PublicInbox::TestCommon;
use PublicInbox::Spawn qw(spawn);
my $inboxdir = $ENV{GIANT_INBOX_DIR};
(defined($inboxdir) && -d $inboxdir) or
	plan skip_all => "GIANT_INBOX_DIR not defined for $0";
plan skip_all => "bad characters in $inboxdir" if $inboxdir =~ m![^\w\.\-/]!;
my $uuidgen = require_cmd('uuidgen');
my $mpop = require_cmd('mpop');
require_mods(qw(DBD::SQLite :fcntl_lock));
require_git(v2.6); # for v2

my ($tmpdir, $for_destroy) = tmpdir();
my $cfg = "$tmpdir/cfg";
my $newsgroup = 'inbox.test';
my %pids;
{
	open my $fh, '>', $cfg or xbail "open: $!";
	print $fh <<EOF or xbail "print: $!";
[publicinbox]
	pop3state = $tmpdir/p3s
[publicinbox "test"]
	newsgroup = $newsgroup
	address = mpop-test\@example.com
	inboxdir = $inboxdir
EOF
	close $fh or xbail "close: $!";
}
my ($out, $err) = ("$tmpdir/stdout.log", "$tmpdir/stderr.log");
my $sock = tcp_server();
my $cmd = [ '-pop3d', '-W0', "--stdout=$out", "--stderr=$err" ];
my $env = { PI_CONFIG => $cfg };
my $td = start_script($cmd, $env, { 3 => $sock }) or xbail "-xbail $?";
chomp(my $uuid = xqx([$uuidgen]));

make_path("$tmpdir/home/.config/mpop",
	map { "$tmpdir/md/$_" } qw(new cur tmp));

{
	open my $fh, '>', "$tmpdir/home/.config/mpop/config"
		or xbail "open $!";
	chmod 0600, $fh;
	print $fh <<EOM or xbail "print $!";
defaults
tls off
delivery maildir $tmpdir/md
account default
host ${\$sock->sockhost}
port ${\$sock->sockport}
user $uuid\@$newsgroup?limit=10000
auth user
password anonymous
received_header off
EOM
	close $fh or xbail "close $!";
	delete local $ENV{XDG_CONFIG_HOME}; # mpop uses this
	local $ENV{HOME} = "$tmpdir/home";
	my $cmd = [ $mpop, '-q' ];
	my $pid = spawn($cmd, undef, { 1 => 2 });
	$pids{$pid} = $cmd;
}
diag "mpop is writing to $tmpdir/md ...";
while (scalar keys %pids) {
	my $pid = waitpid(-1, 0) or next;
	my $cmd = delete $pids{$pid} or next;
	is($?, 0, join(' ', @$cmd, 'done'));
}
$td->kill;
$td->join;
is($?, 0, 'no error on -pop3d exit');
done_testing;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git