]> Sergey Matveev's repositories - public-inbox.git/commitdiff
search: index byte size of a message for IMAP search
authorEric Wong <e@yhbt.net>
Wed, 10 Jun 2020 07:04:52 +0000 (07:04 +0000)
committerEric Wong <e@yhbt.net>
Sat, 13 Jun 2020 07:55:45 +0000 (07:55 +0000)
Searching for messages smaller than a certain size is allowed by
offlineimap(1), mbsync(1), and possibly other tools.  Maybe
public-inbox-watch will support it, too.

I don't see a reason to expose searching by size via WWW search
right now (but maybe in the future, I could be convinced to).

Note: we only store the byte-size of the message in git,
this is typically LF-only and we won't have the correct
size after CRLF conversion for NNTP or IMAP.

lib/PublicInbox/Search.pm
lib/PublicInbox/SearchIdx.pm
t/search.t

index cb669e8733e7cd8596d6483ed77f4bb33dd16d66..f2d3b92dc821e87e71b5dd2cc3f7729157f02494 100644 (file)
@@ -5,12 +5,16 @@
 # Read-only search interface for use by the web and NNTP interfaces
 package PublicInbox::Search;
 use strict;
-use warnings;
 
 # values for searching
-use constant TS => 0;  # Received: header in Unix time
-use constant YYYYMMDD => 1; # Date: header for searching in the WWW UI
-use constant DT => 2; # Date: YYYYMMDDHHMMSS
+use constant {
+       TS => 0, # Received: header in Unix time (IMAP INTERNALDATE)
+       YYYYMMDD => 1, # Date: header for searching in the WWW UI
+       DT => 2, # Date: YYYYMMDDHHMMSS
+       BYTES => 3, # IMAP RFC822.SIZE
+       # TODO
+       # REPLYCNT => 4, # IMAP ANSWERED
+};
 
 use PublicInbox::Smsg;
 use PublicInbox::Over;
index f4fa50ff10fc92ef4bf16e4a18935ac5f5a9c2ec..f7462aa74ca0aa7ff73992437ffeca36c65e60ca 100644 (file)
@@ -341,6 +341,7 @@ sub add_xapian ($$$$) {
        add_val($doc, PublicInbox::Search::YYYYMMDD(), $yyyymmdd);
        my $dt = strftime('%Y%m%d%H%M%S', @ds);
        add_val($doc, PublicInbox::Search::DT(), $dt);
+       add_val($doc, PublicInbox::Search::BYTES(), $smsg->{bytes});
 
        my $tg = term_generator($self);
        $tg->set_document($doc);
@@ -388,6 +389,7 @@ sub add_message {
 
        # v1 and tests only:
        $smsg->populate($hdr, $self);
+       $smsg->{bytes} //= length($mime->as_string);
 
        eval {
                # order matters, overview stores every possible piece of
index 6cf2bc2d6b428938d1cb2ab6c9f7c355cc540f8d..cf3254169ca3485e689e5498f97df82b2b0dc69f 100644 (file)
@@ -318,6 +318,12 @@ $ibx->with_umask(sub {
        foreach my $m ($mset->items) {
                my $smsg = $ro->{over_ro}->get_art($m->get_docid);
                like($smsg->{to}, qr/\blist\@example\.com\b/, 'to appears');
+               my $doc = $m->get_document;
+               my $col = PublicInbox::Search::BYTES();
+               my $bytes = PublicInbox::Smsg::get_val($doc, $col);
+               like($bytes, qr/\A[0-9]+\z/, '$bytes stored as digit');
+               ok($bytes > 0, '$bytes is > 0');
+               is($bytes, $smsg->{bytes}, 'bytes Xapian value matches Over');
        }
 
        $mset = $ro->query('tc:list@example.com', {mset => 1});