X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/3ae173e7c0fd026a06c8804d38fe2c03d161e402..HEAD:/src/src/exiqgrep.src diff --git a/src/src/exiqgrep.src b/src/src/exiqgrep.src index afecbffee..6a0d40b51 100644 --- a/src/src/exiqgrep.src +++ b/src/src/exiqgrep.src @@ -2,6 +2,10 @@ # Utility for searching and displaying queue information. # Written by Matt Hubbard 15 August 2002 +# +# 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: @@ -15,10 +19,13 @@ # 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 '.' }; + use Getopt::Std; +use File::Basename; # Have this variable point to your exim binary. my $exim = 'BIN_DIRECTORY/exim'; @@ -43,10 +50,21 @@ if ($^O eq 'darwin') { # aka MacOS X $base = 62; }; -getopts('hf:r:y:o:s:C:zxlibRca',\%opt); -if ($opt{h}) { &help; exit;} +if ($ARGV[0] eq '--version' || $ARGV[0] eq '-v') { + print basename($0) . ": $0\n", + "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION\n", + "perl(runtime): $]\n"; + exit 0; +} + +if (!getopts('hf:r:y:o:s:C:zxlibRcaG:E:',\%opt)) { &help; exit; } +if ($opt{h}) { &help; exit; } +if ($ARGV[0] || !($opt{f} || $opt{r} || $opt{s} || $opt{y} || $opt{o} || $opt{z} || $opt{x} || $opt{c})) + { &help; exit(1); } if ($opt{a}) { $eargs = '-bp'; } if ($opt{C} && -e $opt{C} && -f $opt{C} && -R $opt{C}) { $eargs .= ' -C '.$opt{C}; } +if ($opt{G}) { $eargs .= ' -qG'.$opt{G}; } +if ($opt{E}) { $exim = $opt{E}; } # Read message queue output into hash &collect(); @@ -63,6 +81,7 @@ Exim message queue display utility. -h This help message. -C Specify which exim.conf to use. + -E Specify exim binary to use. Selection criteria: -f Match sender address sender (field is "< >" wrapped) @@ -72,6 +91,7 @@ Selection criteria: -o Message older than -z Frozen messages only (exclude non-frozen) -x Non-frozen messages only (exclude frozen) + -G Match in given queue only [ NB: for regexps, provided string sits in // ] @@ -86,23 +106,22 @@ EOF } sub collect() { - open(QUEUE,"$exim $eargs |") or die("Error openning pipe: $!\n"); + open(QUEUE,"$exim $eargs |") or die("Error opening pipe: $!\n"); while() { 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*(?\w+) + \s+(?(?:\d+(?:\.\d+)?[A-Z]?)?) + \s*(?(?:\w{6}-\w{6}-\w{2}|\w{6}-\w{11}-\w{4})) # old, 2023 msgid formats + \s+(?<.*?>)/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( =~ /\s+(.*?\@.*)$/) { push(@{$id{$msg}{rcpt}},$1); }