]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/search.t
remove most internal Email::MIME usage
[public-inbox.git] / t / search.t
index 40264345985477bc0609381d5dbdd4c606c317ac..6dd5047454aa48336895d72d843e22da8ec3ae38 100644 (file)
@@ -8,7 +8,7 @@ require_mods(qw(DBD::SQLite Search::Xapian));
 require PublicInbox::SearchIdx;
 require PublicInbox::Inbox;
 require PublicInbox::InboxWritable;
-use PublicInbox::MIME;
+use PublicInbox::Eml;
 my ($tmpdir, $for_destroy) = tmpdir();
 my $git_dir = "$tmpdir/a.git";
 my $ibx = PublicInbox::Inbox->new({ inboxdir => $git_dir });
@@ -60,16 +60,17 @@ sub oct_is ($$$) {
 }
 
 $ibx->with_umask(sub {
-       my $root = PublicInbox::MIME->new(<<'EOF');
+       my $root = PublicInbox::Eml->new(<<'EOF');
 Date: Fri, 02 Oct 1993 00:00:00 +0000
 Subject: Hello world
 Message-ID: <root@s>
 From: John Smith <js@example.com>
 To: list@example.com
+List-Id: I'm not mad <i.m.just.bored>
 
 \m/
 EOF
-       my $last = PublicInbox::MIME->new(<<'EOF');
+       my $last = PublicInbox::Eml->new(<<'EOF');
 Date: Sat, 02 Oct 2010 00:00:00 +0000
 Subject: Re: Hello world
 In-Reply-To: <root@s>
@@ -77,6 +78,7 @@ Message-ID: <last@s>
 From: John Smith <js@example.com>
 To: list@example.com
 Cc: foo@example.com
+List-Id: there's nothing <left.for.me.to.do>
 
 goodbye forever :<
 EOF
@@ -126,7 +128,7 @@ sub filter_mids {
 $ibx->with_umask(sub {
        $rw_commit->();
        my $rmid = '<ghost-message@s>';
-       my $reply_to_ghost = PublicInbox::MIME->new(<<"EOF");
+       my $reply_to_ghost = PublicInbox::Eml->new(<<"EOF");
 Date: Sat, 02 Oct 2010 00:00:00 +0000
 Subject: Re: ghosts
 Message-ID: <ghost-reply\@s>
@@ -140,7 +142,7 @@ EOF
        my $reply_id = $rw->add_message($reply_to_ghost);
        is($reply_id, int($reply_id), "reply_id is an integer: $reply_id");
 
-       my $was_ghost = PublicInbox::MIME->new(<<"EOF");
+       my $was_ghost = PublicInbox::Eml->new(<<"EOF");
 Date: Sat, 02 Oct 2010 00:00:01 +0000
 Subject: ghosts
 Message-ID: $rmid
@@ -189,7 +191,7 @@ $ibx->with_umask(sub {
        $rw_commit->();
        $ro->reopen;
        my $long_mid = 'last' . ('x' x 60). '@s';
-       my $long = PublicInbox::MIME->new(<<EOF);
+       my $long = PublicInbox::Eml->new(<<EOF);
 Date: Sat, 02 Oct 2010 00:00:00 +0000
 Subject: long message ID
 References: <root\@s> <last\@s>
@@ -209,7 +211,7 @@ EOF
        my @res;
 
        my $long_reply_mid = 'reply-to-long@1';
-       my $long_reply = PublicInbox::MIME->new(<<EOF);
+       my $long_reply = PublicInbox::Eml->new(<<EOF);
 Subject: I break references
 Date: Sat, 02 Oct 2010 00:00:00 +0000
 Message-ID: <$long_reply_mid>
@@ -233,7 +235,7 @@ EOF
 # quote prioritization
 $ibx->with_umask(sub {
        $rw_commit->();
-       $rw->add_message(PublicInbox::MIME->new(<<'EOF'));
+       $rw->add_message(PublicInbox::Eml->new(<<'EOF'));
 Date: Sat, 02 Oct 2010 00:00:01 +0000
 Subject: Hello
 Message-ID: <quote@a>
@@ -243,7 +245,7 @@ To: list@example.com
 > theatre illusions
 fade
 EOF
-       $rw->add_message(PublicInbox::MIME->new(<<'EOF'));
+       $rw->add_message(PublicInbox::Eml->new(<<'EOF'));
 Date: Sat, 02 Oct 2010 00:00:02 +0000
 Subject: Hello
 Message-ID: <nquote@a>
@@ -267,7 +269,7 @@ EOF
 # circular references
 $ibx->with_umask(sub {
        my $s = 'foo://'. ('Circle' x 15).'/foo';
-       my $doc_id = $rw->add_message(PublicInbox::MIME->new(<<EOF));
+       my $doc_id = $rw->add_message(PublicInbox::Eml->new(<<EOF));
 Subject: $s
 Date: Sat, 02 Oct 2010 00:00:01 +0000
 Message-ID: <circle\@a>
@@ -286,9 +288,7 @@ EOF
 });
 
 $ibx->with_umask(sub {
-       my $eml = 't/utf8.eml';
-       my $mime = PublicInbox::InboxWritable::mime_from_path($eml) or
-               die "open $eml: $!";
+       my $mime = eml_load 't/utf8.eml';
        my $doc_id = $rw->add_message($mime);
        ok($doc_id > 0, 'message indexed doc_id with UTF-8');
        my $msg = $rw->query('m:testmessage@example.com', {limit => 1})->[0];
@@ -371,7 +371,7 @@ $ibx->with_umask(sub {
 }
 
 $ibx->with_umask(sub {
-       my $amsg = mime_load 't/search-amsg.eml';
+       my $amsg = eml_load 't/search-amsg.eml';
        ok($rw->add_message($amsg), 'added attachment');
        $rw_commit->();
        $ro->reopen;
@@ -429,7 +429,7 @@ $ibx->with_umask(sub {
        my $mid = "$ua.$digits.2460-100000\@penguin.transmeta.com";
        is($ro->reopen->query("m:$digits", { mset => 1})->size, 0,
                'no results yet');
-       my $pine = PublicInbox::MIME->new(<<EOF);
+       my $pine = PublicInbox::Eml->new(<<EOF);
 Subject: blah
 Message-ID: <$mid>
 From: torvalds\@transmeta
@@ -450,6 +450,35 @@ EOF
        is($ro->query("m:Pine m:LNX m:10010260936330", {mset=>1})->size, 1);
 });
 
+{ # List-Id searching
+       my $found = $ro->query('lid:i.m.just.bored');
+       is_deeply([ filter_mids($found) ], [ 'root@s' ],
+               'got expected mid on exact lid: search');
+
+       $found = $ro->query('lid:just.bored');
+       is_deeply($found, [], 'got nothing on lid: search');
+
+       $found = $ro->query('lid:*.just.bored');
+       is_deeply($found, [], 'got nothing on lid: search');
+
+       $found = $ro->query('l:i.m.just.bored');
+       is_deeply([ filter_mids($found) ], [ 'root@s' ],
+               'probabilistic search works on full List-Id contents');
+
+       $found = $ro->query('l:just.bored');
+       is_deeply([ filter_mids($found) ], [ 'root@s' ],
+               'probabilistic search works on partial List-Id contents');
+
+       $found = $ro->query('lid:mad');
+       is_deeply($found, [], 'no match on phrase with lid:');
+
+       $found = $ro->query('lid:bored');
+       is_deeply($found, [], 'no match on partial List-Id with lid:');
+
+       $found = $ro->query('l:nothing');
+       is_deeply($found, [], 'matched on phrase with l:');
+}
+
 done_testing();
 
 1;