need help with inherited script that emails files

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.
{
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;
There are 3 problems:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top