summaryrefslogtreecommitdiff
path: root/faxrcvd-mail
blob: 350cbefb954494773044db45731f6c306dbdf7b7 (plain)
  1. #! /usr/bin/perl -w
  2. #
  3. # /var/spool/fax/bin/faxrcvd-mail
  4. # Noel Burton-Krahn <noel@burton-krahn.com>
  5. # Sept 4, 1999
  6. #
  7. # Modifications by Jonas Smedegaard <dr@jones.dk>
  8. # 2001-2002
  9. #
  10. # $Id: faxrcvd-mail,v 1.2 2002-03-07 16:22:51 jonas Exp $
  11. #
  12. # a replacement for hylafax's faxrcvd which sends the whole fax by email
  13. #
  14. use strict;
  15. my($filebase, $filetype, $device, $commid, $msg, $toaddr, $fromaddr, $sentaddr) = @ARGV;
  16. if( !defined $fromaddr ) { die("Usage: faxrcvd-mail <filebase> <filetype> <device> <coomid> <msg> <toaddr> <fromaddr> [<sentaddr>]") };
  17. if( !defined $sentaddr ) { $sentaddr="" };
  18. open(STDOUT, "|/usr/sbin/sendmail -oi -f$fromaddr $toaddr") || die("/usr/sbin/sendmail -oi -f$fromaddr $toaddr: $!");
  19. my(%info, $info);
  20. my($boundary);
  21. $boundary=join('---',
  22. "=Boundary=",
  23. $$,
  24. sprintf('%x', rand(0xffffffff)));
  25. open(IN, "/usr/sbin/faxinfo $filebase.tif|") || die("/usr/sbin/faxinfo $filebase.tif: $!");
  26. while(<IN>) {
  27. $info .= $_;
  28. $info{lc($1)} = $2 if( /^\s*(\S+): (.*)$/ );
  29. }
  30. close(IN) || die("/usr/sbin/faxinfo: $?");
  31. my($subject) = "FAX from $info{sender}";
  32. if( $sentaddr ne "" ) { $subject .= " (dispatched to $sentaddr)" };
  33. print <<EOF
  34. From: The HylaFAX Receive Agent < $fromaddr >
  35. To: $toaddr
  36. Subject: $subject
  37. Mime-Version: 1.0
  38. Content-Type: Multipart/Mixed; Boundary=\"$boundary\"
  39. Content-Transfer-Encoding: 7bit
  40. This is a multi-part message in MIME format.
  41. --$boundary
  42. Content-Type: text/plain; charset=us-ascii
  43. Content-Description: FAX information
  44. Content-Transfer-Encoding: 7bit
  45. File on host is: $info
  46. EOF
  47. ;
  48. if( $msg ne "" ) {
  49. print <<EOF
  50. The full document was not received because:
  51. $msg
  52. EOF
  53. ;
  54. }
  55. if( $sentaddr ne "" ) {
  56. print <<EOF
  57. The facsimile was automatically dispatched to: $sentaddr.
  58. EOF
  59. ;
  60. } else {
  61. # Attach fax and log
  62. # TODO: code this smarter!
  63. for ($filetype) {
  64. /^pdf$/ and -f "$filebase.pdf" and do {
  65. print <<EOF
  66. --$boundary
  67. Content-Type: application/pdf; name="$filebase.pdf"
  68. Content-Description: FAX from $info{sender}
  69. Content-Transfer-Encoding: base64
  70. Content-Disposition: attachment; filename="$filebase.pdf"
  71. EOF
  72. ;
  73. open(IN, "mimencode $filebase.pdf |") || die ("couldn't mimencode $filebase.pdf: $!");
  74. print while(<IN>);
  75. close(IN) || die("mimencode: $?");
  76. next;
  77. };
  78. /^ps$/ and -f "$filebase.ps" and do {
  79. print <<EOF
  80. --$boundary
  81. Content-Type: application/postscript; name="$filebase.ps"
  82. Content-Description: FAX from $info{sender}
  83. Content-Transfer-Encoding: base64
  84. Content-Disposition: attachment; filename="$filebase.ps"
  85. EOF
  86. ;
  87. open(IN, "mimencode $filebase.ps |") || die ("couldn't mimencode $filebase.ps: $!");
  88. print while(<IN>);
  89. close(IN) || die("mimencode: $?");
  90. next;
  91. };
  92. /^tif$/ and -f "$filebase.tif" and do {
  93. print <<EOF
  94. --$boundary
  95. Content-Type: image/tiff; name="$filebase.tif"
  96. Content-Description: FAX from $info{sender}
  97. Content-Transfer-Encoding: base64
  98. Content-Disposition: attachment; filename="$filebase.tif"
  99. EOF
  100. ;
  101. open(IN, "mimencode $filebase.tif |") || die ("couldn't mimencode $filebase.tif: $!");
  102. print while(<IN>);
  103. close(IN) || die("mimencode: $?");
  104. next;
  105. };
  106. # default: output the tif file
  107. die "Unsupported filetype \"$filetype\"!";
  108. }
  109. if( open(IN, "<log/c$commid") ) {
  110. print <<EOF
  111. --$boundary
  112. Content-Type: text/plain; charset=us-ascii
  113. Content-Description: Reception log
  114. Content-Transfer-Encoding: 7bit
  115. ---- Transcript of session follows ----
  116. EOF
  117. ;
  118. print while(<IN>);
  119. close(IN);
  120. }
  121. }; # end of part possibly dispatched
  122. print <<EOF
  123. --$boundary--
  124. EOF