| |
| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; # added extra space |
| 3 |
use Getopt::Std; # added extra space here too |
| 4 |
|
| 5 |
sub print_usage # and here |
| 6 |
{ # and here |
| 7 |
print @_; and here |
| 8 |
print STDERR "Usage $0 |
| 9 |
-r <recipient>[,<recipient>.... ] |
| 10 |
-b <binary file to send>[,<binary file to send>....] |
| 11 |
-f <text file to send>[,<text file to send>.....] |
| 12 |
-s <subject> |
| 13 |
-t <Message Text> |
| 14 |
-i <Message Text as file>"; |
| 15 |
die "\n"; |
| 16 |
} |
| 17 |
|
| 18 |
my %opts; |
| 19 |
getopt 'rbfsti', \%opts; |
| 20 |
defined $opts{'r'} or print_usage "No recipent(s) defined\n"; |
| 21 |
my $recips = join " ", (split /,/, $opts{'r'}); |
| 22 |
|
| 23 |
my $boundary = "Message-Boundary-$$"; |
| 24 |
my $uname = `whoami`; |
| 25 |
my $host = `uname -n`; |
| 26 |
chomp $uname; |
| 27 |
chomp $host; |
| 28 |
my $fullname; |
| 29 |
open IFH, "/etc/passwd" or print_usage "Can't open /etc/passwd\n"; |
| 30 |
foreach (<IFH>) |
| 31 |
{ |
| 32 |
/^${uname}:[^:]+:[^:]+:[^:]+:([^:]+)/ and $fullname = $1, last; |
| 33 |
} |
| 34 |
close IFH; |
| 35 |
|
| 36 |
defined $opts{'i'} and do |
| 37 |
{ -r $opts{'i'} or print_usage "Unable to open $opts{'i'}\n"; }; |
| 38 |
defined $opts{'f'} and do |
| 39 |
{ |
| 40 |
foreach my $tfile ( split /,/, $opts{'f'} ) |
| 41 |
{ -r $tfile or print_usage "Unable to open $tfile\n"; } |
| 42 |
}; |
| 43 |
defined $opts{'b'} and do |
| 44 |
{ |
| 45 |
foreach my $tfile ( split /,/, $opts{'b'} ) |
| 46 |
{ -r $tfile or print_usage "Unable to open $tfile\n"; } |
| 47 |
}; |
| 48 |
open OFH, "|sendmail $recips" or print_usage "Unable to open pipe to sendmail\n"; |
| 49 |
print OFH "From: $fullname\n"; |
| 50 |
print OFH "To: $recips\n"; |
| 51 |
print OFH "Subject: "; |
| 52 |
defined $opts{'s'} and print OFH "$opts{'s'}\n" or print OFH "\n"; |
| 53 |
print OFH "Content-Type:Multipart/Mixed; boundary=$boundary\n\n"; |
| 54 |
defined $opts{'t'}|| defined $opts{'i'} and do |
| 55 |
{ |
| 56 |
print OFH "--$boundary\n"; |
| 57 |
print OFH "Content-type: text/plain; charset=US-ASCII\n"; |
| 58 |
print OFH "Content-transfer-encoding: 7BIT\n"; |
| 59 |
print OFH "Content-description: Read Me First\n\n\n"; |
| 60 |
defined $opts{'t'} and print OFH "$opts{'t'}\n"; |
| 61 |
defined $opts{'i'} and do |
| 62 |
{ |
| 63 |
open IFH, $opts{'i'} or print_usage "Unable to open $opts{'i'}\n"; |
| 64 |
foreach (<IFH>) { print OFH; } |
| 65 |
close IFH; |
| 66 |
}; |
| 67 |
}; |
| 68 |
defined $opts{'b'} and do |
| 69 |
{ |
| 70 |
foreach my $file ( split /,/, $opts{'b'} ) |
| 71 |
{ |
| 72 |
my $shortname; |
| 73 |
$file =~ /([^\/]+)$/ and $shortname = $1; |
| 74 |
print OFH "--$boundary\n"; |
| 75 |
print OFH "Content-type: Application/Octet-stream; name=$shortname; type=binary\n"; |
| 76 |
print OFH "Content-disposition: attachment; filename=$shortname\n"; |
| 77 |
print OFH "Content-transfer-encoding: X-UUencode\n\n"; |
| 78 |
print OFH `uuencode $file $file`; |
| 79 |
} |
| 80 |
}; |
| 81 |
defined $opts{'f'} and do |
| 82 |
{ |
| 83 |
foreach my $file ( split /,/, $opts{'f'} ) |
| 84 |
{ |
| 85 |
my $shortname; |
| 86 |
$file =~ /([^\/]+)$/ and $shortname = $1; |
| 87 |
print OFH "--$boundary\n"; |
| 88 |
print OFH "Content-type: Application/Octet-stream; name=$shortname; type=text\n"; |
| 89 |
print OFH "Content-disposition: attachment; filename=$shortname\n\n"; |
| 90 |
open IFH, $file or print_usage "Unable to open $file\n"; |
| 91 |
foreach (<IFH>) |
| 92 |
{ |
| 93 |
chomp; |
| 94 |
print OFH "$_\r\n"; |
| 95 |
} |
| 96 |
close IFH; |
| 97 |
} |
| 98 |
}; |
| 99 |
close OFH; |
| |