-
-
Save crawc/6a4eed83f63280f16cae5404e46c3e93 to your computer and use it in GitHub Desktop.
Mail to Fax gateway script for hylafax
This file contains 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment