]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Smsg.pm
searchidx: index THREADID in Xapian
[public-inbox.git] / lib / PublicInbox / Smsg.pm
index 725d420628250e72ca3bcb13d33b5f24faade51e..0a0384efaadf7811d372631885ec771345370c7b 100644 (file)
@@ -40,6 +40,7 @@ sub to_doc_data {
 
 sub load_from_data ($$) {
        my ($self) = $_[0]; # data = $_[1]
+       utf8::decode($_[1]);
        (
                $self->{subject},
                $self->{from},
@@ -67,7 +68,6 @@ sub load_expand {
        my $dt = get_val($doc, PublicInbox::Search::DT());
        my ($yyyy, $mon, $dd, $hh, $mm, $ss) = unpack('A4A2A2A2A2A2', $dt);
        $self->{ds} = timegm($ss, $mm, $hh, $dd, $mon - 1, $yyyy);
-       utf8::decode($data);
        load_from_data($self, $data);
        $self;
 }
@@ -82,21 +82,14 @@ sub psgi_cull ($) {
 
        # drop NNTP-only fields which aren't relevant to PSGI results:
        # saves ~80K on a 200 item search result:
-       delete @$self{qw(ts to cc bytes lines)};
+       # TODO: we may need to keep some of these for JMAP...
+       delete @$self{qw(ts tid to cc bytes lines)};
        $self;
 }
 
-# Only called by PSGI interface, not NNTP
-sub from_mitem {
-       my ($mitem, $srch) = @_;
-       return $srch->retry_reopen(\&from_mitem, $mitem) if $srch;
-       my $self = bless {}, __PACKAGE__;
-       psgi_cull(load_expand($self, $mitem->get_document));
-}
-
 # for Import and v1 non-SQLite WWW code paths
 sub populate {
-       my ($self, $hdr, $v2w) = @_;
+       my ($self, $hdr, $sync) = @_;
        for my $f (qw(From To Cc Subject)) {
                my @all = $hdr->header($f);
                my $val = join(', ', @all);
@@ -105,6 +98,9 @@ sub populate {
                # to protect git and NNTP clients
                $val =~ tr/\0\t\n/   /;
 
+               # rare: in case headers have wide chars (not RFC2047-encoded)
+               utf8::decode($val);
+
                # lower-case fields for read-only stuff
                $self->{lc($f)} = $val;
 
@@ -117,9 +113,9 @@ sub populate {
                }
                $self->{$f} = $val if $val ne '';
        }
-       $v2w //= {};
-       $self->{-ds} = [ my @ds = msg_datestamp($hdr, $v2w->{autime}) ];
-       $self->{-ts} = [ my @ts = msg_timestamp($hdr, $v2w->{cotime}) ];
+       $sync //= {};
+       $self->{-ds} = [ my @ds = msg_datestamp($hdr, $sync->{autime}) ];
+       $self->{-ts} = [ my @ts = msg_timestamp($hdr, $sync->{cotime}) ];
        $self->{ds} //= $ds[0]; # no zone
        $self->{ts} //= $ts[0];