Skip to content

Instantly share code, notes, and snippets.

@jlav1n
Created March 10, 2017 17:20
Show Gist options
  • Save jlav1n/93cc3f096fa650d6d1443ed017efdbd2 to your computer and use it in GitHub Desktop.
Save jlav1n/93cc3f096fa650d6d1443ed017efdbd2 to your computer and use it in GitHub Desktop.
#!/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