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