#!/bin/sh
#
# This script takes a raw article that is already rejected, creates a 
# reply message, signs it with PGP and sends back to the author.
#

# echo $0 invoked with arguments $@ 1>&2

MESSAGE=$TMP/rejected.$$

shift; REASON="$1"; export REASON; shift 
#EXPLANATION="$@"; export EXPLANATION

echo Action: processRejected, reason=$REASON 1>&2

cat  > $MESSAGE

save() { 
  procmail -p -f- $MNG_ROOT/etc/procmail/save-rejected < $MESSAGE
}

reply() {

  (
    cat $MESSAGE | formail -rt -I "Reply-To: $BOARD" 	\
			       -I "Errors-To: $MUNGED_ADDRESS"	
    (
      echo "$EXPLANATION"
      echo

      if [ "x$REASON" != "xcustom" ] ; then
	cat $MNG_ROOT/etc/messages/$REASON
      fi

      echo ""
      echo ============================================ Full text of your message follows
      sed 's/^/> /' < $MESSAGE
    ) | stump-pgp -staf -z "$PMPASSWORD" 	\
            -u "$ROBOMOD_APPROVAL" +clearsig=on  2>/dev/null \
  ) | sendmail -t -f $MUNGED_ADDRESS
}

save
reply $1
rm $MESSAGE
