

tmpdir=~/.pinepgp

cename=GnuPG
ces="/usr/bin/gpg -at -s"
cee="/usr/bin/gpg -at -e"
cese="/usr/bin/gpg -at -se"
cec="/usr/bin/gpg"
cefp=gpg

hrb="--[PinePGP]--------------------------------------------------[begin]--"
hrm="--[PinePGP]-----------------------------------------------------------"
hre="--[PinePGP]----------------------------------------------------[end]--"

n=1
r=1
case $0 in
        *-sign) $ces $*; n=$? ;;
        *-encrypt)



          RCPTS=`echo $* | /usr/bin/sed -e 's/^ */ /' -e 's/  */ -r /g'`

          $cee $RCPTS;
          n=$?
        ;;
        *-sign+encrypt)



          RCPTS=`echo $* | /usr/bin/sed -e 's/^ */ /' -e 's/  */ -r /g'`


          ( /usr/bin/cat; echo; echo "Message signed and encrypted only for: $*"; ) | $cese $RCPTS;







          n=$?
        ;;
        *-check)

          TMP=`/usr/bin/mktemp ${tmpdir}/pinegpg.XXXXXX`



          echo "$hrb"
          $cec $* 2> $TMP
          n=$?
          if [ -s $TMP ]; then
            echo "$hrm"
            /usr/bin/cat $TMP
          fi
          if [ $n != 0 ]; then
            echo "PinePGP: Encryption backend encountered error."
            n=0
          fi
          echo "$hre"
          /bin/rm -f $TMP
          if [ $n = 0 ]; then r=0; fi
        ;;
        *)
          echo "Pine in/out filters for $cename"
          echo "Use:"
          echo "	$cefp-sign"
          echo "	$cefp-encrypt"
          echo "	$cefp-sign+encrypt"
          echo "	$cefp-check"
          ;;
esac

if [ $r != 0 ]; then
        echo -ne "\nHit return to continue." >&2
        read <&2
fi
exit $n
