Skip to content

Commit

Permalink
Add work-around for nnmaildir encoding problem
Browse files Browse the repository at this point in the history
* lisp/gnus/mm-decode.el (mm-with-part): Fix problem with
multipart 8bit encoded posts from nnmaildir (bug#44307).
  • Loading branch information
larsmagne committed Jan 7, 2021
1 parent 7e80aec commit 23a887e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
19 changes: 14 additions & 5 deletions lisp/gnus/mm-decode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,20 @@ in HANDLE."
(when (and (mm-handle-buffer handle)
(buffer-name (mm-handle-buffer handle)))
(with-temp-buffer
(mm-disable-multibyte)
(insert-buffer-substring (mm-handle-buffer handle))
(mm-decode-content-transfer-encoding
(mm-handle-encoding handle)
(mm-handle-media-type handle))
(if (and (eq (mm-handle-encoding handle) '8bit)
(with-current-buffer (mm-handle-buffer handle)
enable-multibyte-characters))
;; Due to unfortunate historical reasons, we may have a
;; multibyte buffer here, but if it's using an 8bit
;; Content-Transfer-Encoding, then work around that by
;; just ignoring the situation.
(insert-buffer-substring (mm-handle-buffer handle))
;; Do the decoding.
(mm-disable-multibyte)
(insert-buffer-substring (mm-handle-buffer handle))
(mm-decode-content-transfer-encoding
(mm-handle-encoding handle)
(mm-handle-media-type handle)))
,@forms))))
(put 'mm-with-part 'lisp-indent-function 1)
(put 'mm-with-part 'edebug-form-spec '(body))
Expand Down
18 changes: 17 additions & 1 deletion test/lisp/gnus/mm-decode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
'charset)))
"<!doctype html><html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"></head><body>ääää</body></html>\n")))))))

(ert-deftest test-mm-with-part ()
(ert-deftest test-mm-with-part-unibyte ()
(with-temp-buffer
(set-buffer-multibyte nil)
(insert-file-contents-literally (ert-resource-file "8bit-multipart.bin"))
Expand All @@ -70,4 +70,20 @@
'charset)))
"ääää\n"))))))

(ert-deftest test-mm-with-part-multibyte ()
(with-temp-buffer
(set-buffer-multibyte t)
(nnheader-insert-file-contents (ert-resource-file "8bit-multipart.bin"))
(while (search-forward "\r\n" nil t)
(replace-match "\n"))
(let ((handle (mm-dissect-buffer)))
(pop handle)
(let ((part (pop handle)))
(should (equal (decode-coding-string
(mm-with-part part
(buffer-string))
(intern (mail-content-type-get (mm-handle-type part)
'charset)))
"ääää\n"))))))

;;; mm-decode-tests.el ends here

0 comments on commit 23a887e

Please sign in to comment.