From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: buffer-swap-text and multibyteness Date: Sun, 01 Feb 2009 20:26:28 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1233595931 29834 80.91.229.12 (2 Feb 2009 17:32:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Feb 2009 17:32:11 +0000 (UTC) Cc: Eli Zaretskii , emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 02 18:33:21 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LU2fS-0002pX-2V for ged-emacs-devel@m.gmane.org; Mon, 02 Feb 2009 18:33:06 +0100 Original-Received: from localhost ([127.0.0.1]:37730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LU2e9-0000pY-Ak for ged-emacs-devel@m.gmane.org; Mon, 02 Feb 2009 12:31:45 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LU2Ns-0001PD-Ix for emacs-devel@gnu.org; Mon, 02 Feb 2009 12:14:56 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LU2No-0001Kj-UC for emacs-devel@gnu.org; Mon, 02 Feb 2009 12:14:56 -0500 Original-Received: from [199.232.76.173] (port=43742 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LU2No-0001KY-PF for emacs-devel@gnu.org; Mon, 02 Feb 2009 12:14:52 -0500 Original-Received: from ironport2-out.pppoe.ca ([206.248.154.182]:3160 helo=ironport2-out.teksavvy.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LU2Nk-0001OK-8I; Mon, 02 Feb 2009 12:14:48 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AswEAGy4hknO+IQk/2dsb2JhbACBbsonhBQGgmw X-IronPort-AV: E=Sophos;i="4.37,366,1231131600"; d="scan'208";a="33208736" Original-Received: from 206-248-132-36.dsl.teksavvy.com (HELO ceviche.home) ([206.248.132.36]) by ironport2-out.teksavvy.com with ESMTP; 02 Feb 2009 12:14:47 -0500 Original-Received: by ceviche.home (Postfix, from userid 20848) id 02A30B4187; Sun, 1 Feb 2009 20:26:28 -0500 (EST) In-Reply-To: (Richard M. Stallman's message of "Sun, 01 Feb 2009 17:49:09 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:108603 Archived-At: > 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)