# ** This is a procmailrc file used to process RelayFax-sent e-mails
# ** for processing through TPC.INT.  This approach closely follows
# ** the analogy for use directly with HylaFAX server which was
# ** also written by this author:  Lee Howard <faxguy@howardsilvan.com>

VERBOSE=yes
LOGFILE=$HOME/procmail.log

# TPC is inconsistent about where it sends notification messages, so we
# need to use this for our sendmail pipe.
RETURNPATH=`grep -e "return-path" -i | sed "s/^.*<//;s/>//"`

# This is our loose way to verify that the mail is coming from a RelayFax
# client program.  If not from RelayFax client, we should ignore the mail.
PRINTEDFAX=`grep -e PRINTEDFAX | sed -e 's/PRINTEDFAX: //g'`

# We need to support fax broadcasting (multiple destinations), since
# RelayFax client supports it.  TPC requires a separate mail for each
# fax sent, so we do that.  The "�" are merely field delimiters.
FAXDESTINATION=`egrep -e '^(FAX|CC)NUMBER' | sed -e 's/@//g' -e 's/^.*NUMBER: \([^,]*[^ ]*[^"]*\), "\([^"]*[^,]*[^ ]*[^"]*\)", "[^$]*"/\2\@\1 �/' -e 's/"//g'`
FAXTOCOMPANY=`egrep -e '^(FAX|CC)NUMBER' | sed -e 's/.*", "\([^$]*\)"/\1 �/' -e 's/"//g'`

# We use $ATTACHMENTNAME to discern whether or not there is an image
# with the fax.  (It could be comment-only.)
ATTACHMENTNAME=`grep -e 'Content-Type.*name=' | sed -e 's/^.*name=//g' | sed -e 's/\"//g'`

:0
* PRINTEDFAX ?? ^^TRUE^^
{ INCLUDERC=.faxitrc }