C
:crp:
This perl script goes through a list of files in IFILE and for each file, it sends it on to sendmail. Attachments need special handling and are signified in the email-file by having a line start with 3@ folowed by the name of the file that should be attached.
1) There has to be a way of doing this without all those system calls, no?
2) this Line does not always get processed:
"cp $base /usr/mailAttached/`date +%d`/"
3) sometimes the text string of
; type=Binary
gets added after the basename in the output of OFILE. The result is
Content-type: Application/octet-stream; name=Cycle108.zip; type=Binary
instead of
Content-type: Application/octet-stream; name=Cycle108.zip
this hurts as several email clients seem to have problems parsing the attached filename correctly.
Thanks.
There are 3 problems:{
open IFILE,"$ifile";
$ofile="$_.mail";
open OFILE,">$ofile";
$fromaddr="PostMaster\@afts.com";
while(<IFILE>)
{
chomp;
if(substr($_,0,3) eq "\@\@\@")
{
chomp($basename=substr($_,3,(length $_)-4));
chomp($aname="/mnt/opserve/automail/ATTACH/" . $basename);
chomp($base="$aname.base64");
system "cat $aname | /usr/bin/mimencode -o $base";
print OFILE "\n--Message-Boundary--\n";
print OFILE "Content-type: Application/octet-stream; name=\"$basename\"\n";
print OFILE "Content-transfer-encoding: BASE64\n\n";
close OFILE;
system "cat $base >> $ofile";
open OFILE,">>$ofile";
system "cp $base /usr/mailAttached/`date +%d`/";
system "rm -f $base";
system "rm -f $aname";
print OFILE "\n--Message-Boundary--\n";
};
if(substr($_,0,5) eq "From:")
{
$fromaddr=(substr($_,5));
};
if(substr($_,0,3) ne "\@\@\@")
{
print OFILE $_ ."\n";
};
}
close IFILE;
1) There has to be a way of doing this without all those system calls, no?
2) this Line does not always get processed:
"cp $base /usr/mailAttached/`date +%d`/"
3) sometimes the text string of
; type=Binary
gets added after the basename in the output of OFILE. The result is
Content-type: Application/octet-stream; name=Cycle108.zip; type=Binary
instead of
Content-type: Application/octet-stream; name=Cycle108.zip
this hurts as several email clients seem to have problems parsing the attached filename correctly.
Thanks.