]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchMsg.pm
update copyrights for 2018
[public-inbox.git] / lib / PublicInbox / SearchMsg.pm
index 96406c6f9296646ff9534f211eefa461541b7c83..afba8b1a814c92c978c37c1ec3f44ea5b6a443e9 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # based on notmuch, but with no concept of folders, files or flags
 #
@@ -14,7 +14,7 @@ use PublicInbox::Address;
 sub new {
        my ($class, $mime) = @_;
        my $doc = Search::Xapian::Document->new;
-       $doc->add_term(PublicInbox::Search::xpfx('type') . 'mail');
+       $doc->add_term('T' . 'mail');
 
        bless { type => 'mail', doc => $doc, mime => $mime }, $class;
 }
@@ -29,6 +29,22 @@ sub get_val ($$) {
        Search::Xapian::sortable_unserialise($doc->get_value($col));
 }
 
+sub load_expand {
+       my ($self) = @_;
+       my $doc = $self->{doc};
+       my $data = $doc->get_data or return;
+       $self->{ts} = get_val($doc, &PublicInbox::Search::TS);
+       utf8::decode($data);
+       my ($subj, $from, $refs, $to, $cc, $blob) = split(/\n/, $data);
+       $self->{subject} = $subj;
+       $self->{from} = $from;
+       $self->{references} = $refs;
+       $self->{to} = $to;
+       $self->{cc} = $cc;
+       $self->{blob} = $blob;
+       $self;
+}
+
 sub load_doc {
        my ($class, $doc) = @_;
        my $data = $doc->get_data or return;
@@ -69,7 +85,7 @@ sub subject ($) { __hdr($_[0], 'subject') }
 sub to ($) { __hdr($_[0], 'to') }
 sub cc ($) { __hdr($_[0], 'cc') }
 
-# no strftime, that is locale-dependent
+# no strftime, that is locale-dependent and not for RFC822
 my @DoW = qw(Sun Mon Tue Wed Thu Fri Sat);
 my @MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
 
@@ -103,7 +119,7 @@ sub from_name {
 
 sub ts {
        my ($self) = @_;
-       $self->{ts} ||= eval { str2time($self->mime->header('Date')) } || 0;
+       $self->{ts} ||= eval { str2time($self->{mime}->header('Date')) } || 0;
 }
 
 sub to_doc_data {
@@ -146,36 +162,7 @@ sub mid ($;$) {
        }
 }
 
-sub _extract_mid { mid_clean(mid_mime($_[0]->mime)) }
-
-sub blob {
-       my ($self, $x40) = @_;
-       if (defined $x40) {
-               $self->{blob} = $x40;
-       } else {
-               $self->{blob};
-       }
-}
-
-sub mime {
-       my ($self, $mime) = @_;
-       if (defined $mime) {
-               $self->{mime} = $mime;
-       } else {
-               # TODO load from git
-               $self->{mime};
-       }
-}
-
-sub doc_id {
-       my ($self, $doc_id) = @_;
-       if (defined $doc_id) {
-               $self->{doc_id} = $doc_id;
-       } else {
-               # TODO load from xapian
-               $self->{doc_id};
-       }
-}
+sub _extract_mid { mid_clean(mid_mime($_[0]->{mime})) }
 
 sub thread_id {
        my ($self) = @_;
@@ -184,6 +171,7 @@ sub thread_id {
        $self->{thread} = _get_term_val($self, 'G', qr/\AG/); # *G*roup
 }
 
+# XXX: consider removing this, we can phrase match subject
 sub path {
        my ($self) = @_;
        my $path = $self->{path};