HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [hylafax-users] emailtofax options



What you're really looking for is a script that uses sendfax rather then trying to use the program faxmail.
Something like this:


#!/bin/sh
#
# simple mail-to-fax utility designed to replace HylaFAX's faxmail
# uses shell, sendfax, metamail, and uudecode
#
# - Lee Howard - NubJub & Marek
# This is a modified version of the script provided by Lee Howard
# on this Hylafax+ website.
#
# HINT: TO COMPLETELY DISABLE COVERPAGES TAKE
# A LOOK AT THE VERY BOTTOM OF THE SCRIPT
#
# I am compelled to point out here that using faxcover to
# automatically generate cover pages using the content of your
# email is pretty great.
#
# It would like to find a hyfax.conf file in etc that looks
# something like this:
#    *********************************************************
#    # Set to 'true' to enable logging; set to 'false' to disable.
#    LOG=true
#    LOG_FILE=/var/log/hyfax.log
#    OUTGOINGFAXNUMBER=XXX-XXX-XXXX
#    *********************************************************
#
# You will also need to create a log file writeable by the user
# your mta will be running with script with.
#
# Mail to addresses work in the formats
#    1) Dispaly Name <PHONE-NUMBER@xxxxxxxxxxx>
#    2) "Display Name" <PHONE-NUMBER@xxxxxxxxxxx>
#
# These formats are really just a matter of the sed parsing of the
# _message_ file and can easily be edited to suit your particular
# preferences.
#
# The formats described above match the 2nd email-to-fax
# configuration described in the file:
# /usr/share/doc/hylafax-client/faxmail/mailfax.sh-postfix.gz
# This script does not have any swtiches so the -d -n
# switches shown in the example should be removed
#
# Mail from addresses are assumed to be in the formats
#    1) Dispaly Name <username@xxxxxxxxxxx>
#    2) "Display Name" <username@xxxxxxxxxxx>
#
# Which are generally the formats used by modern email cients.
#
#
#

if [ -f /etc/hyfax.conf ]
then
   . /etc/hyfax.conf

   if [ "$LOG_FILE" != "" ]
   then
       if [ ! -f $LOG_FILE ]
       then
           LOG=false
       fi
   fi
fi

TIMESTAMP=`/bin/date --iso-8601=seconds`

RANDOMFAX=/tmp/faxtmp.$RANDOM

export METAMAIL_TMPDIR=$RANDOMFAX
if [ ! -d $METAMAIL_TMPDIR ]; then
   mkdir $METAMAIL_TMPDIR;
fi
rm -f $METAMAIL_TMPDIR/*

#
# metamail doesn't understand "multipart/alternative"
#

sed 's/multipart\/alternative/multipart\/mixed/' > $RANDOMFAX/_message_

TOLINE=`grep -e "^to:" -i $RANDOMFAX/_message_ | sed q`
FROMLINE=`grep -e "^from:" -i $RANDOMFAX/_message_ | sed q`
SUBJECT=`grep -e "^subject:" -i $RANDOMFAX/_message_ | sed q | sed -e 's/^[Ss]ubject:[ ]*//g'`


if [ "$LOG" == "true" ]
then
   echo "$TIMESTAMP | to line: $TOLINE" >>$LOG_FILE
   echo "$TIMESTAMP | from line: $FROMLINE" >>$LOG_FILE
fi

if [ "`echo $TOLINE | grep '<.*>'`" != "" ]; then
TONUMBER=`echo $TOLINE| sed -e 's/.*<\(.*\)@[^\.]*.*>.*/\1/'`
else
TONUMBER=`echo $TOLINE| sed -e 's/^[Tt]o://g' -e 's/[ ]*\(.*@[^\.]*\).*/\1/'`
fi


FROM=`echo $FROMLINE | sed -e 's/^[Ff]rom:[ ]*//g' -e 's/"//g'`
# FROMCO=`echo $FROMLINE | sed -e 's/.*"\(.*\)".*/\1/'`
FROMCO=`echo $FROMLINE | sed -e 's/^[Ff]rom:\(.*\)<.*/\1/' -e 's/"//g'`
COMPANY=`echo $TOLINE| sed -e 's/^[Tt]o:\(.*\)<.*/\1/' -e 's/"//g'`
# COMPANY=`echo $TOLINE | sed -e 's/.*"\(.*\)".*/\1/' -e 's/.*<\(.*\)@.*/\1/'`


metamail -w -x $RANDOMFAX/_message_ > /dev/null 2>&1

# We also have to use uudecode, because metamail will only
# help us with mail that has Content-Type headers, although
# uudecode can only handle one attachment.  (Can a
# multi-attachment mail not have Content-Type headers?)

uudecode -o $METAMAIL_TMPDIR/_uudecoded_message_ $RANDOMFAX/_message_ > /dev/null 2>&1

