--- /dev/null
+.\"
+.\" %nmhwarning%
+.\"
+.TH MHPGP %manext1% "%nmhdate%" MH.6.8 [%nmhversion%]
+.SH NAME
+mhpgp \- check PGP signatures and decrypt PGP messages using gnupg
+.SH SYNOPSIS
+.HP 5
+.na
+.B mhpgp
+.RB [ \-write ]
+.RI [ msg ]
+.RB [ \-Version ]
+.RB [ \-help ]
+.ad
+.SH DESCRIPTION
+.B mhpgp
+is a script to simplify verifying and decrypting PGP messages,
+using gnupg.
+.PP
+.B mhpgp
+can handle signatures and encryption in MIME and plain (non-MIME) format.
+Signed messages are verified.
+Encrypted messages are displayed with
+.B show
+in decrypted form, the signature is verified as well.
+.PP
+With the
+.B \-write
+switch, the decrypted message is stored into the current folder.
+.PP
+If no
+.I msg
+is given, the current message is used.
+.PP
+Trailing blanks are stripped from the lines before signature verification,
+because non are expected to be present as RFC 3156 requests:
+.PP
+.RS 5
+[...] implementations MUST make sure that no trailing
+whitespace is present after the MIME encoding has been applied.
+.RE
+.PP
+If there is trailing whitespace, it was likely added mistakenly
+during mail transfer.
+
+.SH FILES
+None
+
+.SH "PROFILE COMPONENTS"
+None
+
+.SH "SEE ALSO"
+mhsign(1), gpg(1)
+
+.SH DEFAULTS
+None
+
+.SH CONTEXT
+None
+
+.SH BUGS
+None
# commands to build
CMDS = ali anno burst comp dist flist folder forw mmh mark \
- mhbuild mhl mhsign \
+ mhbuild mhl mhsign mhpgp \
mhlist mhmail mhparam mhpath mhstore new packf pick \
print-mimetype prompter rcvdist rcvpack rcvstore refile repl rmf \
rmm scan send sendfiles show slocal sortm spost whatnow whom
SRCS = ali.c aliasbr.c anno.c ap.c burst.c comp.c \
dist.c distsbr.c dp.c dropsbr.c flist.c fmtdump.c \
folder.c forw.c inc.c mark.c mmh.sh mmhwrap.sh mhbuild.c \
- mhfree.c mhl.c mhlist.c mhlistsbr.c mhsign.sh \
+ mhfree.c mhl.c mhlist.c mhlistsbr.c mhsign.sh mhpgp.sh \
mhmail.c mhmisc.c mhoutsbr.c mhparam.c mhparse.c \
mhpath.c mhshow.c mhshowsbr.c mhstore.c mhtest.c \
new.c packf.c pick.c print-mimetype.sh \
cp $(srcdir)/mhsign.sh mhsign
chmod +x mhsign
+mhpgp: mhpgp.sh
+ cp $(srcdir)/mhpgp.sh mhpgp
+ chmod +x mhpgp
+
mhbuild: mhbuild.o mhoutsbr.o mhmisc.o mhfree.o mhparse.o termsbr.o $(LOCALLIBS)
$(LINK) mhbuild.o mhoutsbr.o mhmisc.o mhfree.o mhparse.o $(LINKLIBS) $(TERMLIB)
--- /dev/null
+#!/bin/sh
+# Based on mhpgp 1.1.0.7 2005/11/29 06:25:05 by Neil Rickert
+# Adjusted to mmh by markus schnalke <meillo@marmaro.de>, 2012-07
+
+
+# mhpgp:
+# -write: Save the decrypted message to the current folder
+
+usage="Usage: mhpgp [-write] msg"
+
+# prepend the default options from the profile
+set -- `mhparam -nocomp ${0##*/}` "$@"
+
+while : ; do
+ case "$1" in
+ -w*)
+ wflag=1
+ ;;
+ -V*)
+ echo "${0##*/} has no own version number, thus this instead:"
+ folder -Version
+ exit 0
+ ;;
+ -h*|-*)
+ echo "$usage" >&2
+ exit 1
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+done
+
+TEMP=/tmp/${0##*/}.$$
+umask 077
+mkdir $TEMP || exit 1
+trap "rm -rf $TEMP" 0 1 2 15
+
+
+### verify a mime message
+mimeverify() {
+ bdry=`echo "$CH" | sed -n \
+ -e 's/[Bb][Oo][Uu][Nn][Dd][Aa][Rr][Yy]=/;boundary=/' \
+ -e 's/.*;boundary=/boundary=/' \
+ -e 's/^boundary=\([^;]*\);.*/boundary=\1/' \
+ -e 's/^boundary="\([^"]*\)".*/boundary=\1/' \
+ -e 's/[ \r ][ \r ]*$//' \
+ -e 's/^boundary=//p'`
+
+ xbdry=`echo "$bdry" | sed -e 's"/"\\\\/"g' -e 's"\."\\\\."g'`
+
+ sed -e '1,/^--'"$xbdry"'[ \r ]*$/d' $FILE > $TEMP/body
+
+ sed -e '/^--'"$xbdry"'[ \r ]*$/,$d' \
+ -e 's/[ \r ][ \r ]*$//' $TEMP/body |
+ sed -e '$d' -e 's/$/\r/' > $TEMP/msg
+ if grep "[ ^M ]$" $TEMP/body >/dev/null 2>&1 ; then
+ echo 'Warning: trailing blanks removed from message body' >&2
+ fi
+
+ sed -e '1,/^--'"$xbdry"'[ \r ]*$/d' $TEMP/body |
+ sed -n -e '/BEGIN PGP /,/END PGP /p' > $TEMP/msg.asc
+
+ gpg --verify $TEMP/msg.asc
+}
+
+### decrypt MIME and non-MIME messages (type is in $1)
+###; invoke the pager as needed
+decrypt() {
+ sed -n -e ':a
+ /^-----BEGIN PGP MESSAGE/b x
+ d
+ :x
+ p
+ /^-----END PGP MESSAGE/b y
+ n
+ b x
+ :y
+ n
+ b y' $FILE | gpg --decrypt >$TEMP/msg
+ X=`tail -1c $TEMP/msg`
+ if [ "$X" != "" ] ; then
+ # ensure trailing newline
+ echo >> $TEMP/msg
+ fi
+ if [ "$1" = "plain" ] ; then
+ sedcmd="/^[Mm][Ii][Mm][Ee]-.*:/b r"
+ else
+ sedcmd='/^-*$/q'
+ fi
+
+ sed -n ':a
+ /^-*$/q
+ '"$sedcmd"'
+ /^[Cc][Oo][Nn][Tt][Ee][Nn][Tt]-/b r
+ p
+ n
+ b a
+ :r
+ n
+ /^[ ]/b r
+ b a' "$FILE" > "$TEMP/outfile"
+
+ if [ "$1" = "plain" ] ; then echo "" >> "$TEMP/outfile" ; fi
+ sed -e 's/\r$//' $TEMP/msg >> "$TEMP/outfile" || exit 1
+
+ if [ "$wflag" = "1" ] ; then
+ refile -file "$TEMP/outfile" @
+ else
+ show -file "$TEMP/outfile"
+ fi
+}
+
+
+### Mainline processing
+
+case "$#" in
+0)
+ FILE=`mhpath c` || exit 1 ;;
+*)
+ case "$*" in
+ /*) FILE=`echo "$@"` ;;
+ *) FILE=`mhpath "$@"` || exit 1 ;;
+ esac ;;
+esac
+
+set X $FILE
+
+if [ $# != 2 ] ; then
+ echo "One message at a time, please!" >&2
+ exit 1
+fi
+
+# get mime-version and content-type headers.
+CH=`sed -n -e '\
+ :a
+ /^-*$/q
+ /^[Mm][Ii][Mm][Ee]-[Vv][Ee][Rr][Ss][Ii][Oo][Nn]:/b x
+ /^[Cc][Oo][Nn][Tt][Ee][Nn][Tt]-[Tt][Yy][Pp][Ee]:/b x
+ d
+ :x
+ p
+ n
+ /^[ ]/b x
+ b a' $FILE`
+
+if echo "$CH" | grep -i mime-version >/dev/null 2>&1; then
+ : ## nothing, this is good
+else
+ CH=
+fi
+
+# Handle MIME variants
+case "$CH" in
+*application/pgp-signature*)
+ mimeverify
+ exit
+ ;;
+*application/pgp-encrypted*)
+ decrypt mime
+ exit
+ ;;
+esac
+
+# Handle plain variants
+case "`grep '^-----BEGIN PGP' $FILE 2>/dev/null`" in
+*"PGP SIGNED MESSAGE"*)
+ gpg --verify "$FILE"
+ exit
+ ;;
+*"BEGIN PGP MESSAGE"*)
+ decrypt plain
+ exit
+ ;;
+esac
+
+echo "I can't find a PGP message there" >&2
+exit 1