aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2011-11-15 21:06:06 -0500
committerGlenn Morris2011-11-15 21:06:06 -0500
commit6ad1cdded9db68c3152e15e46647ae53febca953 (patch)
treead42f37ecaebcc2c87f7b5873f2eec4be759949c
parentd20faa20cff77bc4b64a9ceb5da267996786853c (diff)
downloademacs-6ad1cdded9db68c3152e15e46647ae53febca953.tar.gz
emacs-6ad1cdded9db68c3152e15e46647ae53febca953.zip
Try to stop rmailedit destroying mime messages (bug#9840)
* lisp/mail/rmailedit.el: Require rmailmm when compiling. (rmail-old-mime-state): New declaration. (rmail-edit-current-message): If editing a mime message, edit the "raw" message from the mbox buffer. (rmail-cease-edit): Handle mime messages.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/mail/rmailedit.el37
2 files changed, 43 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 387afa667fe..384e7f276dc 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12011-11-16 Glenn Morris <rgm@gnu.org>
2
3 * mail/rmailedit.el: Require rmailmm when compiling.
4 (rmail-old-mime-state): New declaration.
5 (rmail-edit-current-message): If editing a mime message,
6 edit the "raw" message from the mbox buffer.
7 (rmail-cease-edit): Handle mime messages. (Bug#9840)
8
12011-11-15 Glenn Morris <rgm@gnu.org> 92011-11-15 Glenn Morris <rgm@gnu.org>
2 10
3 * mail/rmailmm.el (rmail-mime-toggle-raw): Remove entity arg, 11 * mail/rmailmm.el (rmail-mime-toggle-raw): Remove entity arg,
diff --git a/lisp/mail/rmailedit.el b/lisp/mail/rmailedit.el
index 868ca15923f..7e70f66ef11 100644
--- a/lisp/mail/rmailedit.el
+++ b/lisp/mail/rmailedit.el
@@ -78,6 +78,7 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
78 78
79 79
80(defvar rmail-old-text) 80(defvar rmail-old-text)
81(defvar rmail-old-mime-state)
81(defvar rmail-old-pruned nil 82(defvar rmail-old-pruned nil
82 "Non-nil means the message being edited originally had pruned headers.") 83 "Non-nil means the message being edited originally had pruned headers.")
83(put 'rmail-old-pruned 'permanent-local t) 84(put 'rmail-old-pruned 'permanent-local t)
@@ -86,6 +87,10 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
86 "Holds the headers of this message before editing started.") 87 "Holds the headers of this message before editing started.")
87(put 'rmail-old-headers 'permanent-local t) 88(put 'rmail-old-headers 'permanent-local t)
88 89
90;; Everything we use from here is a defsubst.
91(eval-when-compile
92 (require 'rmailmm))
93
89;;;###autoload 94;;;###autoload
90(defun rmail-edit-current-message () 95(defun rmail-edit-current-message ()
91 "Edit the contents of this message." 96 "Edit the contents of this message."
@@ -96,6 +101,28 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
96 (make-local-variable 'rmail-old-pruned) 101 (make-local-variable 'rmail-old-pruned)
97 (setq rmail-old-pruned (rmail-msg-is-pruned)) 102 (setq rmail-old-pruned (rmail-msg-is-pruned))
98 (rmail-edit-mode) 103 (rmail-edit-mode)
104 (set (make-local-variable 'rmail-old-mime-state)
105 (and rmail-enable-mime
106 ;; If you use something else, you are on your own.
107 (eq rmail-mime-feature 'rmailmm)
108 (rmail-mime-message-p)
109 (let ((entity (get-text-property (point-min) 'rmail-mime-entity)))
110 ;; rmailmm has got its hands on the message.
111 ;; Even if the message is in `raw' state, boundaries etc
112 ;; are still missing. All we can do is insert the real
113 ;; raw message. (Bug#9840)
114 (when (and entity
115 (not (equal "text/plain"
116 (car (rmail-mime-entity-type entity)))))
117 (let ((inhibit-read-only t))
118 (erase-buffer)
119 (insert-buffer-substring
120 rmail-view-buffer
121 (aref (rmail-mime-entity-header entity) 0)
122 (aref (rmail-mime-entity-body entity) 1)))
123 (goto-char (point-min))
124 ;; t = decoded; raw = raw.
125 (aref (aref (rmail-mime-entity-display entity) 0) 0)))))
99 (make-local-variable 'rmail-old-text) 126 (make-local-variable 'rmail-old-text)
100 (setq rmail-old-text 127 (setq rmail-old-text
101 (save-restriction 128 (save-restriction
@@ -134,7 +161,10 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
134 (error "There must be a blank line at the end of the headers")) 161 (error "There must be a blank line at the end of the headers"))
135 ;; Disguise any "From " lines so they don't start a new message. 162 ;; Disguise any "From " lines so they don't start a new message.
136 (goto-char (point-min)) 163 (goto-char (point-min))
137 (or rmail-old-pruned (forward-line 1)) 164 ;; This tries to skip the mbox From. FIXME less fragile to go to EOH?
165 (if (or rmail-old-mime-state
166 (not rmail-old-pruned))
167 (forward-line 1))
138 (while (re-search-forward "^>*From " nil t) 168 (while (re-search-forward "^>*From " nil t)
139 (beginning-of-line) 169 (beginning-of-line)
140 (insert ">") 170 (insert ">")
@@ -145,6 +175,7 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
145 (rmail-ensure-blank-line) 175 (rmail-ensure-blank-line)
146 (let ((old rmail-old-text) 176 (let ((old rmail-old-text)
147 (pruned rmail-old-pruned) 177 (pruned rmail-old-pruned)
178 (mime-state rmail-old-mime-state)
148 ;; People who know what they are doing might have modified the 179 ;; People who know what they are doing might have modified the
149 ;; buffer's encoding if editing the message included inserting 180 ;; buffer's encoding if editing the message included inserting
150 ;; characters that were unencodable by the original message's 181 ;; characters that were unencodable by the original message's
@@ -256,7 +287,9 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
256;;; (if (boundp 'rmail-summary-vector) 287;;; (if (boundp 'rmail-summary-vector)
257;;; (aset rmail-summary-vector (1- rmail-current-message) nil)) 288;;; (aset rmail-summary-vector (1- rmail-current-message) nil))
258 (rmail-show-message) 289 (rmail-show-message)
259 (rmail-toggle-header (if pruned 1 0))) 290 (rmail-toggle-header (if pruned 1 0))
291 ;; Restore mime display state.
292 (and mime-state (rmail-mime nil mime-state)))
260 (run-hooks 'rmail-mode-hook)) 293 (run-hooks 'rmail-mode-hook))
261 294
262(defun rmail-abort-edit () 295(defun rmail-abort-edit ()