SPDX: Mass-update to GPL-2.0-or-later
[exim.git] / src / src / exiqgrep.src
index 05c1b9ed06ef9ee43212ef9ef1e39798ce71a495..0661c57920a65a8190f1223807238a194e194813 100644 (file)
@@ -2,6 +2,8 @@
 
 # Utility for searching and displaying queue information.
 # Written by Matt Hubbard 15 August 2002
+#
+# Copyright (c) The Exim Maintainers 2021 - 2022
 
 # Except when they appear in comments, the following placeholders in this
 # source are replaced when it is turned into a runnable script:
 # Version 1.2
 
 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,9 +48,21 @@ if ($^O eq 'darwin') { # aka MacOS X
   $base = 62;
 };
 
-getopts('hf:r:y:o:s:zxlibRca',\%opt);
-if ($opt{h}) { &help; exit;}
+if ($ARGV[0] eq '--version') {
+    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();
@@ -61,6 +78,8 @@ sub help() {
 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 <regexp>     Match sender address sender (field is "< >" wrapped)
@@ -70,6 +89,7 @@ Selection criteria:
        -o <seconds>    Message older than
        -z              Frozen messages only (exclude non-frozen)
        -x              Non-frozen messages only (exclude frozen)
+       -G <queuename>  Match in given queue only
 
 [ NB: for regexps, provided string sits in /<string>/ ]
 
@@ -84,7 +104,7 @@ EOF
 }
 
 sub collect() {
-       open(QUEUE,"$exim $eargs |") or die("Error openning pipe: $!\n");
+       open(QUEUE,"$exim $eargs |") or die("Error opening pipe: $!\n");
        while(<QUEUE>) {
                chomp();
                my $line = $_;