Subject: bug#40118: 27.0.90; Signing emails with gpg

From: Robert Pluim <[email-masked]>
Date: Mon, 20 Apr 2020 12:52:00 +0200

>>>>> On Fri, 17 Apr 2020 17:11:53 +0200, Robert Pluim <[email-masked]> said:

ping. Eli, full patch to emacs-27, or just error message change to
emacs-27?

Just to reiterate: this is a regression from emacs-26

    Robert> Since itʼs Friday afternoon, what Eli really wants to do is make
    Robert> another decision on whether to let something into emacs-27 just before
    Robert> the next rc. How about this? If itʼs not OK Iʼll just adjust the error
    Robert> message, if it is OK Iʼll write a NEWS entry.

    Robert> diff --git a/lisp/gnus/mml-sec.el b/lisp/gnus/mml-sec.el
    Robert> index 740e1d2b72..8abe83b937 100644
    Robert> --- a/lisp/gnus/mml-sec.el
    Robert> +++ b/lisp/gnus/mml-sec.el
    Robert> @@ -937,6 +937,47 @@ mml-secure-epg-encrypt
    Robert>         (signal (car error) (cdr error))))
    Robert>      cipher))
 
    Robert> +(defun mml-secure-sender-sign-query (protocol sender)
    Robert> +  "Query whether to use SENDER to sign when using PROTOCOL.
    Robert> +PROTOCOL will be `OpenPGP' or `CMS' (smime).
    Robert> +This can also save the resulting value of
    Robert> +`mml-secure-smime-sign-with-sender' or
    Robert> +`mml-secure-openpgp-sign-with-sender' via Customize.
    Robert> +Returns non-nil if the user has chosen to use SENDER."
    Robert> +  (let ((buffer (get-buffer-create "*MML sender signing options*"))
    Robert> +        (options '((?a "always" "Sign using this sender now and sign with message sender in future.")
    Robert> +                   (?s "session only" "Sign using this sender now, and sign with message sender for this session only.")
    Robert> +                   (?n "no" "Do not sign this message (and error out)")))
    Robert> +        answer done val)
    Robert> +    (save-window-excursion
    Robert> +      (pop-to-buffer buffer)
    Robert> +      (erase-buffer)
    Robert> +      (insert (format "No %s signing key was found for this message.\nThe sender of this message is \"%s\".\nWould you like to attempt looking up a signing key based on it?"
    Robert> +                      (if (eq protocol 'OpenPGP)
    Robert> +                          "openpgp" "smime")
    Robert> +                      sender))
    Robert> +      (while (not done)
    Robert> +        (setq answer (read-multiple-choice "Sign this message using the sender?" options))
    Robert> +        (cl-case (car answer)
    Robert> +          (?a
    Robert> +           (if (eq protocol 'OpenPGP)
    Robert> +               (progn
    Robert> +                 (setq mml-secure-openpgp-sign-with-sender t)
    Robert> +                 (customize-save-variable 'mml-secure-openpgp-sign-with-sender t))
    Robert> +             (setq mml-secure-smime-sign-with-sender t)
    Robert> +             (customize-save-variable 'mml-secure-smime-sign-with-sender t))
    Robert> +           (setq done t
    Robert> +                 val t))
    Robert> +          (?s
    Robert> +           (if (eq protocol 'OpenPGP)
    Robert> +               (setq mml-secure-openpgp-sign-with-sender t)
    Robert> +             (setq mml-secure-smime-sign-with-sender t))
    Robert> +           (setq done t
    Robert> +                 val t))
    Robert> +          (?n
    Robert> +           (setq done t)))))
    Robert> +    val))
    Robert> +
    Robert>  (defun mml-secure-epg-sign (protocol mode)
    Robert>    ;; Based on code appearing inside mml2015-epg-sign.
    Robert>    (let* ((context (epg-make-context protocol))
    Robert> @@ -945,15 +986,21 @@ mml-secure-epg-sign
    Robert>  	 (signers (mml-secure-signers context signer-names))
    Robert>  	 signature micalg)
    Robert>      (unless signers
    Robert> -      (let ((maybe-msg
    Robert> -             (if mml-secure-smime-sign-with-sender
    Robert> -                 "."
    Robert> -               "; try setting `mml-secure-smime-sign-with-sender'.")))
    Robert> -        ;; If `mml-secure-smime-sign-with-sender' is already non-nil
    Robert> -        ;; then there's no point advising the user to examine it.  If
    Robert> -        ;; there are any other variables worth examining, please
    Robert> -        ;; improve this error message by having it mention them.
    Robert> -        (error "Couldn't find any signer names%s" maybe-msg)))
    Robert> +      (if (mml-secure-sender-sign-query protocol sender)
    Robert> +          (setq signer-names (mml-secure-signer-names protocol sender)
    Robert> +                signers (mml-secure-signers context signer-names)))
    Robert> +      (unless signers
    Robert> +        (let ((maybe-msg
    Robert> +               (if (or mml-secure-smime-sign-with-sender
    Robert> +                       mml-secure-openpgp-sign-with-sender)
    Robert> +                   "."
    Robert> +                 "; try setting `mml-secure-smime-sign-with-sender' or 'mml-secure-openpgp-sign-with-sender'.")))
    Robert> +          ;; If `mml-secure-smime-sign-with-sender' or
    Robert> +          ;; `mml-secure-openpgp-sign-with-sender' are already non-nil
    Robert> +          ;; then there's no point advising the user to examine them.
    Robert> +          ;; If there are any other variables worth examining, please
    Robert> +          ;; improve this error message by having it mention them.
    Robert> +          (error "Couldn't find any signer names%s" maybe-msg))))
    Robert>      (when (eq 'OpenPGP protocol)
    Robert>        (setf (epg-context-armor context) t)
    Robert>        (setf (epg-context-textmode context) t)