mhsign: Fix key lookup of aliases when encrypting
authormarkus schnalke <meillo@marmaro.de>
Fri, 22 Apr 2016 10:46:33 +0000 (12:46 +0200)
committermarkus schnalke <meillo@marmaro.de>
Fri, 22 Apr 2016 10:46:33 +0000 (12:46 +0200)
Now mhsign can handle addresses that contain whitespace (e.g.
``markus schnalke <meillo@marmaro.de>'') in aliases. The helper
tool ap(1) is used to extract the actual addresses.

test/tests/mhsign/test-mhsign [new file with mode: 0755]
uip/Makefile.in
uip/mhsign.sh

diff --git a/test/tests/mhsign/test-mhsign b/test/tests/mhsign/test-mhsign
new file mode 100755 (executable)
index 0000000..7654e5f
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/sh
+######################################################
+#
+# Test mhsign (correct alias expansion with -enc)
+#
+######################################################
+
+. "$MH_TEST_COMMON"
+
+
+# setup some aliases
+
+cat >"$MH_TEST_DIR/.mmh/aliases" <<!
+a1:     unknownperson
+a2:     unknownperson@example.org
+a3:     Unknown Person <unknownperson>
+a4:     Unknown Person <unknownperson@example.org>
+a5:     "Unknown Person" <unknownperson@example.org>
+a6:     (Unknown) <unknownperson@example.org> (Person)
+a7:     Unknown <unknownperson@example.org>, unknownperson@example.org
+!
+cat >>"$MH_TEST_DIR/.mmh/profile" <<!
+aliasfile: aliases
+!
+
+
+# override gpg with our own function for defined output
+
+echo '#!/bin/sh
+exit 1
+' >"$MH_TEST_DIR/bin/gpg"
+chmod +x "$MH_TEST_DIR/bin/gpg"
+export MMHPGPKEY=0x12345678
+
+
+# now test it
+
+draft=`mhpath +drafts b`
+cat >"$draft" <<!
+To: a1, a2, a3, a4, a5
+Cc: a6, a7
+Subject: mhsign -enc test
+--------
+secret
+!
+
+runandcheck "whom -noali $draft" <<!
+a1
+a2
+a3
+a4
+a5
+a6
+a7
+!
+
+runandcheck "whom -ali $draft" <<!
+unknownperson
+unknownperson@example.org
+Unknown Person <unknownperson>
+Unknown Person <unknownperson@example.org>
+"Unknown Person" <unknownperson@example.org>
+(Unknown) <unknownperson@example.org> (Person)
+Unknown <unknownperson@example.org>
+unknownperson@example.org
+!
+
+runandcheck "mhsign -enc $draft" <<!
+Could not find key for <unknownperson>
+Could not find key for <unknownperson@example.org>
+Could not find key for <unknownperson>
+Could not find key for <unknownperson@example.org>
+Could not find key for <unknownperson@example.org>
+Could not find key for <unknownperson@example.org>
+Could not find key for <unknownperson@example.org>
+Could not find key for <unknownperson@example.org>
+!
index be02b67..6b7a570 100644 (file)
@@ -130,7 +130,7 @@ mmhwrap: mmhwrap.sh
        chmod +x mmhwrap
 
 mhsign: mhsign.sh
        chmod +x mmhwrap
 
 mhsign: mhsign.sh
-       cp $(srcdir)/mhsign.sh mhsign
+       sed "s,%libdir%,"$(libdir)"," $(srcdir)/mhsign.sh >mhsign
        chmod +x mhsign
 
 mhpgp: mhpgp.sh
        chmod +x mhsign
 
 mhpgp: mhpgp.sh
index 038052b..17b7489 100755 (executable)
@@ -108,14 +108,17 @@ lookupkeys() {
                echo "Encryption is not supported for BCCs" >&2
                return 1
        fi
                echo "Encryption is not supported for BCCs" >&2
                return 1
        fi
-               
-       for i in `whom -ali -tocc -nobcc "$1"` ; do
+
+       whom -ali -tocc -nobcc "$1" | while read i ; do
                case "$i" in
                '|'*)   echo "Ignoring pipe address" >&2
                        continue ;;
                *@*)    ;;
                case "$i" in
                '|'*)   echo "Ignoring pipe address" >&2
                        continue ;;
                *@*)    ;;
-               *)      i="$i@`hostname -f`" ;;
+               *)      a="$i@`hostname -f`" ;;
                esac
                esac
+               # extract the actual address
+               format='%<{error}%{error}: %{text}%|%(addr{text})%>'
+               i=`%libdir%/ap -form "=$format" "$i"`
                if k=`lookupkeyfile "$i"` ; then
                        KL="$KL $k"
                elif k=`lookupkeyring "$i"` ; then
                if k=`lookupkeyfile "$i"` ; then
                        KL="$KL $k"
                elif k=`lookupkeyring "$i"` ; then