2 # Based on mhpgp 1.1.0.7 2005/11/29 06:25:05 by Neil Rickert
3 # Adjusted to mmh by markus schnalke <meillo@marmaro.de>, 2012-07
7 # -write: Save the decrypted message to the current folder
9 usage="Usage: mhpgp [-write] msg"
11 # prepend the default options from the profile
12 set -- `mhparam -nocomp ${0##*/}` "$@"
20 echo "${0##*/} has no own version number, thus this instead:"
38 trap "rm -rf $TEMP" 0 1 2 15
41 ### verify a mime message
43 bdry=`echo "$CH" | sed -n \
44 -e 's/[Bb][Oo][Uu][Nn][Dd][Aa][Rr][Yy]=/;boundary=/' \
45 -e 's/.*;boundary=/boundary=/' \
46 -e 's/^boundary=\([^;]*\);.*/boundary=\1/' \
47 -e 's/^boundary="\([^"]*\)".*/boundary=\1/' \
48 -e 's/[
\r ][
\r ]*$//' \
51 xbdry=`echo "$bdry" | sed -e 's"/"\\\\/"g' -e 's"\."\\\\."g'`
53 sed -e '1,/^--'"$xbdry"'[
\r ]*$/d' $FILE > $TEMP/body
55 sed -e '/^--'"$xbdry"'[
\r ]*$/,$d' \
56 -e 's/[
\r ][
\r ]*$//' $TEMP/body |
57 sed -e '$d' -e 's/$/
\r/' > $TEMP/msg
58 if grep "[ ^M ]$" $TEMP/body >/dev/null 2>&1 ; then
59 echo 'Warning: trailing blanks removed from message body' >&2
62 sed -e '1,/^--'"$xbdry"'[
\r ]*$/d' $TEMP/body |
63 sed -n -e '/BEGIN PGP /,/END PGP /p' > $TEMP/msg.asc
65 gpg --verify $TEMP/msg.asc
68 ### decrypt MIME and non-MIME messages (type is in $1)
69 ###; invoke the pager as needed
72 /^-----BEGIN PGP MESSAGE/b x
76 /^-----END PGP MESSAGE/b y
81 b y' $FILE | gpg --decrypt >$TEMP/msg
82 X=`tail -1c $TEMP/msg`
83 if [ "$X" != "" ] ; then
84 # ensure trailing newline
87 if [ "$1" = "plain" ] ; then
88 sedcmd="/^[Mm][Ii][Mm][Ee]-.*:/b r"
96 /^[Cc][Oo][Nn][Tt][Ee][Nn][Tt]-/b r
103 b a' "$FILE" > "$TEMP/outfile"
105 if [ "$1" = "plain" ] ; then echo "" >> "$TEMP/outfile" ; fi
106 sed -e 's/
\r$//' $TEMP/msg >> "$TEMP/outfile" || exit 1
108 if [ "$wflag" = "1" ] ; then
109 refile -file "$TEMP/outfile" @
111 show -file "$TEMP/outfile"
116 ### Mainline processing
120 FILE=`mhpath c` || exit 1 ;;
123 /*) FILE=`echo "$@"` ;;
124 *) FILE=`mhpath "$@"` || exit 1 ;;
130 if [ $# != 2 ] ; then
131 echo "One message at a time, please!" >&2
135 # get mime-version and content-type headers.
139 /^[Mm][Ii][Mm][Ee]-[Vv][Ee][Rr][Ss][Ii][Oo][Nn]:/b x
140 /^[Cc][Oo][Nn][Tt][Ee][Nn][Tt]-[Tt][Yy][Pp][Ee]:/b x
148 if echo "$CH" | grep -i mime-version >/dev/null 2>&1; then
149 : ## nothing, this is good
154 # Handle MIME variants
156 *application/pgp-signature*)
160 *application/pgp-encrypted*)
166 # Handle plain variants
167 case "`grep '^-----BEGIN PGP' $FILE 2>/dev/null`" in
168 *"PGP SIGNED MESSAGE"*)
172 *"BEGIN PGP MESSAGE"*)
178 echo "I can't find a PGP message there" >&2