I have written a Perl program to that receives and forwards email to a fax number specified in the subject line. This is executed via /etc/aliases on a particular userid. The install looks like this:
fax: "| /usr/local/bin/faxout.pl"
The email has a TIFF attachment, which is extracted, decoded from base64 back to TIFF, and faxed to the number on the subject line. I am not a MIME expert and have used my own test data to debug what to do. I may be missing some big issues that will arrive shortly after implementation.
My code is running on Perl 5.8 under RedHat Linux 8. I seek advice on the Perl code itself, and what MIME issues that I didn't code for.
Here is the code. Thanks in advance!
#!/usr/bin/perl -w # # /usr/local/bin/faxout.pl [debug] # # Script to parse email and send as a fax. Looks to the Subject: lin +e # for /name= /fax= information. The fax number extracted is used to c +all # /usr/bin/sendfax with the correct number to dial. # The fax attachment is extracted and decoded from base64 back to tiff # before being sent to sendfax. # # Parameters: # debug - set debug on # use strict; local (*MAIL); my ($name,$faxno,$appno); my ($cboundary,$cencode); # set the debug parm. my $DEBUG = (shift @ARGV || 0); while (my $line := <>) { # read each line of the email # Extract the Subject: line information if ($line =~ /^Subject:/) { print "\n$line" if $DEBUG; ($name,$faxno,$appno) = $line =~ /\/name=(.*)\/fax=(.*)\/app#=(.*) +$/; print "$name\n$faxno\n$appno\n" if $DEBUG; } # Extract the boundary information if ($line =~ /^ boundary=/) { print "\n$line" if $DEBUG; ($cboundary) = $line =~ /"(.*)"/; print "$cboundary\n" if $DEBUG; } # verify the attachment's encoding is base64 if ($line =~ /^Content-transfer-encoding:/) { print "\n$line" if $DEBUG; ($cencode) = $line =~ / (.*)$/; print "$cencode\n" if $DEBUG; next if ($cencode ne "base64"); # ready to read and decode the encoded attachment # # setup a pipe to decode the attachment and write the data to temp +. open MAIL, "| /usr/bin/uudecode -o /var/tmp/uu.$$"; print MAIL "\nbegin-base64 644 tmp\n"; # necessary begin marker while (<>) { next if /^$/; # skip blank lines. next if /$cboundary/; # skip boundary lines. print MAIL; } print MAIL "====\n"; # necessary end marker close MAIL; } } # submit the fax and remove the temp file. my @args = ("/usr/bin/sendfax", "-mnd", "$name\@$faxno", "/var/tmp/uu. +$$"); system @args; unlink "/var/tmp/uu.$$";
In reply to Fax out service by Lhamo Latso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |