Created
August 28, 2015 07:20
-
-
Save stefb69/ab1bbb39453d37d54eb4 to your computer and use it in GitHub Desktop.
Mail to Fax gateway script for hylafax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# mail2fax reloaded | |
# modified version working 100% by stefb (for europe) | |
# This script allows you to send faxes through your HylaFAX box. | |
# It uses mpack to strip out email attachments and sendfax to do | |
# the fax delivery. | |
### Temporary dir stuff | |
RANDOMFAX=/tmp/faxtmp.$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" ") | |
if [ ! -d "$RANDOMFAX" ] ; then | |
mkdir $RANDOMFAX | |
fi | |
rm -f $RANDOMFAX/* | |
### Some makeup (maybe not necessary anymore) | |
sed 's/multipart\/alternative/multipart\/mixed/' > $RANDOMFAX/_message_ | |
JOBID=`grep -e "^subject:" -i $RANDOMFAX/_message_ | sed q | sed 's/^[^:]*: *//g'` | |
TOLINE=`grep -e "^to:" -i $RANDOMFAX/_message_ | sed q` | |
FROMLINE=`grep -e "^from:" -i $RANDOMFAX/_message_ | sed q` | |
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 | |
if [ "`echo $FROMLINE | grep '<.*>'`" != "" ]; then | |
FROMPATH=`echo $FROMLINE| sed -e 's/.*<\(.*\).*>.*/\1/'` | |
else | |
FROMPATH=`echo $FROMLINE| sed -e 's/^[Ff]rom://g' -e 's/[ ]*\([^ ]*\).*/\1/'` | |
fi | |
### Split message | |
munpack -q -C $RANDOMFAX _message_ > /dev/null 2>&1 | |
### Delete all but the attachments | |
rm -f $RANDOMFAX/_message_ | |
rm -f $RANDOMFAX/*.desc | |
### Delivery time! | |
echo sendfax -R -f "$FROMPATH" -s a4 -n -d "$TONUMBER" $RANDOMFAX/* >> /tmp/faxlog | |
sendfax -R -f "$FROMPATH" -s a4 -n -d "$TONUMBER" $RANDOMFAX/* | |
### Remove temporary dir | |
rm -rf $RANDOMFAX |
Great, thank's a lot worked of the shell. Please be reminded to install mpack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi there, im using this script in my hylafax + postfix. When im trying to send email to fax (using thunderbird) , it didnt show any JID on my faxstat, its like not working for me at all... and when im using the original version which was written by Lee. It could send mail to fax but what i got there at the another side (fax machine) only bunch of logs, my sent contents were gone.