#!/bin/sh
#
# Plugin for FEddy
#
# For forwarding Fido-messages to Fax-machines via mgetty+sendfax
#
# Needs "dialog" to run
# /dev/tty must be world- readable/writable
# Needs fully configured mgetty+sendfax package with all needed tools
# Can easily be configured for other fax-software
#
# German Umlauts may be problematic (see script "faxspool")
#
# Addressee can be given as first parameter
#
# Author: Andreas Foerster, 2:2448/655.8

# Formater
FORMAT=/usr/local/bin/utils/formatmsg

# Temp-File: (extention important!)
TMP=/tmp/faxforward.asc

#####

STATUS=0
USER=$1

if [ -z "$USER" ]; then
   if dialog --title "Forward to Fax" \
             --inputbox "Fax-Nr. or Alias :" 8 60 \
                   >/dev/tty </dev/tty 2>$TMP
   then
      USER=`cat $TMP | tr [:blank:]/ -`

      dialog --title "Forward to Fax" \
             --infobox "Preparing Fax... please wait" 3 40 \
               >/dev/tty </dev/tty
   fi
fi

if [ -n "$USER" ];
then
   cat - | $FORMAT >$TMP
   faxspool -q $USER $TMP
   STATUS=$?
else
   cat - > /dev/null
fi

rm -f $TMP

exit $STATUS

