#! /usr/bin/perl -w # # /var/spool/fax/bin/faxrcvd-mail # Noel Burton-Krahn # Sept 4, 1999 # # Modifications by Jonas Smedegaard # 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 []") }; 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() { $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 < 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 <); close(IN) || die("mimencode: $?"); next; }; /^ps$/ and -f "$filebase.ps" and do { print <); close(IN) || die("mimencode: $?"); next; }; /^tif$/ and -f "$filebase.tif" and do { print <); close(IN) || die("mimencode: $?"); next; }; # default: output the tif file die "Unsupported filetype \"$filetype\"!"; } if( open(IN, "); close(IN); } }; # end of part possibly dispatched print <