Created
March 10, 2017 17:20
-
-
Save jlav1n/93cc3f096fa650d6d1443ed017efdbd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use File::Temp; | |
my $basedir = "/tmp/sendmail-$ENV{'USER'}"; | |
my $sendmail = '/usr/sbin/sendmail'; | |
my @opts; | |
for(@ARGV) { | |
push @opts, $_; | |
} | |
for(@opts) { shift(@ARGV) } | |
my $opt = join ' ', @opts; | |
umask 2; | |
mkdir $basedir unless -d $basedir; | |
my $tmp = File::Temp->new( DIR => $basedir ); | |
$tmp->unlink_on_destroy(0); | |
my $tmpnam = $tmp->filename; | |
open OUT, "> $tmpnam" | |
or die "Cannot create $tmpnam: $!\n"; | |
my $cmdline = join " ", $sendmail, $opt, '<', $tmpnam, '&'; | |
while(<>) { | |
print OUT $_; | |
} | |
close OUT; | |
system($cmdline); | |
if($?) { | |
die "Failed to fork sendmail: $!\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment