]> git.donarmstrong.com Git - bin.git/commitdiff
handle nullmailer versions ≥ 2.0
authorDon Armstrong <don@donarmstrong.com>
Sat, 6 Jan 2018 00:02:30 +0000 (16:02 -0800)
committerDon Armstrong <don@donarmstrong.com>
Sat, 6 Jan 2018 00:02:30 +0000 (16:02 -0800)
sshsendmail

index 62565968d906f39a1da632431e5ba15bced43a8a..25330fc27328166b70c6fa1fd54f24d1ecf8368e 100755 (executable)
@@ -87,7 +87,21 @@ my %options = (debug              => 0,
                'sendmail_options' => [],
              );
 
+my $new_nullmailer = 0;
+## The new nullmailer passes options on STDIN and the message on FD 3.
+my $message_fd = \*STDIN;
+eval {
+    my $fh = IO::Handle->new() or
+        die "Unable to create new fd";
+    $fh->fdopen(3,"r") or
+        die "Unable to open fd 3: $!";
+    $message_fd = $fh;
+    $new_nullmailer = 1;
+    push @ARGV, map {chomp; "--$_"} <STDIN>;
+};
+
 GetOptions(\%options,'identity|i=s','username|l=s','daemon|d', 'syslog|s',
+           'host=s',
            'sendmail_options|sendmail-options|o=s@',
            'help|h|?','man|m');
 
@@ -96,7 +110,7 @@ pod2usage({verbose=>2}) if $options{man};
 
 $DEBUG = $options{debug};
 
-if (not @ARGV) {
+if (not (@ARGV or defined $options{host})) {
      print STDERR "${0}: Too few command-line arguments\n";
      print <<END;
 usage: ${0} [flags] remote-address < mail-file
@@ -110,9 +124,11 @@ END
      exit(1);
 }
 
-my $hostname = shift @ARGV;
+if (not defined $options{host} and @ARGV) {
+    $options{host} = shift @ARGV;
+}
 
-my @message = <>;
+my @message = <$message_fd>;
 #throw away envelope sender
 shift @message;
 my @recipients;
@@ -125,7 +141,7 @@ while (my $line = shift @message) {
 
 @recipients = qw(-t) if not @recipients;
 
-my @ssh_arguments = ($hostname);
+my @ssh_arguments = ($options{host});
 
 push @ssh_arguments, '-i', $options{identity} if defined $options{identity};
 push @ssh_arguments, '-l', $options{username} if defined $options{username};
@@ -164,9 +180,9 @@ EOF
 $Data::Dumper::Useqq=0;
 print STDERR Dumper(\@ssh_arguments) if $DEBUG;
 
-qx(ping -q -w 3 -c 1 $hostname 2>/dev/null);
+qx(ping -q -w 3 -c 1 $options{host} 2>/dev/null);
 if ($?) {
-    syslog(LOG_WARNING,"${0}: Failed: unable to ping $hostname\n");
+    syslog(LOG_WARNING,"${0}: Failed: unable to ping $options{host}\n");
     exit (9);
 }
 print STDERR md5_hex(join('',@message))."\n" if $DEBUG;