1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use PublicInbox::TestCommon;
7 use PublicInbox::Emergency;
8 use PublicInbox::IO qw(write_file);
9 use PublicInbox::InboxIdle;
10 use PublicInbox::Inbox;
12 use PublicInbox::Config;
13 require_mods(qw(DBD::SQLite Xapian));
15 my $config = "$tmpdir/pi_config";
16 local $ENV{PI_CONFIG} = $config;
17 delete local $ENV{PI_DIR};
19 my @creat_opt = (indexlevel => 'medium', sub {});
20 my $v1 = create_inbox 'v1', tmpdir => "$tmpdir/v1", @creat_opt;
21 my $fh = write_file '>', $config, <<EOM;
23 inboxdir = $v1->{inboxdir}
24 address = v1\@example.com
25 watch = maildir:$tmpdir/v1-md
26 indexheader = boolean_term:xarchiveshash:X-Archives-Hash
32 my $v2 = create_inbox 'v2', tmpdir => "$tmpdir/v2", @creat_opt;
36 address = v2\@example.com
37 watch = maildir:$tmpdir/v2-md
38 indexheader = boolean_term:xarchiveshash:X-Archives-Hash
42 my $cfg = PublicInbox::Config->new;
43 for my $v (@V) { for ('', qw(cur new tmp)) { mkdir "$tmpdir/v$v-md/$_" } }
44 my $wm = start_script([qw(-watch)]);
45 my $h1 = 'deadbeef' x 4;
48 my $em = PublicInbox::Emergency->new("$tmpdir/v$v-md");
49 $em->prepare(\(PublicInbox::Eml->new(<<EOM)->as_string));
51 Message-ID: <i-1$v\@example.com>
52 To: <v$v\@example.com>
53 Date: Sat, 02 Oct 2010 00:00:00 +0000
62 diag "message delivered to `$_[0]->{name}'";
65 PublicInbox::DS->Reset;
66 my $ii = PublicInbox::InboxIdle->new($cfg);
67 my $obj = bless \$cb, 'PublicInbox::TestCommon::InboxWakeup';
68 $cfg->each_inbox(sub { $_[0]->subscribe_unlock('ident', $obj) });
69 local @PublicInbox::DS::post_loop_do = (sub { $delivered != @V });
71 diag 'waiting for -watch to import new message(s)';
72 PublicInbox::DS::event_loop();
76 $cfg->each_inbox(sub {
78 my $srch = $ibx->search;
79 my $mset = $srch->mset('xarchiveshash:miss');
80 is($mset->size, 0, 'got xarchiveshash:miss non-result');
81 $mset = $srch->mset("xarchiveshash:$h1");
82 is($mset->size, 1, 'got xarchiveshash: hit result') or return;
83 my $num = $srch->mset_to_artnums($mset);
84 my $eml = $ibx->smsg_eml($ibx->over->get_art($num->[0]));
85 is($eml->header_raw('X-Archives-Hash'), $h1,
86 'stored message with X-Archives-Hash');
87 my @opt = $srch->xh_args;
88 is $opt[-2], '-Q', 'xap_helper -Q switch';
89 is $opt[-1], 'xarchiveshash=XXARCHIVESHASH', 'xap_helper -Q arg';