]> Sergey Matveev's repositories - public-inbox.git/commitdiff
msgtime: require ASCII digits for parsing dates
authorEric Wong <e@80x24.org>
Tue, 4 Jun 2019 02:04:24 +0000 (02:04 +0000)
committerEric Wong <e@80x24.org>
Tue, 4 Jun 2019 10:06:18 +0000 (10:06 +0000)
User input contains the darndest things.  Don't waste more time
than necessary trying to parse dates out of non-ASCII digits.

lib/PublicInbox/MsgTime.pm

index 62160233f78d627d0bfc9c2e24b72f634d42005b..12412825800952c35f1d189841758fe0e7a02128 100644 (file)
@@ -44,8 +44,9 @@ sub msg_received_at ($) {
        my @recvd = $hdr->header_raw('Received');
        my ($ts);
        foreach my $r (@recvd) {
-               $r =~ /\s*(\d+\s+[[:alpha:]]+\s+\d{2,4}\s+
-                       \d+\D\d+(?:\D\d+)\s+([\+\-]\d+))/sx or next;
+               $r =~ /\s*([0-9]+\s+[a-zA-Z]+\s+[0-9]{2,4}\s+
+                       [0-9]+[^0-9][0-9]+(?:[^0-9][0-9]+)
+                       \s+([\+\-][0-9]+))/sx or next;
                $ts = eval { str2date_zone($1) } and return $ts;
                my $mid = $hdr->header_raw('Message-ID');
                warn "no date in $mid Received: $r\n";
@@ -59,7 +60,7 @@ sub msg_date_only ($) {
        my ($ts);
        foreach my $d (@date) {
                # Y2K problems: 3-digit years
-               $d =~ s!([A-Za-z]{3}) (\d{3}) (\d\d:\d\d:\d\d)!
+               $d =~ s!([A-Za-z]{3}) ([0-9]{3}) ([0-9]{2}:[0-9]{2}:[0-9]{2})!
                        my $yyyy = $2 + 1900; "$1 $yyyy $3"!e;
                $ts = eval { str2date_zone($d) } and return $ts;
                if ($@) {