diff options
author | Jonas Smedegaard <dr@jones.dk> | 2001-12-12 19:52:40 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2001-12-12 19:52:40 +0000 |
commit | c81b7f986867db292d62a1757123723b5ef66518 (patch) | |
tree | a217cf2f481ab7b3099ef76b519a4cc8e1786096 /faxrcvd-mail |
Initial revision
Diffstat (limited to 'faxrcvd-mail')
-rwxr-xr-x | faxrcvd-mail | 147 |
1 files changed, 147 insertions, 0 deletions
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 <noel@burton-krahn.com> +# Sept 4, 1999 +# +# Tweaks by Jonas Smedegaard <dr@jones.dk> +# 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 <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 + |