[BUG] mel-q's encoder doesn't work with Emacs 23

Katsumi Yamaoka <[email protected]> Wed, 25 Nov 2009 09:12:07 +0900
Newsgroups gmane.mail.emacs.mime.japanese
Organization Emacsen advocacy group
Message-ID <[email protected]>
--=-=-=
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

I realized mel-q.el's QP encoder doesn't work with Emacs23 if it
runs in a multibyte buffer.  Some people seem to use it rather
than the one of mel-q-ccl.el for some reason.

Cf. http://article.gmane.org/gmane.mail.wanderlust.general/2695

Related articles:
http://article.gmane.org/gmane.emacs.mime.japanese/676
http://article.gmane.org/gmane.emacs.mime.japanese/677 (Japanese)

The way to reproduce the bug is as follows:

--8<---------------cut here---------------start------------->8---
(require 'mel)
(mel-use-module 'mel-q '("quoted-printable" "Q"))

(let ((buffer "*testing*"))
  (pop-to-buffer buffer)
  (erase-buffer)
  (set-buffer-multibyte t)
  (insert "Gr=FC=DF Gott\n")
  (sit-for 1)
  (encode-coding-region (point-min) (point-max) 'iso-8859-1)
  (sit-for 1)
  (funcall (mel-find-function 'mime-encode-region "quoted-printable")
	   (point-min) (point-max)))
--8<---------------cut here---------------end--------------->8---

Debugger entered--Lisp error: (args-out-of-range "0123456789ABCDEF" 262143)
[...]

262143 is a representation of the iso-8859-1 encoded letter "=FC"
in the multibyte buffer of Emacs 23, though it is displayed as
"\374".  In Emacs 22 or older, it is just 252 (i.e., ?\374).
The attached patch makes mel-q's encoder run in a unibyte buffer.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline

--- mel-q.el~	2005-07-06 02:09:04 +0000
+++ mel-q.el	2009-11-25 00:09:48 +0000
@@ -44,6 +44,16 @@
    (char-to-string (aref quoted-printable-hex-chars (logand character 15)))))
 
 (defun quoted-printable-internal-encode-region (start end)
+  (let ((data (buffer-substring start end)))
+    (delete-region (goto-char start) end)
+    (insert
+     (with-temp-buffer
+       (set-buffer-multibyte nil)
+       (insert data)
+       (quoted-printable-internal-encode-region-1 (point-min) (point-max))
+       (buffer-string)))))
+
+(defun quoted-printable-internal-encode-region-1 (start end)
   (save-excursion
     (save-restriction
       (narrow-to-region (goto-char start) end)

--=-=-=--