[exim-cvs] exim_msgdate: more options, better perl version …

Top Page
Delete this message
Reply to this message
Author: Exim Git Commits Mailing List
Date:  
To: exim-cvs
Subject: [exim-cvs] exim_msgdate: more options, better perl version compatibility
Gitweb: https://git.exim.org/exim.git/commitdiff/bd0f95ded48f560cb1f9f8b808e1abaabeb4d4ec
Commit:     bd0f95ded48f560cb1f9f8b808e1abaabeb4d4ec
Parent:     f95cf0d24bbb6faaa74f449759d089601dbab892
Author:     Andrew Aitchison <exim@???>
AuthorDate: Sat Mar 4 17:23:09 2023 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sat Mar 4 17:29:00 2023 +0000


    exim_msgdate: more options, better perl version compatibility
---
 src/src/exim_msgdate.src     | 60 +++++++++++++++++++++++++++++++++-----------
 test/runtest                 |  2 +-
 test/scripts/0000-Basic/0700 |  2 +-
 test/stderr/0700             |  1 +
 test/stdout/0700             |  1 -
 5 files changed, 49 insertions(+), 17 deletions(-)


diff --git a/src/src/exim_msgdate.src b/src/src/exim_msgdate.src
index e5c357bca..c591f306e 100755
--- a/src/src/exim_msgdate.src
+++ b/src/src/exim_msgdate.src
@@ -1,4 +1,4 @@
-#!PERL_COMMAND -WT
+#!PERL_COMMAND -T
#
# Utility to convert an exim message-id to a human readable form
#
@@ -27,6 +27,11 @@
#
# PROCESSED_FLAG

+# These match runtest
+use v5.10.1;
+use warnings;
+use if $^V >= v5.19.11, experimental => 'smartmatch';
+
use strict;
use File::Basename;
use Getopt::Long;
@@ -48,6 +53,7 @@ if (defined $ENV{TZ}) {
}

my $localhost_number; # An Exim config value
+my $nolocalhost_number;

 my $p_name    = basename $0;
 my $p_version = "20230203.0";
@@ -56,20 +62,13 @@ my $p_cp      = <<EOM;


  Portions taken from exicyclog.src, which is
    Copyright (c) University of Cambridge, 1995 - 2015
-   See the file NOTICE for conditions of use and distribution.
+ See the file NOTICE for conditions of use and distribution.
 EOM


$ENV{PATH} = "/bin:/usr/bin:/usr/sbin";

use POSIX qw(strftime);

-sub main::VERSION_MESSAGE()
-{
-    print basename($0), ": $0\n";
-    print "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION\n";
-    print "perl(          runtime): $]\n";
-}
-
 my ($debug, $nodebug,
     $optbase, $optbase36, $optbase62,
     $optunix, $optgmt, $optlocal,
@@ -95,6 +94,9 @@ GetOptions (
     "base62" => \$optbase62,


     "localhost_number=s" => \$localhost_number,  # cf "local"
+    "nolocalhost_number" => \$nolocalhost_number,
+    "no-localhost_number" => \$nolocalhost_number,
+    "no_localhost_number" => \$nolocalhost_number,


     "unix" => \$optunix,
     "u" => \$optunix,
@@ -122,6 +124,11 @@ GetOptions (
             -noperldoc => system('perldoc -V 2>/dev/null 1>&2')
        );
     },
+    'version'  => sub {
+    print basename($0), ": $0\n";
+    print "build: EXIM_RELEASE_VERSIONEXIM_VARIANT_VERSION\n";
+    print "perl(runtime): $]\n";
+    },
 ) or pod2usage;
 # die("Error in command line arguments\n");


@@ -270,13 +277,27 @@ if ($debug) {
     } else {
         warn "localhost_number unset\n";
     }
