Subject: Re: bug#79376: [PATCH] [WIP] Fix mm multibyte

From: Manuel Giraud <[email-masked]>
Date: Thu, 04 Sep 2025 11:47:48 +0200

Hi,

Hopefully, this new patch is a better fix.  AFAIU, with this, the
content of the temporary MIME buffer is preserved as unibyte (as it
should?) and its content is encoded from a possibly multibyte buffer.

FWIW, I did not used `insert-buffer-substring' anymore as this is using
`string-make-unibyte' that does not do TRT.

>From 0be5c11bf307c32d0b2ee1e27f20f9a1ef80e030 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Thu, 4 Sep 2025 11:23:05 +0200
Subject: [PATCH] Do preserve MIME buffer as unibyte

* lisp/gnus/mm-decode.el (mm-copy-to-buffer): Preserve unibyte
in MIME buffer.
---
 lisp/gnus/mm-decode.el | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el
index 759d19a047e..732c8c42837 100644
--- a/lisp/gnus/mm-decode.el
+++ b/lisp/gnus/mm-decode.el
@@ -793,17 +793,15 @@ mm-dissect-multipart
 
 (defun mm-copy-to-buffer ()
   "Copy the contents of the current buffer to a fresh buffer."
-  (let ((obuf (current-buffer))
-        (mb enable-multibyte-characters)
-        beg)
+  (let (content)
     (goto-char (point-min))
     (search-forward-regexp "^\n" nil 'move) ;; There might be no body.
-    (setq beg (point))
+    (setq content (buffer-substring (point) (point-max)))
     (with-current-buffer
           (generate-new-buffer " *mm*")
       ;; Preserve the data's unibyteness (for url-insert-file-contents).
-      (set-buffer-multibyte mb)
-      (insert-buffer-substring obuf beg)
+      (set-buffer-multibyte nil)
+      (insert (encode-coding-string content 'undecided))
       (current-buffer))))
 
 (defun mm-display-parts (handle)
-- 
2.51.0

-- 
Manuel Giraud