Control: tags -1 patch upstream

On 2023-09-08 19:30:29 +0200, Vincent Lefevre wrote:
> mailgraph no longer works after the upgrade to bookworm, and
> this is probably due to the fact that it does not support the
> new syslog format: /usr/sbin/mailgraph contains
[...]
> and this format is no longer correct.
> 
> There's a git repository where this bug seems to have been fixed
> 5 years ago:
> 
>   https://gist.github.com/mdklapwijk/4f8d2fc39f09f4aa615cbf8ffae0379a

I've attached a patch based on these modifications.
I've made 2 changes:
  * This patch does not add a new type "rsyslog" for this new format;
    so both formats are supported at the same time.
  * Fixed a variable name ($mon → $montxt) for the old format.

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
Description: support the rsyslog high-precision timestamp format.
 Patch based on M.D. Klapwijk's modifications for this support:
   https://gist.github.com/mdklapwijk/4f8d2fc39f09f4aa615cbf8ffae0379a
 (with some changes).
Author: Vincent Lefevre <vinc...@vinc17.net>
Bug-Debian: https://bugs.debian.org/1051496
Last-Update: 2023-09-09

--- mailgraph.pl.bak
+++ mailgraph.pl
@@ -202,27 +202,41 @@
     }
     my $file = $self->{file};
     line: while(defined (my $str = $self->_next_line)) {
-        # date, time and host 
-        $str =~ /^
-            (\S{3})\s+(\d+)      # date  -- 1, 2
-            \s
-            (\d+):(\d+):(\d+)    # time  -- 3, 4, 5
-            (?:\s<\w+\.\w+>)?    # FreeBSD's verbose-mode
-            \s
-            ([-\w\.\@:]+)        # host  -- 6
-            \s+
-            (?:\[LOG_[A-Z]+\]\s+)?  # FreeBSD
-            (.*)                 # text  -- 7
-            $/x or do
-        {
-            warn "WARNING: line not in syslog format: $str";
-            next line;
-        };
-        my $mon = $months_map{$1};
-        defined $mon or croak "unknown month $1\n";
-        $self->_year_increment($mon);
+        # date, time and host
+        my ($year, $mon, $day, $hour, $min, $sec, $host, $text);
+        if(($year, $mon, $day, $hour, $min, $sec, $host, $text) = $str =~ /^
+                (\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)\S+  # datetime
+                \s+
+                (\S+)                                   # host
+                \s+
+                (.*)                                    # text
+                $/x) {
+            $mon--;
+            $self->{year} = $year;
+        }
+        else {
+            my $montxt;
+            ($montxt, $day, $hour, $min, $sec, $host, $text) = $str =~ /^
+                (\S{3})\s+(\d+)      # date
+                \s
+                (\d+):(\d+):(\d+)    # time
+                (?:\s<\w+\.\w+>)?    # FreeBSD's verbose-mode
+                \s
+                ([-\w\.\@:]+)        # host
+                \s+
+                (?:\[LOG_[A-Z]+\]\s+)?  # FreeBSD
+                (.*)                 # text
+                $/x or do
+            {
+                warn "WARNING: line not in syslog format: $str";
+                next line;
+            };
+            $mon = $months_map{$montxt};
+            defined $mon or croak "unknown month $montxt\n";
+            $self->_year_increment($mon);
+        }
         # convert to unix time
-        my $time = $self->str2time($5,$4,$3,$2,$mon,$self->{year}-1900,$self->{GMT});
+        my $time = $self->str2time($sec,$min,$hour,$day,$mon,$self->{year}-1900,$self->{GMT});
         if(not $self->{allow_future}) {
             # accept maximum one day in the present future
             if($time - time > 86400) {
@@ -230,7 +244,6 @@
                 next line;
             }
         }
-        my ($host, $text) = ($6, $7);
         # last message repeated ... times
         if($text =~ /^(?:last message repeated|above message repeats) (\d+) time/) {
             next line if defined $self->{repeat} and not $self->{repeat};

Reply via email to