From 42ed39da5af85552a35626348bb77e5576e18aa4 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sun, 6 Mar 2022 14:25:13 +0000 Subject: [PATCH] Utilities: fix exiqgrep perl syntax, add testcases. Bug 2821 Broken-by: df618101a5 --- doc/doc-docbook/spec.xfpt | 18 +++++++++-- src/src/exiqgrep.src | 9 ++++-- test/README | 6 ++++ test/runtest | 15 +++++++-- test/scripts/0000-Basic/0611 | 6 ++++ test/stdout/0611 | 62 ++++++++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 test/stdout/0611 diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index bfadeb10a..a7625630e 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -39422,9 +39422,6 @@ or (in case &*-a*& switch is specified) .code exim -bp .endd -The &*-C*& option is used to specify an alternate &_exim.conf_& which might -contain alternate exim configuration the queue management might be using. - to obtain a queue listing, and then greps the output to select messages that match given criteria. The following selection options are available: @@ -39481,7 +39478,22 @@ Display messages in reverse order. Include delivered recipients in queue listing. .endlist +The following options give alternates for configuration: + +.vlist +.vitem &*-C*&&~<&'config file'&> +is used to specify an alternate &_exim.conf_& which might +contain alternate exim configuration the queue management might be using. + +.vitem &*-E*&&~<&'path'&> +can be used to specify a path for the exim binary, +overriding the built-in one. +.endlist + There is one more option, &%-h%&, which outputs a list of options. +.new +At least one selection option, or either the &*-c*& or &*-h*& option, must be given. +.wen diff --git a/src/src/exiqgrep.src b/src/src/exiqgrep.src index 9fee423e4..9dfa2c735 100644 --- a/src/src/exiqgrep.src +++ b/src/src/exiqgrep.src @@ -55,12 +55,14 @@ if ($ARGV[0] eq '--version') { exit 0; } -if (!getopts('hf:r:y:o:s:C:zxlibRcaG:',\%opt) { &help; exit;} -if ($ARGV[0]) { &help; exit;} -if ($opt{h}) { &help; exit;} +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(); @@ -77,6 +79,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) diff --git a/test/README b/test/README index bca17eb18..ab9fb6496 100644 --- a/test/README +++ b/test/README @@ -747,6 +747,12 @@ This command runs the exigrep utility with the given data (the search pattern) on the current mainlog file. + exiqgrep + +This command runs the exiqgrep utility with the given options +on the current spool directory. + + gnutls This command is present at the start of all but one of the tests that use diff --git a/test/runtest b/test/runtest index 2ac6198eb..f0fc25f75 100755 --- a/test/runtest +++ b/test/runtest @@ -2416,6 +2416,17 @@ if (/^exigrep\s+(.*)/) } +# The "exiqgrep" command runs exiqgrep on the current spool + +if (/^exiqgrep(\s+.*)?/) + { + run_system("(./eximdir/exiqgrep -E ./eximdir/exim -C $parm_cwd/test-config" . ($1 || '') . ";" . + "echo exiqgrep exit code = \$?)" . + ">>test-stdout"); + return 1; + } + + # The "eximstats" command runs eximstats on the current mainlog if (/^eximstats\s+(.*)/) @@ -3798,7 +3809,7 @@ if (defined $parm_lookups{dbm} && not cp("$parm_exim_dir/exim_dbmbuild", "eximdi $dbm_build_deleted = 1; } -foreach my $tool (qw(exim_dumpdb exim_lock exinext exigrep eximstats)) { +foreach my $tool (qw(exim_dumpdb exim_lock exinext exigrep eximstats exiqgrep)) { cp("$parm_exim_dir/$tool" => "eximdir/$tool") or tests_exit(-1, "Failed to make a copy of $tool: $!"); } @@ -3806,7 +3817,7 @@ foreach my $tool (qw(exim_dumpdb exim_lock exinext exigrep eximstats)) { # Collect some version information print '-' x 78, "\n"; print "Perl version for runtest: $]\n"; -foreach (map { "./eximdir/$_" } qw(exigrep exinext eximstats)) { +foreach (map { "./eximdir/$_" } qw(exigrep exinext eximstats exiqgrep)) { # fold (or unfold?) multiline output into a one-liner print join(', ', map { chomp; $_ } `$_ --version`), "\n"; } diff --git a/test/scripts/0000-Basic/0611 b/test/scripts/0000-Basic/0611 index c35284147..40d08fcf1 100644 --- a/test/scripts/0000-Basic/0611 +++ b/test/scripts/0000-Basic/0611 @@ -6,6 +6,12 @@ need_ipv4 exim -odq a b c . **** +# Check that exiqgrep does not fall over, refuses no selectors, and can count. +exiqgrep -h +exiqgrep -r '[bc]' +exiqgrep +exiqgrep -c -r a +exiqgrep -c # # a slow server as a test target exim -DSERVER=server -bd -oX PORT_D diff --git a/test/stdout/0611 b/test/stdout/0611 new file mode 100644 index 000000000..11867c03a --- /dev/null +++ b/test/stdout/0611 @@ -0,0 +1,62 @@ +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) + -r Match recipient address + -s Match against the size field from long output + -y Message younger than + -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 // ] + +Display options: + -c Display match count + -l Long Format [Default] + -i Message IDs only + -b Brief Format + -R Reverse order + -a All recipients (including delivered) +exiqgrep exit code = 0 + 0m sss 10HmaX-0005vi-00 + a@test.ex + b@test.ex + c@test.ex + +exiqgrep exit code = 0 +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) + -r Match recipient address + -s Match against the size field from long output + -y Message younger than + -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 // ] + +Display options: + -c Display match count + -l Long Format [Default] + -i Message IDs only + -b Brief Format + -R Reverse order + -a All recipients (including delivered) +exiqgrep exit code = 1 +1 matches out of 1 messages +exiqgrep exit code = 0 +1 matches out of 1 messages +exiqgrep exit code = 0 -- 2.30.2