:0
# Here's our loop control...
* ! FAXDESTINATION ?? ^^^^
{
 # We need to pull out single fields from $FAXDESTINATION and
 # $FAXTOCOMPANY.  This is probably inefficient... besides
 # being formatted for HylaFAX instead of TPC.
 FAXTOWHOM=`echo $FAXDESTINATION | sed 's/^\([^¿]*\) ¿.*/\1/'`
 FAXTOAT=`echo $FAXTOCOMPANY | sed 's/^\([^¿]*\) ¿.*/\1/'`
 TONAME=`echo $FAXTOWHOM | sed 's/^\([^\@]*\)@.*/\1/'`
 TONUMBER=`echo $FAXTOWHOM | sed 's/^[^\@]*@\(.*\)/\1/'`
 FAXDESTINATION=`echo $FAXDESTINATION | sed 's/^[^¿]* ¿\(.*\)/\1/'`
 FAXTOCOMPANY=`echo $FAXTOCOMPANY | sed 's/^[^¿]* ¿\(.*\)/\1/'`

 # Clean up and format for TPC...
 FAXTOAT=`echo $FAXTOAT | sed -e 's/ /_/g' -e 's/,//g'`
 TONAME=`echo $TONAME | sed -e 's/ /_/g' -e 's/,//g'`
 TONUMBER=`echo $TONUMBER | sed 's/[ .)(+-]//g'`

 :0 bhfw
 # This strips out the body content except for the COMMENTS
 # and it reformats the To: header field.  And, because RelayFax client
 # erroniously uses "image/tif" and not "image/tiff", we need to work
 # around that...
 | egrep -v 'PRINTEDFAX|CLIENTVERSION|FAXNUMBER|FROMLINE|BILLINGCODE|FAXPASSWORD|FROMNAME|STREET|CITY|STATE|ZIP|HOMEPHONE|HOMEFAX|BUSPHONE|BUSFAX|PRIORITY|CONFIRMSEND|FAXSUBJECT|CCNUMBER' | \
    sed -e 's/COMMENTS: //g' -e 's/image\/tif\;/image\/tiff\;/g' | \
    formail -i "To: remote-printer.$TONAME/$FAXTOAT@$TONUMBER.iddd.tpc.int"

   :0 cAbhw
   # now that the mail is formatted right, this shoots it out to tpc
   | /usr/sbin/sendmail -f$RETURNPATH remote-printer.$TONAME/$FAXTOAT@$TONUMBER.iddd.tpc.int

 :0
 # Loop...
 { INCLUDERC=.faxitrc }

}
:0 i
# The mail has to be delivered somewhere, or it hits the mailbox, 
# and now that we've got no more destinations...
/dev/null


