From c81b7f986867db292d62a1757123723b5ef66518 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 12 Dec 2001 19:52:40 +0000 Subject: Initial revision --- faxrcvd-mail | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100755 faxrcvd-mail (limited to 'faxrcvd-mail') diff --git a/faxrcvd-mail b/faxrcvd-mail new file mode 100755 index 0000000..d7ff1ee --- /dev/null +++ b/faxrcvd-mail @@ -0,0 +1,147 @@ +#! /usr/bin/perl -w +# +# /var/spool/fax/bin/faxrcvd-mail +# Noel Burton-Krahn +# Sept 4, 1999 +# +# Tweaks by Jonas Smedegaard +# fall 2001 +# +# 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 <