ok($@, "exception raised on non-existent DB");
my $rw = PublicInbox::SearchIdx->new($git_dir, 1);
-$rw->_xdb_acquire;
-$rw->_xdb_release;
my $ibx = $rw->{-inbox};
+$ibx->with_umask(sub {
+ $rw->_xdb_acquire;
+ $rw->_xdb_release;
+});
$rw = undef;
my $ro = PublicInbox::Search->new($git_dir);
my $rw_commit = sub {
umask, 'umask => existing umask');
}
-{
+$ibx->with_umask(sub {
my $root = Email::MIME->create(
header_str => [
Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
is($root_id, int($root_id), "root_id is an integer: $root_id");
$last_id = $rw->add_message($last);
is($last_id, int($last_id), "last_id is an integer: $last_id");
-}
+});
sub filter_mids {
my ($msgs) = @_;
}
# ghost vivication
-{
+$ibx->with_umask(sub {
$rw_commit->();
my $rmid = '<ghost-message@s>';
my $reply_to_ghost = Email::MIME->create(
}
isnt($msgs->[0]->{num}, $msgs->[1]->{num}, "num do not match");
ok($_->{num} > 0, 'positive art num') foreach @$msgs
-}
+});
# search thread on ghost
{
}
# long message-id
-{
+$ibx->with_umask(sub {
$rw_commit->();
$ro->reopen;
my $long_mid = 'last' . ('x' x 60). '@s';
my @exp = sort($long_reply_mid, 'root@s', 'last@s', $long_mid);
@res = filter_mids($t);
is_deeply(\@res, \@exp, "get_thread works");
-}
+});
# quote prioritization
-{
+$ibx->with_umask(sub {
$rw_commit->();
$rw->add_message(Email::MIME->create(
header_str => [
is(scalar(@$res), 1, "got a match for quoted text");
is($res->[0]->mid, 'quote@a',
"quoted result returned if nothing else");
-}
+});
# circular references
-{
+$ibx->with_umask(sub {
my $s = 'foo://'. ('Circle' x 15).'/foo';
my $doc_id = $rw->add_message(Email::MIME->create(
header => [ Subject => $s ],
my $smsg = $rw->query('m:circle@a', {limit=>1})->[0];
is($smsg->references, '', "no references created");
is($s, $smsg->subject, 'long subject not rewritten');
-}
+});
-{
+$ibx->with_umask(sub {
my $str = eval {
my $mbox = 't/utf8.mbox';
open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n";
ok($doc_id > 0, 'message indexed doc_id with UTF-8');
my $msg = $rw->query('m:testmessage@example.com', {limit => 1})->[0];
is($mime->header('Subject'), $msg->subject, 'UTF-8 subject preserved');
-}
+});
{
my $msgs = $ro->query('d:19931002..20101002');
# names and addresses
{
- my $res = $ro->query('t:list@example.com');
- is(scalar @$res, 6, 'searched To: successfully');
- foreach my $smsg (@$res) {
+ my $mset = $ro->query('t:list@example.com', {mset => 1});
+ is($mset->size, 6, 'searched To: successfully');
+ foreach my $m ($mset->items) {
+ my $smsg = $ro->lookup_article($m->get_docid);
like($smsg->to, qr/\blist\@example\.com\b/, 'to appears');
}
- $res = $ro->query('tc:list@example.com');
- is(scalar @$res, 6, 'searched To+Cc: successfully');
- foreach my $smsg (@$res) {
+ $mset = $ro->query('tc:list@example.com', {mset => 1});
+ is($mset->size, 6, 'searched To+Cc: successfully');
+ foreach my $m ($mset->items) {
+ my $smsg = $ro->lookup_article($m->get_docid);
my $tocc = join("\n", $smsg->to, $smsg->cc);
like($tocc, qr/\blist\@example\.com\b/, 'tocc appears');
}
foreach my $pfx ('tcf:', 'c:') {
- $res = $ro->query($pfx . 'foo@example.com');
- is(scalar @$res, 1,
- "searched $pfx successfully for Cc:");
- foreach my $smsg (@$res) {
+ my $mset = $ro->query($pfx . 'foo@example.com', { mset => 1 });
+ is($mset->items, 1, "searched $pfx successfully for Cc:");
+ foreach my $m ($mset->items) {
+ my $smsg = $ro->lookup_article($m->get_docid);
like($smsg->cc, qr/\bfoo\@example\.com\b/,
'cc appears');
}
}
foreach my $pfx ('', 'tcf:', 'f:') {
- $res = $ro->query($pfx . 'Laggy');
+ my $res = $ro->query($pfx . 'Laggy');
is(scalar(@$res), 1,
"searched $pfx successfully for From:");
foreach my $smsg (@$res) {
}
}
-{
+$ibx->with_umask(sub {
my $part1 = Email::MIME->create(
attributes => {
content_type => 'text/plain',
my $txt = $ro->query('"inside another"');
is($txt->[0]->mid, $res->[0]->mid,
'search inside text attachments works');
+
+ my $mid = $n->[0]->mid;
+ my ($id, $prev);
+ my $art = $ro->next_by_mid($mid, \$id, \$prev);
+ ok($art, 'article exists in OVER DB');
+ $rw->unindex_blob($amsg);
+ $rw->commit_txn_lazy;
+ is($ro->lookup_article($art->{num}), undef, 'gone from OVER DB');
+});
+
+foreach my $f ("$git_dir/public-inbox/msgmap.sqlite3",
+ glob("$git_dir/public-inbox/xapian*/"),
+ glob("$git_dir/public-inbox/xapian*/*")) {
+ my @st = stat($f);
+ my ($bn) = (split(m!/!, $f))[-1];
+ is($st[2] & 07777, -f _ ? 0660 : 0770,
+ "sharedRepository respected for $bn");
}
-$rw->commit_txn_lazy;
+
+$ibx->with_umask(sub {
+ $rw_commit->();
+ my $digits = '10010260936330';
+ my $ua = 'Pine.LNX.4.10';
+ my $mid = "$ua.$digits.2460-100000\@penguin.transmeta.com";
+ is($ro->reopen->query("m:$digits", { mset => 1})->size, 0,
+ 'no results yet');
+ my $pine = Email::MIME->create(
+ header_str => [
+ Subject => 'blah',
+ 'Message-ID' => "<$mid>",
+ From => 'torvalds@transmeta',
+ To => 'list@example.com',
+ ],
+ body => ""
+ );
+ my $x = $rw->add_message($pine);
+ $rw->commit_txn_lazy;
+ is($ro->reopen->query("m:$digits", { mset => 1})->size, 1,
+ 'searching only digit yielded result');
+
+ my $wild = $digits;
+ for my $i (1..6) {
+ chop($wild);
+ is($ro->query("m:$wild*", { mset => 1})->size, 1,
+ "searching chopped($i) digit yielded result $wild ");
+ }
+ is($ro->query("m:Pine m:LNX m:10010260936330", {mset=>1})->size, 1);
+});
done_testing();