Hintsdb: fix build with USE_TDB
[exim.git] / src / src / exiqgrep.src
index 0661c57920a65a8190f1223807238a194e194813..6a0d40b516552cb4d1c4633036d6e239def36362 100644 (file)
@@ -3,7 +3,9 @@
 # Utility for searching and displaying queue information.
 # Written by Matt Hubbard 15 August 2002
 #
-# Copyright (c) The Exim Maintainers 2021 - 2022
+# Copyright (c) The Exim Maintainers 2021 - 2023
+# SPDX-License-Identifier: GPL-2.0-or-later
+# See the file NOTICE for conditions of use and distribution.
 
 # Except when they appear in comments, the following placeholders in this
 # source are replaced when it is turned into a runnable script:
@@ -17,7 +19,7 @@
 # Routine for extracting the UTC timestamp from message ID
 # lifted from eximstat utility
 
-# Version 1.2
+# Version 1.3
 
 use strict;
 BEGIN { pop @INC if $INC[-1] eq '.' };
@@ -48,7 +50,7 @@ if ($^O eq 'darwin') { # aka MacOS X
   $base = 62;
 };
 
-if ($ARGV[0] eq '--version') {
+if ($ARGV[0] eq '--version' || $ARGV[0] eq '-v') {
     print basename($0) . ": $0\n",
         "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION\n",
         "perl(runtime): $]\n";
@@ -109,18 +111,17 @@ sub collect() {
                chomp();
                my $line = $_;
                #Should be 1st line of record, if not error.
-               if ($line =~ /^\s*(\w+)\s+((?:\d+(?:\.\d+)?[A-Z]?)?)\s*(\w{6}-\w{6}-\w{2})\s+(<.*?>)/) {
-                       my $msg = $3;
-                       $id{$msg}{age} = $1;
-                       $id{$msg}{size} = $2;
-                       $id{$msg}{from} = $4;
+               if ($line =~ /^\s*(?<age>\w+)
+                             \s+(?<size>(?:\d+(?:\.\d+)?[A-Z]?)?)
+                             \s*(?<msgid>(?:\w{6}-\w{6}-\w{2}|\w{6}-\w{11}-\w{4}))     # old, 2023 msgid formats
+                             \s+(?<from><.*?>)/x) {
+                       my $msg = $+{msgid};
+                       $id{$msg}{age} = $+{age};
+                       $id{$msg}{size} = $+{size};
+                       $id{$msg}{from} = $+{from};
                        $id{$msg}{birth} = &msg_utc($msg);
                        $id{$msg}{ages} = time - $id{$msg}{birth};
-                       if ($line =~ /\*\*\* frozen \*\*\*$/) {
-                               $id{$msg}{frozen} = 1;
-                       } else {
-                               $id{$msg}{frozen} = 0;
-                       }
+                       $id{$msg}{frozen} = ($line =~ /\*\*\* frozen \*\*\*$/) ? 1 : 0;
                        while(<QUEUE> =~ /\s+(.*?\@.*)$/) {
                                push(@{$id{$msg}{rcpt}},$1);
                        }