about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchMsg.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-21 01:52:58 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-22 00:12:39 +0000
commit8e52e5fdea416d6fda0b8d301144af0c043a5a76 (patch)
treedafe724cfb77f00e8cb50d89a2f03b50d8c330cb /lib/PublicInbox/SearchMsg.pm
parent54590383027a67d11953690cbb6390347757730b (diff)
downloadpublic-inbox-8e52e5fdea416d6fda0b8d301144af0c043a5a76.tar.gz
We want to rely on Date: to sort messages within individual
threads since it keeps messages from git-send-email(1) sorted.
However, since developers occasionally have the clock set
wrong on their machines, sort overall messages by the newest
date in a Received: header so the landing page isn't forever
polluted by messages from the future.

This also gives us determinism for commit times in most cases,
as we'll used the Received: timestamp there, as well.
Diffstat (limited to 'lib/PublicInbox/SearchMsg.pm')
-rw-r--r--lib/PublicInbox/SearchMsg.pm26
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm
index a1cd0c28..de1fd131 100644
--- a/lib/PublicInbox/SearchMsg.pm
+++ b/lib/PublicInbox/SearchMsg.pm
@@ -9,7 +9,7 @@ use warnings;
 use Search::Xapian;
 use PublicInbox::MID qw/mid_clean mid_mime/;
 use PublicInbox::Address;
-use PublicInbox::MsgTime qw(msg_timestamp);
+use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
 
 sub new {
         my ($class, $mime) = @_;
@@ -46,6 +46,7 @@ sub load_expand {
         my $doc = $self->{doc};
         my $data = $doc->get_data or return;
         $self->{ts} = get_val($doc, &PublicInbox::Search::TS);
+        $self->{ds} = get_val($doc, &PublicInbox::Search::DS);
         utf8::decode($data);
         load_from_data($self, $data);
         $self;
@@ -53,12 +54,8 @@ sub load_expand {
 
 sub load_doc {
         my ($class, $doc) = @_;
-        my $data = $doc->get_data or return;
-        my $ts = get_val($doc, &PublicInbox::Search::TS);
-        utf8::decode($data);
-        my $self = bless { doc => $doc, ts => $ts }, $class;
-        load_from_data($self, $data);
-        $self
+        my $self = bless { doc => $doc }, $class;
+        $self->load_expand;
 }
 
 # :bytes and :lines metadata in RFC 3977
@@ -91,9 +88,9 @@ my @MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
 
 sub date ($) {
         my ($self) = @_;
-        my $ts = $self->{ts};
-        return unless defined $ts;
-        my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($ts);
+        my $ds = $self->{ds};
+        return unless defined $ds;
+        my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($ds);
         "$DoW[$wday], " . sprintf("%02d $MoY[$mon] %04d %02d:%02d:%02d +0000",
                                 $mday, $year+1900, $hour, $min, $sec);
 
@@ -119,9 +116,12 @@ sub from_name {
 
 sub ts {
         my ($self) = @_;
-        $self->{ts} ||= eval {
-                msg_timestamp($self->{mime}->header_obj);
-        } || 0;
+        $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 to_doc_data {