#!/usr/local/bin/perl
package sendmail;
$location = "/usr/sbin/sendmail";
@option = ("-t", "-n", "-oi");
sub send{
local($content, %header) = @_;
# get FROM and TO address(needed).
return 0 unless($from = $header{'From'});
return 0 unless($to = $header{'To'});
# remove unexpected char..
$from =~ tr/\x00-\x1F//d;
$to =~ tr/\x00-\x1F//d;
$location =~ tr/\x00-\x1F\x7F-\xFF\(\)'`$"~|;*?\\//d;
$option =~ tr/[^\-a-zA-Z]//d;
# put "(no subject)" if Subject isn't specified.
$header{'Subject'} = '(no subject)' unless $header{'Subject'};
#if(open(MAIL, "| $location $option '$header{'To'}'")){
if(open(MAIL, "|-") || exec $location, @option, $header{'To'}, $header{'Cc'}, $header{'Bcc'}){
# Print From, To, Subject first..
foreach('To', 'From', 'Subject'){
# remove unexpected char..
$header{$_} =~ tr/\x00-\x1F//d;
print MAIL "$_: $header{$_}\n";
delete $header{$_};
}
# Print other Header..
foreach(sort keys %header){
# remove unexpected char..
tr/\r\n//d;
$header{$_} =~ tr/\x00-\x1F//d;
print MAIL "$_: $header{$_}\n";
}
# Print blank line..
print MAIL "\n";
# Print Content..
print MAIL $content;
}else{
return 0;
}
1;
}
1;