1#!/bin/sh 2# $Id: new_fax.in,v 1.1 2002/03/09 04:25:17 mrsam Exp $ 3# 4# Install this script as mgetty+sendfax's new_fax script (usually in 5# /usr/local/lib/etc/mgetty+sendfax, or /etc/mgetty+sendfax), to automatically 6# convert incoming faxes to PNG attachments, and mailing them 7 8prefix="@prefix@" 9exec_prefix="@exec_prefix@" 10bindir="@bindir@" 11sysconfdir="@sysconfdir@" 12 13. $sysconfdir/faxnotifyrc 14 15if test "$3" -lt 1 16then 17 exit 0 18fi 19 20makemessage() { 21 22STATUS="$1" 23shift 24FAXID="$1" 25shift 26PAGES="$1" 27shift 28 29echo "To: $TOHDR" 30echo "From: $FROMHDR" 31echo "Subject: $SUBJECTHDR" 32echo "Mime-Version: 1.0" 33echo "Content-Type: multipart/mixed; boundary=courierfax" 34echo "" 35echo "This is a MIME formatted message" 36echo "" 37echo "--courierfax" 38 39 40FILE="$1" 41BASENAME="`echo $1 | @SED@ 's:.*/::'`" 42RES="`echo $BASENAME | @CUT@ -c2`" 43TTY="`echo $BASENAME | @SED@ 's/-.*//;s/.*\(..\)$/\1/'`" 44FAXID="`echo $BASENAME | @SED@ 's/^[^-]*-//;s/\.[0-9][0-9]*$//'`" 45 46if test "$RES" = "f" 47then 48 RES="Fine" 49else 50 RES="Low" 51fi 52 53( 54 55if test "$STATUS" = 0 56then 57 : 58else 59 echo "PARTIAL FAX - TRANSMISSION INTERRUPTED AFTER $PAGES PAGES" 60fi 61 62echo "" 63echo "Pages: $PAGES" 64echo "Resolution: $RES" 65echo "Modem line: tty$TTY" 66 67if test "$FAXID" = "" 68then 69 : 70else 71 echo "Sender's FAX ID: $FAXID" 72fi 73echo "" 74) | @bindir@/makemime -c "text/plain" -e "quoted-printable" - 75 76PAGENUM=1 77 78while test $PAGENUM -le $PAGES 79do 80 echo "" 81 echo "--courierfax" 82 83 FILE="$1" 84 BASENAME="`echo $1 | @SED@ 's:.*/::'`" 85 RES="`echo $BASENAME | @CUT@ -c2`" 86 87 if test -f "$FILE" 88 then 89 if test "$RES" = "f" 90 then 91 RES="" 92 else 93 RES="-s" 94 fi 95 96 @G3TOPBM@ $RES $FILE | @PNMTOPNG@ | \ 97 @bindir@/makemime -c "image/png" -e "base64" \ 98 -N "Page $PAGENUM" \ 99 -a "Content-Disposition: attachment; filename=\"page$PAGENUM.png\"" - 100 else 101 echo "ERROR: $FILE - not found" | makemime -c "text/plain" -e "quoted-printable" - 102 fi 103 104 PAGENUM=`expr $PAGENUM + 1` 105 shift 106done 107 108echo "" 109echo "--courierfax--" 110} 111 112makemessage "$@" | $bindir/sendmail -f "$MAILFROM" "$RCPTTO" 113 114if test $? = 0 115then 116 if test "$DODELETE" = 1 117 then 118 shift 3 119 while test $# -gt 0 120 do 121 rm -f "$1" 122 shift 123 done 124 fi 125fi 126 127