Dear Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.