]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Smsg.pm
smsg: remove remaining accessor methods
[public-inbox.git] / lib / PublicInbox / Smsg.pm
index 446bca81b48637d400983f9721ec683079342632..e8f9c9a3681bd8519997e77729a06949e6ba5ce6 100644 (file)
@@ -12,7 +12,7 @@ use strict;
 use warnings;
 use base qw(Exporter);
 our @EXPORT_OK = qw(subject_normalized);
-use PublicInbox::MID qw/mid_mime/;
+use PublicInbox::MID qw(mids);
 use PublicInbox::Address;
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
 use Time::Local qw(timegm);
@@ -28,7 +28,7 @@ sub to_doc_data {
        join("\n",
                $self->{subject},
                $self->{from},
-               $self->references,
+               $self->{references} // '',
                $self->{to},
                $self->{cc},
                $self->{blob},
@@ -74,11 +74,15 @@ sub load_expand {
 
 sub psgi_cull ($) {
        my ($self) = @_;
-       from_name($self); # fill in {from_name} so we can delete {from}
+
+       # ghosts don't have ->{from}
+       my $from = delete($self->{from}) // '';
+       my @n = PublicInbox::Address::names($from);
+       $self->{from_name} = join(', ', @n);
 
        # drop NNTP-only fields which aren't relevant to PSGI results:
        # saves ~80K on a 200 item search result:
-       delete @$self{qw(from ts to cc bytes lines)};
+       delete @$self{qw(ts to cc bytes lines)};
        $self;
 }
 
@@ -90,22 +94,7 @@ sub from_mitem {
        psgi_cull(load_expand($self, $mitem->get_document));
 }
 
-# :bytes and :lines metadata in RFC 3977
-sub bytes ($) { $_[0]->{bytes} }
-sub lines ($) { $_[0]->{lines} }
-
-sub __hdr ($$) {
-       my ($self, $field) = @_;
-       $self->{lc($field)} //= do {
-               my $mime = $self->{mime} or return;
-               my $val = join(', ', $mime->header($field));
-               $val =~ tr/\r//d;
-               $val =~ tr/\t\n/  /;
-               $val;
-       };
-}
-
-# for Import and v1 WWW code paths
+# for Import and v1 non-SQLite WWW code paths
 sub populate {
        my ($self, $hdr, $v2w) = @_;
        for my $f (qw(From To Cc Subject)) {
@@ -133,11 +122,10 @@ sub populate {
        $self->{-ts} = [ my @ts = msg_timestamp($hdr, $v2w->{cotime}) ];
        $self->{ds} //= $ds[0]; # no zone
        $self->{ts} //= $ts[0];
-}
 
-sub subject ($) { __hdr($_[0], 'Subject') }
-sub to ($) { __hdr($_[0], 'To') }
-sub cc ($) { __hdr($_[0], 'Cc') }
+       # for v1 users w/o SQLite
+       $self->{mid} //= eval { mids($hdr)->[0] } // '';
+}
 
 # no strftime, that is locale-dependent and not for RFC822
 my @DoW = qw(Sun Mon Tue Wed Thu Fri Sat);
@@ -153,53 +141,6 @@ sub date ($) {
 
 }
 
-sub from ($) {
-       my ($self) = @_;
-       my $from = __hdr($self, 'From');
-       if (defined $from && !defined $self->{from_name}) {
-               my @n = PublicInbox::Address::names($from);
-               $self->{from_name} = join(', ', @n);
-       }
-       $from;
-}
-
-sub from_name {
-       my ($self) = @_;
-       my $from_name = $self->{from_name};
-       return $from_name if defined $from_name;
-       $self->from;
-       $self->{from_name};
-}
-
-sub ts {
-       my ($self) = @_;
-       $self->{ts} ||= eval { msg_timestamp($self->{mime}->header_obj) } || 0;
-}
-
-sub ds {
-       my ($self) = @_;
-       $self->{ds} ||= eval { msg_datestamp($self->{mime}->header_obj); } || 0;
-}
-
-sub references {
-       my ($self) = @_;
-       my $x = $self->{references};
-       defined $x ? $x : '';
-}
-
-sub mid ($;$) {
-       my ($self, $mid) = @_;
-
-       if (defined $mid) {
-               $self->{mid} = $mid;
-       } elsif (defined(my $rv = $self->{mid})) {
-               $rv;
-       } else {
-               die "NO {mime} for mid\n" unless $self->{mime};
-               mid_mime($self->{mime}) # v1 w/o Xapian
-       }
-}
-
 our $REPLY_RE = qr/^re:\s+/i;
 
 sub subject_normalized ($) {