emacs-devel
[Top][All Lists]
Advanced

[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: Wed, 04 Feb 2009 23:26:12 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

> It always fails.  For instance, this mail contains signle
> A-grave here:

> À

> Please edit this message after typing e
> (rmail-edit-current-message) and type C-c C-c.  The above
> line is changed to \300 (byte #xC0).

Have you tried the patch I sent (and which I re-appended below)?


        Stefan


- 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))
 
       (rmail-swap-buffers-maybe)
+
+      (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.
        (cond
         ((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]