lib/PublicInbox/MsgTime.pm | 6 +++++- t/msgtime.t | 14 ++++++++++++-- diff --git a/lib/PublicInbox/MsgTime.pm b/lib/PublicInbox/MsgTime.pm index 479aaa4ecf132f5176d49ce54db6171769872666..9f4326442dd110d12a40f96595d3b2b2da7461aa 100644 --- a/lib/PublicInbox/MsgTime.pm +++ b/lib/PublicInbox/MsgTime.pm @@ -38,7 +38,7 @@ # SpamAssassin ignores commas and redundant spaces, too. if ($date =~ /(?:[A-Za-z]+,?\s+)? # day-of-week ([0-9]+),?\s+ # dd ([A-Za-z]+)\s+ # mon - ([0-9]{2,})\s+ # YYYY or YY (or YYY :P) + ([0-9]{2,4})\s+ # YYYY or YY (or YYY :P) ([0-9]+)[:\.] # HH: ((?:[0-9]{2})|(?:\s?[0-9])) # MM (?:[:\.]((?:[0-9]{2})|(?:\s?[0-9])))? # :SS @@ -66,6 +66,10 @@ $yyyy += 100 if $yyyy < 1950; } $ts = timegm($ss // 0, $mm, $hh, $dd, $mon, $yyyy); + + # 4-digit dates in non-spam from 1900s and 1910s exist in + # lore archives + return if $ts < 0; # Compute the time offset from [+-]HHMM $tz //= 0; diff --git a/t/msgtime.t b/t/msgtime.t index 1452dc97d5b0bc4d2f338a40d7ea1f3945c5135c..98cf66e6426c4feee883b3dcf1433352b33b7e9b 100644 --- a/t/msgtime.t +++ b/t/msgtime.t @@ -5,7 +5,7 @@ use warnings; use Test::More; use PublicInbox::MIME; use PublicInbox::MsgTime; - +our $received_date = 'Mon, 22 Jan 2007 13:16:24 -0500'; sub datestamp ($) { my ($date) = @_; local $SIG{__WARN__} = sub {}; # Suppress warnings @@ -17,7 +17,11 @@ 'Content-Type' => 'text/plain', Subject => 'this is a subject', 'Message-ID' => '', Date => $date, - 'Received' => '(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S932173AbXAVSQY (ORCPT );\n\tMon, 22 Jan 2007 13:16:24 -0500', + 'Received' => <); +\t$received_date +EOF ], body => "hello world\n", ); @@ -103,5 +107,11 @@ for (qw(UT GMT Z)) { is_datestamp('Fri, 02 Oct 1993 00:00:00 '.$_, [ 749520000, '+0000']); } is_datestamp('Fri, 02 Oct 1993 00:00:00 EDT', [ 749534400, '-0400']); + +# fallback to Received: header if Date: is out-of-range: +is_datestamp('Fri, 1 Jan 1904 10:12:31 +0100', + PublicInbox::MsgTime::str2date_zone($received_date)); +is_datestamp('Fri, 9 Mar 71685 18:45:56 +0000', # Y10K is not my problem :P + PublicInbox::MsgTime::str2date_zone($received_date)); done_testing();