+    if (defined $nolocalhost_number) {
+        warn "nolocalhost_number=$nolocalhost_number\n";
+    } else {
+        warn "nolocalhost_number unset\n";
+    }
 }


 if (defined $localhost_number) {
     if ($localhost_number eq "none") {
         $localhost_number = undef;
+        $nolocalhost_number = TRUE;
+    } else {
+    if ($nolocalhost_number) {
+        die "aborting: localhost_number and nolocalhost_number both set\n ";
+    }
+        $nolocalhost_number = FALSE;
     }
-} else {
+}
+
+unless (defined $nolocalhost_number) {
+    warn "Looking for config file\n" if $debug;
     my $config = get_configfilename();
     warn "Reading config $config to find localhost_number\n" if $debug;


@@ -296,6 +317,9 @@ if (defined $localhost_number) {
         warn "$config gives localhost_number $localhost_number\n"
             if $debug and defined $localhost_number;
     } else {
+    if ($debug) {
+        warn "cannot read config file $config\n";
+    }
         # This way we get the expanded value for localhost_number
         # directly from exim, but we have to guess which exim binary ...
         # On Debian and Ubuntu, /usr/sbin/exim is a link to exim4 so is OK.
@@ -315,10 +339,18 @@ if (defined $localhost_number) {
 }


 if (defined $localhost_number) {
-    die "localhost_number > 16\n"
-        if $localhost_number > 16;
-    die "localhost_number > 10\n"
-        if $localhost_number > 10 && ($base != 62);
+    if ($localhost_number =~ /\D/) {
+    die "localhost_number must be a number >=0\n";
+    } elsif ($localhost_number =~ /^\d*$/) {
+    die "localhost_number > 16\n"
+        if $localhost_number > 16;
+    die "localhost_number > 10\n"
+        if $localhost_number > 10 && ($base != 62);
+    } else {
+    warn "clearing localhost_number - was $localhost_number\n";
+    undef $localhost_number;
+    $nolocalhost_number=TRUE;
+    }
 }


 if ($debug) {
diff --git a/test/runtest b/test/runtest
index 137f8dac6..82ae480ce 100755
--- a/test/runtest
+++ b/test/runtest
@@ -3920,7 +3920,7 @@ foreach my $tool (qw(exim_dumpdb exim_lock exinext exigrep eximstats exiqgrep ex
 # Collect some version information
 print '-' x 78, "\n";
 print "Perl version for runtest: $]\n";
-foreach (map { "./eximdir/$_" } qw(exigrep exinext eximstats exiqgrep)) {
+foreach (map { "./eximdir/$_" } qw(exigrep exinext eximstats exiqgrep exim_msgdate)) {
   # fold (or unfold?) multiline output into a one-liner
   print join(', ', map { chomp; $_ } `$_ --version`), "\n";
 }
diff --git a/test/scripts/0000-Basic/0700 b/test/scripts/0000-Basic/0700
index 8d4f06976..255e8e209 100644
--- a/test/scripts/0000-Basic/0700
+++ b/test/scripts/0000-Basic/0700
@@ -129,7 +129,7 @@ exim_msgdate --localhost_number 11 -base 36 EZZZZZZ-003FPJ-ZZ
 0 TZ=GB
 exim_msgdate -localhost_number 11 --local -base 62 EZZZZZZ-003FPJ-ZZ
 ****
-0 TZ=GB
+255 TZ=GB
 exim_msgdate --localhost_number -1 -base 36 EZZZZZZ-003FPJ-ZZ
 ****
 255 TZ=GB
diff --git a/test/stderr/0700 b/test/stderr/0700
index 4531d5e2c..f05729b31 100644
--- a/test/stderr/0700
+++ b/test/stderr/0700
@@ -23,6 +23,7 @@ zzzzzzz not parsed
 ### Show the process id too
 ### Override the value of localhost_number set in the exim configuation file
 localhost_number > 10
+localhost_number must be a number >=0
 localhost_number > 16
 ### From here as 701 - 703
 ### Each msg-id type, all zone
diff --git a/test/stdout/0700 b/test/stdout/0700
index 2e47baa35..260a13279 100644
--- a/test/stdout/0700
+++ b/test/stdout/0700
@@ -50,7 +50,6 @@
 3002-09-30 13:51:45.025000 BST
 2038-12-24 05:45:38.950000 GMT
 3002-09-30 13:51:45.025000 BST
-2038-12-24 05:45:48.950000 GMT
 ### From here as 701 - 703
 ### Each msg-id type, all zone
 0.000000    pid 1319504