unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: rms@gnu.org
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: buffer-swap-text and multibyteness
Date: Sun, 01 Feb 2009 20:26:28 -0500	[thread overview]
Message-ID: <jwviqnt63d7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <E1LTl7l-0005Dm-8W@fencepost.gnu.org> (Richard M. Stallman's message of "Sun, 01 Feb 2009 17:49:09 -0500")

>     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.


        Stefan


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)




  parent reply	other threads:[~2009-02-02  1:26 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-31 14:52 buffer-swap-text and multibyteness Eli Zaretskii
2009-01-31 17:12 ` Stefan Monnier
2009-01-31 19:03   ` Eli Zaretskii
2009-01-31 19:43     ` Stefan Monnier
2009-01-31 20:05       ` Eli Zaretskii
2009-01-31 21:28         ` Stefan Monnier
2009-01-31 22:02           ` Eli Zaretskii
2009-02-01  1:43             ` Stefan Monnier
2009-02-01  4:13               ` Eli Zaretskii
2009-02-01 21:43                 ` Stefan Monnier
     [not found]         ` <E1LTl7l-0005Dm-8W@fencepost.gnu.org>
2009-02-02  1:26           ` Stefan Monnier [this message]
2009-02-02  2:37           ` Kenichi Handa
2009-02-02  2:48             ` Kenichi Handa
2009-02-05  4:26               ` Stefan Monnier
2009-02-07 12:58                 ` Eli Zaretskii
2009-02-09 11:31                 ` Kenichi Handa
2009-02-09 14:11                   ` Stefan Monnier
2009-02-09 20:26                     ` Eli Zaretskii
2009-02-10  2:03                       ` Stefan Monnier
2009-02-10  8:49                         ` Eli Zaretskii
2009-02-10 21:57                           ` Stefan Monnier
2009-02-11  4:01                             ` Eli Zaretskii
2009-02-11 14:10                               ` Stefan Monnier
2009-02-11  9:24                         ` Kenichi Handa
     [not found]                   ` <umycvs6a0.fsf@gnu.org>
2009-02-10  8:17                     ` Kenichi Handa
2009-02-10  9:12                       ` Eli Zaretskii
2009-02-10 11:52                         ` Kenichi Handa
2009-02-21 15:12                           ` Eli Zaretskii
2009-02-24  8:09                             ` Kenichi Handa
2009-02-24 18:48                               ` Eli Zaretskii
2009-02-25  1:15                                 ` Kenichi Handa
2009-02-25  4:11                                   ` Eli Zaretskii
2009-02-26  5:48                                     ` Kenichi Handa
2009-02-02  4:09           ` Eli Zaretskii
2009-02-01 22:49       ` Richard M Stallman
2009-02-02  2:14     ` Kenichi Handa
2009-02-02  2:39       ` Stefan Monnier
2009-02-03  7:59         ` Kenichi Handa
2009-02-03 16:46           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwviqnt63d7.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).