rm -f $RANDOMFAX/_message_

DONE=false
COMMENT=
for FILE in `/bin/ls $RANDOMFAX/1-*`
do
   if [ -f $FILE ]
   then
       if [ "$DONE" != "true" ]
       then
           if [ "$LOG" == "true" ]
           then
               echo "$TIMESTAMP | using: $FILE" >>$LOG_FILE
           fi

/usr/bin/html2text -ascii "$FILE" >"$FILE.tmp.$$"
COMMENT=`/bin/cat "$FILE.tmp.$$" |perl -e 'while (<>) { s/\r//; print; }' |perl -e 'while (<>) { s/\n/ /; print; }'`
COMMENT=`echo $COMMENT`
DONE=true
fi


       if [ "$LOG" == "true" ]
       then
           echo "$TIMESTAMP | removing: $FILE" >>$LOG_FILE
       fi

       /bin/rm -f $FILE
   fi
done

if [ "$LOG" == "true" ]
then
   echo "$TIMESTAMP | removing temp files" >>$LOG_FILE
fi

/bin/rm -rf $RANDOMFAX/*.tmp.$$

if [ "$LOG" == "true" ]
then
   echo "$TIMESTAMP | from: $FROM" >>$LOG_FILE
   echo "$TIMESTAMP | to: $COMPANY" >>$LOG_FILE
   echo "$TIMESTAMP | from-company: $FROMCO" >>$LOG_FILE
   echo "$TIMESTAMP | subject line: $SUBJECT" >>$LOG_FILE
   echo "$TIMESTAMP | number: $TONUMBER" >> $LOG_FILE
   echo "$TIMESTAMP | comment: $COMMENT" >> $LOG_FILE
fi

if [ "$SUBJECT" != "" ]; then
sendfax -R -s na-let -f "$FROM" -X "$FROMCO" -x "$COMPANY" -W "$OUTGOINGFAXNUMBER" -r "$SUBJECT" -c "$COMMENT" -d "$TONUMBER" $METAMAIL_TMPDIR/*
else
sendfax -R -f "$FROM" -n -d "$TONUMBER" $METAMAIL_TMPDIR/*
fi


# To disable coverpages simply compent the above if then else conditional and uncomment the command bellow
# sendfax -R -f "$FROM" -n -d "$TONUMBER" $METAMAIL_TMPDIR/*


#!/bin/sh
#
# simple mail-to-fax utility designed to replace HylaFAX's faxmail
# uses shell, sendfax, metamail, and uudecode
#
# - Lee Howard - NubJub & Marek
# This is a modified version of the script provided by Lee Howard
# on this Hylafax+ website.
#
# HINT: TO COMPLETELY DISABLE COVERPAGES TAKE 
# A LOOK AT THE VERY BOTTOM OF THE SCRIPT
#
# I am compelled to point out here that using faxcover to
# automatically generate cover pages using the content of your 
# email is pretty great. 
# 
# It would like to find a hyfax.conf file in etc that looks
# something like this:
#    *********************************************************
#    # Set to 'true' to enable logging; set to 'false' to disable.
#    LOG=true
#    LOG_FILE=/var/log/hyfax.log
#    OUTGOINGFAXNUMBER=XXX-XXX-XXXX
#    *********************************************************
#
# You will also need to create a log file writeable by the user 
# your mta will be running with script with.
#
# Mail to addresses work in the formats
#	1) Dispaly Name <PHONE-NUMBER@xxxxxxxxxxx>
#	2) "Display Name" <PHONE-NUMBER@xxxxxxxxxxx>
#
# These formats are really just a matter of the sed parsing of the 
# _message_ file and can easily be edited to suit your particular
# preferences.
#
# The formats described above match the 2nd email-to-fax
# configuration described in the file:
# /usr/share/doc/hylafax-client/faxmail/mailfax.sh-postfix.gz
# This script does not have any swtiches so the -d -n
# switches shown in the example should be removed
# 
# Mail from addresses are assumed to be in the formats 
#	1) Dispaly Name <username@xxxxxxxxxxx>
#	2) "Display Name" <username@xxxxxxxxxxx>
# 
# Which are generally the formats used by modern email cients.
# 
#
#

if [ -f /etc/hyfax.conf ]
then
	. /etc/hyfax.conf

	if [ "$LOG_FILE" != "" ]
	then
		if [ ! -f $LOG_FILE ]
		then
			LOG=false
		fi
	fi
fi

TIMESTAMP=`/bin/date --iso-8601=seconds`

RANDOMFAX=/tmp/faxtmp.$RANDOM

export METAMAIL_TMPDIR=$RANDOMFAX
if [ ! -d $METAMAIL_TMPDIR ]; then
	mkdir $METAMAIL_TMPDIR;
fi
rm -f $METAMAIL_TMPDIR/*

#
# metamail doesn't understand "multipart/alternative"
#

sed 's/multipart\/alternative/multipart\/mixed/' > $RANDOMFAX/_message_

TOLINE=`grep -e "^to:" -i $RANDOMFAX/_message_ | sed q`
FROMLINE=`grep -e "^from:" -i $RANDOMFAX/_message_ | sed q`
SUBJECT=`grep -e "^subject:" -i $RANDOMFAX/_message_ | sed q | sed -e 's/^[Ss]ubject:[ ]*//g'`

