[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: buffer-swap-text and multibyteness

From: Stefan Monnier
Subject: Re: buffer-swap-text and multibyteness
Date: Sun, 01 Feb 2009 20:26:28 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

>     Just imagine what it takes to implement rmail-edit with this
>     mind-swapping design (which is probably the main reason why it
>     currently seems to work only with plain-ASCII message bodies).

> I implemented support for editing non-ASCII messages.  If it fails,
> please send a bug report with a test case.

I don't have a test case, but would propose a completely untested patch
(see below).  The reason is:

- narrow should take place before extracting the headers.
- insert-buffer-substring from a multibyte buffer to a unibyte buffer
  (as here), has tricky semantics.  Better do the encoding at that
  point, so we're going from multibyte non-encoded text to unibyte
  encoded text, both of which are well understood.
- text encoding should take place before the QP/base64 encoding.


Index: lisp/mail/rmailedit.el
RCS file: /sources/emacs/emacs/lisp/mail/rmailedit.el,v
retrieving revision 1.47
diff -u -r1.47 rmailedit.el
--- lisp/mail/rmailedit.el      1 Feb 2009 03:26:20 -0000       1.47
+++ lisp/mail/rmailedit.el      2 Feb 2009 01:23:45 -0000
@@ -143,7 +143,10 @@
       (search-forward "\n\n")
       (setq headers-end (point))
+      (narrow-to-region (rmail-msgbeg rmail-current-message)
+                       (rmail-msgend rmail-current-message))
       (setq character-coding (mail-fetch-field "content-transfer-encoding")
            is-text-message (rmail-is-text-p)
@@ -151,28 +154,25 @@
       (if character-coding
          (setq character-coding (downcase character-coding)))
-      (narrow-to-region (rmail-msgbeg rmail-current-message)
-                       (rmail-msgend rmail-current-message))
       (goto-char (point-min))
       (search-forward "\n\n")
-      (let ((inhibit-read-only t)
-           (headers-end-1 (point)))
-       (insert-buffer-substring rmail-view-buffer headers-end)
-       (delete-region (point) (point-max))
+      (let ((inhibit-read-only t))
+        (let ((data-buffer (current-buffer))
+              (end (copy-marker (point) t)))
+          (with-current-buffer rmail-view-buffer
+            (encode-coding-region headers-end (point-max) coding-system
+                                  data-buffer))
+          (delete-region end (point-max)))
        ;; Re-encode the message body in whatever
        ;; way it was decoded.
         ((string= character-coding "quoted-printable")
-         (mail-quote-printable-region headers-end-1 (point-max)))
+         (mail-quote-printable-region (point) (point-max)))
         ((and (string= character-coding "base64") is-text-message)
-         (base64-encode-region headers-end-1 (point-max)))
+         (base64-encode-region (point) (point-max)))
         ((eq character-coding 'uuencode)
-         (error "Not supported yet."))
-        (t
-         (if (or (not coding-system) (not (coding-system-p coding-system)))
-             (setq coding-system 'undecided))
-         (encode-coding-region headers-end-1 (point-max) coding-system)))
+         (error "Not supported yet.")))
     (rmail-set-attribute rmail-edited-attr-index t)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]