#!/usr/bin/perl -w # # /usr/local/bin/faxout.pl [debug] # # Script to parse email and send as a fax. Looks to the Subject: line # for /name= /fax= information. The fax number extracted is used to call # /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.$$";