Subject: bug#38512: 27.0.50; Reading PGP-signed email from people with non-ascii names give error

From: Robert Pluim <[email-masked]>
Date: Mon, 09 Dec 2019 17:26:08 +0100

>>>>> On Fri, 06 Dec 2019 21:43:37 +0100, "Adam Sjøgren <[email-masked]>" said:

    Adam> Recently, when I read an email that has been PGP-signed and/or encrypted
    Adam> by a person who has non-ascii chars in their name in the PGP-key, Gnus
    Adam> gives an error on the email, showing this message:

    Adam>   epg--decode-percent-escape: Can’t convert the 8th character to unibyte

    Adam> This also means I can't read encrypted emails I have sent myself.

    Adam> I have bisected the problem to this commit:

    Adam>   98387b9e2455b0bd5a2aafe6fac939fb111eedce is the first bad commit
    Adam>   commit 98387b9e2455b0bd5a2aafe6fac939fb111eedce
    Adam>   Author: Lars Ingebrigtsen <[email-masked]>
    Adam>   Date:   Wed Oct 23 10:50:29 2019 +0200

    Adam>       Make display of S/MIME signatures slightly better

    Adam>       * lisp/epg.el (epg-signature-to-string): Decode percent escapes
    Adam>       (bug#36101).

    Adam>    lisp/epg.el | 2 +-
    Adam>    1 file changed, 1 insertion(+), 1 deletion(-)

If I remember correctly what Eli taught me the last time this kind of
discussion came up, this should fix it:

diff --git a/lisp/epg.el b/lisp/epg.el
index 090317f422..5466716e34 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -2032,7 +2032,7 @@ epg-edit-key
     (epg-reset context)))
 
 (defun epg--decode-percent-escape (string)
-  (setq string (string-to-unibyte string))
+  (setq string (encode-coding-string string 'raw-text))
   (let ((index 0))
     (while (string-match "%\\(\\(%\\)\\|\\([[:xdigit:]][[:xdigit:]]\\)\\)"
 			 string index)