emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs-26 7ed7360: Fix problems when editing raw undecoded


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs-26 7ed7360: Fix problems when editing raw undecoded message (Bug#28671)
Date: Mon, 9 Oct 2017 09:55:37 -0400 (EDT)

branch: emacs-26
commit 7ed73608559c2254ac66cf440f6f9eec934c4dae
Author: Ken Olum <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix problems when editing raw undecoded message (Bug#28671)
    
    * lisp/mail/rmailedit.el (rmail-cease-edit): If rmail-old-mime-state
    is set, meaning that we are editing the raw message, do not
    encode it again.  Delete old body after, not before, inserting
    new, to avoid moving marker at beginning of next message.
---
 lisp/mail/rmailedit.el | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/lisp/mail/rmailedit.el b/lisp/mail/rmailedit.el
index b91a815..640febd 100644
--- a/lisp/mail/rmailedit.el
+++ b/lisp/mail/rmailedit.el
@@ -312,26 +312,34 @@ This function runs the hooks `text-mode-hook' and 
`rmail-edit-mode-hook'.
             (data-buffer (current-buffer))
             (start (copy-marker (point) nil)) ; new body will be between
             (end (copy-marker (point) t)))    ; these two markers
-        (with-current-buffer rmail-view-buffer
-          (encode-coding-region headers-end (point-max) coding-system
-                                data-buffer))
-        (delete-region end (point-max))
+        (if mime-state
+            ;; Message is already in encoded state
+            (insert-buffer-substring rmail-view-buffer headers-end
+                                     (with-current-buffer rmail-view-buffer
+                                       (point-max)))
+          (with-current-buffer rmail-view-buffer
+            (encode-coding-region headers-end (point-max) coding-system
+                                  data-buffer)))
        ;; Apply to the mbox buffer any changes in header fields
        ;; that the user made while editing in the view buffer.
-       (rmail-edit-update-headers (rmail-edit-diff-headers
+        (rmail-edit-update-headers (rmail-edit-diff-headers
                                    rmail-old-headers new-headers))
        ;; Re-apply content-transfer-encoding, if any, on the message body.
        (cond
+        (mime-state)               ; if set, already transfer-encoded
         ((string= character-coding "quoted-printable")
-         (mail-quote-printable-region start (point-max)))
+         (mail-quote-printable-region start end))
         ((and (string= character-coding "base64") is-text-message)
-         (base64-encode-region start (point-max)))
+         (base64-encode-region start end))
         ((and (eq character-coding 'uuencode) is-text-message)
          (error "uuencoded messages are not supported")))
         ;; After encoding, make sure buffer ends with a blank line so as not to
         ;; run this message together with the following one.
-        (goto-char (point-max))
-        (rmail-ensure-blank-line))
+        (goto-char end)
+        (rmail-ensure-blank-line)
+        ;; Delete previous body.  This must be after all insertions at the end,
+        ;; so the marker for the beginning of the next message isn't messed up.
+        (delete-region end (point-max)))
       (rmail-set-attribute rmail-edited-attr-index t))
 ;;;??? BROKEN perhaps.
 ;;;    (if (boundp 'rmail-summary-vector)



reply via email to

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