- #! /usr/bin/perl -w
- #
- # /var/spool/fax/bin/faxrcvd-mail
- # Noel Burton-Krahn <noel@burton-krahn.com>
- # Sept 4, 1999
- #
- # Modifications by Jonas Smedegaard <dr@jones.dk>
- # 2001-2002
- #
- # $Id: faxrcvd-mail,v 1.2 2002-03-07 16:22:51 jonas Exp $
- #
- # a replacement for hylafax's faxrcvd which sends the whole fax by email
- #
- use strict;
- my($filebase, $filetype, $device, $commid, $msg, $toaddr, $fromaddr, $sentaddr) = @ARGV;
- if( !defined $fromaddr ) { die("Usage: faxrcvd-mail <filebase> <filetype> <device> <coomid> <msg> <toaddr> <fromaddr> [<sentaddr>]") };
- if( !defined $sentaddr ) { $sentaddr="" };
- open(STDOUT, "|/usr/sbin/sendmail -oi -f$fromaddr $toaddr") || die("/usr/sbin/sendmail -oi -f$fromaddr $toaddr: $!");
- my(%info, $info);
- my($boundary);
- $boundary=join('---',
- "=Boundary=",
- $$,
- sprintf('%x', rand(0xffffffff)));
- open(IN, "/usr/sbin/faxinfo $filebase.tif|") || die("/usr/sbin/faxinfo $filebase.tif: $!");
- while(<IN>) {
- $info .= $_;
- $info{lc($1)} = $2 if( /^\s*(\S+): (.*)$/ );
- }
- close(IN) || die("/usr/sbin/faxinfo: $?");
- my($subject) = "FAX from $info{sender}";
- if( $sentaddr ne "" ) { $subject .= " (dispatched to $sentaddr)" };
- print <<EOF
- From: The HylaFAX Receive Agent < $fromaddr >
- To: $toaddr
- Subject: $subject
- Mime-Version: 1.0
- Content-Type: Multipart/Mixed; Boundary=\"$boundary\"
- Content-Transfer-Encoding: 7bit
- This is a multi-part message in MIME format.
- --$boundary
- Content-Type: text/plain; charset=us-ascii
- Content-Description: FAX information
- Content-Transfer-Encoding: 7bit
- File on host is: $info
-
- EOF
- ;
- if( $msg ne "" ) {
- print <<EOF
- The full document was not received because:
- $msg
- EOF
- ;
- }
- if( $sentaddr ne "" ) {
- print <<EOF
- The facsimile was automatically dispatched to: $sentaddr.
- EOF
- ;
- } else {
- # Attach fax and log
- # TODO: code this smarter!
- for ($filetype) {
- /^pdf$/ and -f "$filebase.pdf" and do {
- print <<EOF
- --$boundary
- Content-Type: application/pdf; name="$filebase.pdf"
- Content-Description: FAX from $info{sender}
- Content-Transfer-Encoding: base64
- Content-Disposition: attachment; filename="$filebase.pdf"
- EOF
- ;
- open(IN, "mimencode $filebase.pdf |") || die ("couldn't mimencode $filebase.pdf: $!");
- print while(<IN>);
- close(IN) || die("mimencode: $?");
- next;
- };
- /^ps$/ and -f "$filebase.ps" and do {
- print <<EOF
- --$boundary
- Content-Type: application/postscript; name="$filebase.ps"
- Content-Description: FAX from $info{sender}
- Content-Transfer-Encoding: base64
- Content-Disposition: attachment; filename="$filebase.ps"
- EOF
- ;
- open(IN, "mimencode $filebase.ps |") || die ("couldn't mimencode $filebase.ps: $!");
- print while(<IN>);
- close(IN) || die("mimencode: $?");
- next;
- };
- /^tif$/ and -f "$filebase.tif" and do {
- print <<EOF
- --$boundary
- Content-Type: image/tiff; name="$filebase.tif"
- Content-Description: FAX from $info{sender}
- Content-Transfer-Encoding: base64
- Content-Disposition: attachment; filename="$filebase.tif"
- EOF
- ;
- open(IN, "mimencode $filebase.tif |") || die ("couldn't mimencode $filebase.tif: $!");
- print while(<IN>);
- close(IN) || die("mimencode: $?");
- next;
- };
- # default: output the tif file
- die "Unsupported filetype \"$filetype\"!";
- }
- if( open(IN, "<log/c$commid") ) {
- print <<EOF
- --$boundary
- Content-Type: text/plain; charset=us-ascii
- Content-Description: Reception log
- Content-Transfer-Encoding: 7bit
- ---- Transcript of session follows ----
- EOF
- ;
- print while(<IN>);
- close(IN);
- }
- }; # end of part possibly dispatched
- print <<EOF
- --$boundary--
- EOF
|