Subject: bug#41659: [ASCII is ok]

From: Uwe Brauer <[email-masked]>
Date: Wed, 10 Jun 2020 17:49:15 +0200

>>> "UB" == Uwe Brauer <[email-masked]> writes:

>>> "UB" == Uwe Brauer <[email-masked]> writes:
>>> "UB" == Uwe Brauer <[email-masked]> writes:
Hi Lars,

I just had an interchange of smime encrypted and signed messages with
Jens Lechtenboerger.

He confirms that a message with latin-1 chars, which is encrypted and
signed, is not correctly decrypted in the sense that the latin-1 chars
are not correctly displayed and superflusios text is added.

The culprits are 
(defun mm-possibly-verify-or-decrypt (parts ctl &optional from)

And the following commits

 commit 4ce81556b7ad7f7f8c8bb07a7a935114bbe850d0
 Author: Lars Ingebrigtsen <[email-masked]>
 Date:   Mon Sep 23 18:23:22 2019 +0200

     Make mm-possibly-verify-or-decrypt pass decryption error

     * lisp/gnus/mm-decode.el (mm-possibly-verify-or-decrypt): If
     there's an error, report the error back in a new part (bug#25649).

Now message cannot be decrypted anymore

** Git repaired
 commit 84ef1ea8b524f8998fc8674b99cf8069e38dce4f (HEAD)
 Author: Lars Ingebrigtsen <[email-masked]>
 Date:   Thu Sep 26 16:24:29 2019 +0200

      Make it possible to view S/MIME verified emails

      * lisp/gnus/mm-decode.el (mm-possibly-verify-or-decrypt): When
      dissecting the result, we need a header (bug#18393).

      * lisp/gnus/mm-view.el (mm-view-pkcs7-verify): Insert the verified
      string.

      * lisp/gnus/smime.el (smime-verify-region): Return the verified
      string.

Message can be decrypted, but latin-1 chars are not decoded.

If you want we can run some experiements, but you need to have a smime
certificate installed.

For me it is so annoying that I partially reverted these commits in the
latest emacs master. Here is the diff (I would not call it a patch).

Regards

Uwe Brauer 

--- mm-decode.el	2020-06-07 13:16:45.973266246 +0200
+++ mm-decode-patched.el	2020-06-07 13:15:56.861220757 +0200
@@ -1680,8 +1680,8 @@
 		    (t (y-or-n-p
 			(format "Decrypt (S/MIME) part? "))))
 		   (mm-view-pkcs7 parts from))
-	  (goto-char (point-min))
-	  (insert "Content-type: text/plain\n\n")
+;; 	  (goto-char (point-min))
+;; 	  (insert "Content-type: text/plain\n\n")
 	  (setq parts (mm-dissect-buffer t)))))
      ((equal subtype "signed")
       (unless (and (setq protocol
@@ -1745,28 +1745,11 @@
 	(save-excursion
 	  (if func
 	      (setq parts (funcall func parts ctl))
-	    (mm-sec-error
-	     'gnus-details
-	     (format "Unknown encrypt protocol (%s)" protocol)))))))
-    ;; Check the results (which are now in `parts').
-    (let ((err (get-text-property 0 'sec-error (car mm-security-handle))))
-      (if (or (not err)
-	      (not (equal subtype "encrypted")))
-	  parts
-	;; We had an error during decryption.  Report what it is.
-	(list
-	 (mm-make-handle
-	  (with-current-buffer (generate-new-buffer " *mm*")
-	    (insert "Error!  Result from decryption:\n\n"
-		    (or (get-text-property 0 'gnus-details
-					   (car mm-security-handle))
-			"")
-		    "\n\n"
-		    (or (get-text-property 0 'gnus-details
-					   (car mm-security-handle))
-			""))
-	    (current-buffer))
-	  '("text/plain")))))))
+	    (mm-set-handle-multipart-parameter
+	     mm-security-handle 'gnus-details
+	     (format "Unknown encrypt protocol (%s)" protocol))))))
+     (t nil))
+    parts))
 
 (defun mm-multiple-handles (handles)
   (and (listp handles)