2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # we can index a message from a mirror which bypasses dedupe.
8 use PublicInbox::TestCommon;
10 require_mods(qw(DBD::SQLite));
11 my ($tmpdir, $for_destroy) = tmpdir();
12 use_ok 'PublicInbox::Import';
13 use_ok 'PublicInbox::Git';
14 use_ok 'PublicInbox::InboxWritable';
15 my $ibx = PublicInbox::InboxWritable->new({
17 name => 'test-v2dupindex',
19 indexlevel => 'basic',
20 -primary_address => 'test@example.com',
23 my $v2w = $ibx->importer;
24 $v2w->add(eml_load('t/plack-qp.eml'));
25 $v2w->add(eml_load('t/mda-mime.eml'));
28 my $git0 = PublicInbox::Git->new("$tmpdir/git/0.git");
29 my $im = PublicInbox::Import->new($git0, undef, undef, $ibx);
30 $im->{path_type} = 'v2';
31 $im->{lock_path} = undef;
33 # bypass duplicate filters (->header_set is optional)
34 my $eml = eml_load('t/plack-qp.eml');
35 $eml->header_set('X-This-Is-Not-Checked-By-ContentHash', 'blah');
36 ok($im->add($eml), 'add seen message directly');
37 ok($im->add(eml_load('t/mda-mime.eml')), 'add another seen message directly');
39 ok($im->add(eml_load('t/iso-2202-jp.eml')), 'add another new message');
42 # mimic a fresh clone by dropping indices
43 my @sqlite = (glob("$tmpdir/*sqlite3*"), glob("$tmpdir/xap*/*sqlite3*"));
44 is(unlink(@sqlite), scalar(@sqlite), 'unlinked SQLite indices');
45 my @shards = glob("$tmpdir/xap*/?");
46 is(scalar(@shards), 0, 'no Xapian shards to drop');
48 my $rdr = { 2 => \(my $err = '') };
49 ok(run_script([qw(-index -Lbasic), $tmpdir], undef, $rdr), '-indexed');
50 my @n = $ibx->over->dbh->selectrow_array('SELECT COUNT(*) FROM over');
51 is_deeply(\@n, [ 3 ], 'identical message not re-indexed');
52 my $mm = $ibx->mm->{dbh}->selectall_arrayref(<<'');
53 SELECT num,mid FROM msgmap ORDER BY num ASC
56 [ 1, 'qp@example.com' ],
57 [ 2, 'multipart-html-sucks@11' ],
58 [ 3, '199707281508.AAA24167@hoyogw.example' ]
59 ], 'msgmap omits redundant message');