if [ "$LOG" == "true" ]
then
	echo "$TIMESTAMP | to line: $TOLINE" >>$LOG_FILE
	echo "$TIMESTAMP | from line: $FROMLINE" >>$LOG_FILE
fi

if [ "`echo $TOLINE | grep '<.*>'`" != "" ]; then
	TONUMBER=`echo $TOLINE| sed -e 's/.*<\(.*\)@[^\.]*.*>.*/\1/'`
else
	TONUMBER=`echo $TOLINE| sed -e 's/^[Tt]o://g' -e 's/[ ]*\(.*@[^\.]*\).*/\1/'`
fi

FROM=`echo $FROMLINE | sed -e 's/^[Ff]rom:[ ]*//g' -e 's/"//g'`
# FROMCO=`echo $FROMLINE | sed -e 's/.*"\(.*\)".*/\1/'`
FROMCO=`echo $FROMLINE | sed -e 's/^[Ff]rom:\(.*\)<.*/\1/' -e 's/"//g'`
COMPANY=`echo $TOLINE| sed -e 's/^[Tt]o:\(.*\)<.*/\1/' -e 's/"//g'`
# COMPANY=`echo $TOLINE | sed -e 's/.*"\(.*\)".*/\1/' -e 's/.*<\(.*\)@.*/\1/'`

metamail -w -x $RANDOMFAX/_message_ > /dev/null 2>&1

# We also have to use uudecode, because metamail will only
# help us with mail that has Content-Type headers, although
# uudecode can only handle one attachment.  (Can a
# multi-attachment mail not have Content-Type headers?)

uudecode -o $METAMAIL_TMPDIR/_uudecoded_message_ $RANDOMFAX/_message_ > /dev/null 2>&1

rm -f $RANDOMFAX/_message_

DONE=false
COMMENT=
for FILE in `/bin/ls $RANDOMFAX/1-*`
do
	if [ -f $FILE ]
	then
		if [ "$DONE" != "true" ]
		then
			if [ "$LOG" == "true" ]
			then
				echo "$TIMESTAMP | using: $FILE" >>$LOG_FILE
			fi

			/usr/bin/html2text -ascii "$FILE" >"$FILE.tmp.$$"
			COMMENT=`/bin/cat "$FILE.tmp.$$" |perl -e 'while (<>) { s/\r//; print; }' |perl -e 'while (<>) { s/\n/ /; print; }'`
			COMMENT=`echo $COMMENT`
			DONE=true
		fi

		if [ "$LOG" == "true" ]
		then
			echo "$TIMESTAMP | removing: $FILE" >>$LOG_FILE
		fi

		/bin/rm -f $FILE
	fi
done

if [ "$LOG" == "true" ]
then
	echo "$TIMESTAMP | removing temp files" >>$LOG_FILE
fi

/bin/rm -rf $RANDOMFAX/*.tmp.$$

if [ "$LOG" == "true" ]
then
	echo "$TIMESTAMP | from: $FROM" >>$LOG_FILE
	echo "$TIMESTAMP | to: $COMPANY" >>$LOG_FILE
	echo "$TIMESTAMP | from-company: $FROMCO" >>$LOG_FILE
	echo "$TIMESTAMP | subject line: $SUBJECT" >>$LOG_FILE
	echo "$TIMESTAMP | number: $TONUMBER" >> $LOG_FILE
	echo "$TIMESTAMP | comment: $COMMENT" >> $LOG_FILE
fi

if [ "$SUBJECT" != "" ]; then
	sendfax -R -s na-let -f "$FROM" -X "$FROMCO" -x "$COMPANY" -W "$OUTGOINGFAXNUMBER" -r "$SUBJECT" -c "$COMMENT" -d "$TONUMBER" $METAMAIL_TMPDIR/*
else
	sendfax -R -f "$FROM" -n -d "$TONUMBER" $METAMAIL_TMPDIR/*
fi

# To disable coverpages simply compent the above if then else conditional and uncomment the command bellow
#	sendfax -R -f "$FROM" -n -d "$TONUMBER" $METAMAIL_TMPDIR/*



Project hosted by iFAX Solutions