aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2009-02-21 15:06:12 +0000
committerEli Zaretskii2009-02-21 15:06:12 +0000
commitff4abce949adc72b6a55ee648945542027625573 (patch)
treecd00daf5a747facc726e6691fb3f5726337c7a4f
parent3a6aa9653a4c1bd913224aa41cad3b0f7c6ba750 (diff)
downloademacs-ff4abce949adc72b6a55ee648945542027625573.tar.gz
emacs-ff4abce949adc72b6a55ee648945542027625573.zip
(rmail-cease-edit): Notice changes in buffer's encoding during editing.
Make sure to use encoding that can safely encode the message. Rewrite MIME charset= header if the new encoding is different from the old one.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/mail/rmailedit.el43
2 files changed, 49 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0c3db1833d8..5e018f9d5f5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12009-02-21 Eli Zaretskii <eliz@gnu.org>
2
3 * mail/rmailedit.el (rmail-cease-edit): Notice changes in buffer's
4 encoding during editing. Make sure to use encoding that can
5 safely encode the message. Rewrite MIME charset= header if the
6 new encoding is different from the old one.
7
12009-02-21 Glenn Morris <rgm@gnu.org> 82009-02-21 Glenn Morris <rgm@gnu.org>
2 9
3 * mail/supercite.el (sc-mail-glom-frame): Handle a "From " line 10 * mail/supercite.el (sc-mail-glom-frame): Handle a "From " line
diff --git a/lisp/mail/rmailedit.el b/lisp/mail/rmailedit.el
index 826e5da06e3..46c1ab6e03c 100644
--- a/lisp/mail/rmailedit.el
+++ b/lisp/mail/rmailedit.el
@@ -136,9 +136,18 @@ This functions runs the normal hook `rmail-edit-mode-hook'.
136 (insert "\n"))) 136 (insert "\n")))
137 (let ((old rmail-old-text) 137 (let ((old rmail-old-text)
138 (pruned rmail-old-pruned) 138 (pruned rmail-old-pruned)
139 ;; People who know what they are doing might have modified the
140 ;; buffer's encoding if editing the message included inserting
141 ;; characters that were unencodable by the original message's
142 ;; encoding. Make note of the new encoding and use it for
143 ;; encoding the edited message.
144 (edited-coding buffer-file-coding-system)
139 new-headers 145 new-headers
140 character-coding is-text-message coding-system 146 character-coding is-text-message coding-system
141 headers-end limit) 147 headers-end limit)
148 ;; Make sure `edited-coding' can safely encode the edited message.
149 (setq edited-coding
150 (select-safe-coding-system (point-min) (point-max) edited-coding))
142 ;; Go back to Rmail mode, but carefully. 151 ;; Go back to Rmail mode, but carefully.
143 (force-mode-line-update) 152 (force-mode-line-update)
144 (let ((rmail-buffer-swapped nil)) ; Prevent change-major-mode-hook 153 (let ((rmail-buffer-swapped nil)) ; Prevent change-major-mode-hook
@@ -154,6 +163,33 @@ This functions runs the normal hook `rmail-edit-mode-hook'.
154 (string= old (buffer-substring (point-min) (point-max)))) 163 (string= old (buffer-substring (point-min) (point-max))))
155 (setq old nil) 164 (setq old nil)
156 (goto-char (point-min)) 165 (goto-char (point-min))
166 ;; If they changed the message's encoding, rewrite the charset=
167 ;; header for them, so that subsequent rmail-show-message
168 ;; decodes it correctly.
169 (let ((buffer-read-only nil)
170 (new-coding (coding-system-base edited-coding))
171 old-coding mime-charset mime-beg mime-end)
172 (when (re-search-forward rmail-mime-charset-pattern
173 (1- (save-excursion (search-forward "\n\n")))
174 'move)
175 (setq mime-beg (match-beginning 1)
176 mime-end (match-end 1)
177 old-coding (coding-system-from-name (match-string 1))))
178 (setq mime-charset
179 (symbol-name
180 (or (coding-system-get new-coding :mime-charset)
181 (if (coding-system-equal new-coding 'undecided)
182 'us-ascii
183 new-coding))))
184 (cond
185 ((null old-coding)
186 ;; If there was no charset= spec, insert one.
187 (insert "Content-type: text/plain; charset=" mime-charset "\n"))
188 ((not (coding-system-equal (coding-system-base old-coding)
189 new-coding))
190 (delete-region mime-beg mime-end)
191 (insert mime-charset))))
192 (goto-char (point-min))
157 (search-forward "\n\n") 193 (search-forward "\n\n")
158 (setq headers-end (point)) 194 (setq headers-end (point))
159 (setq new-headers (rmail-edit-headers-alist t)) 195 (setq new-headers (rmail-edit-headers-alist t))
@@ -171,7 +207,12 @@ This functions runs the normal hook `rmail-edit-mode-hook'.
171 (setq character-coding 207 (setq character-coding
172 (mail-fetch-field "content-transfer-encoding") 208 (mail-fetch-field "content-transfer-encoding")
173 is-text-message (rmail-is-text-p) 209 is-text-message (rmail-is-text-p)
174 coding-system (rmail-get-coding-system))) 210 coding-system (if (and edited-coding
211 (not (coding-system-equal
212 (coding-system-base edited-coding)
213 'undecided)))
214 edited-coding
215 (rmail-get-coding-system))))
175 (if character-coding 216 (if character-coding
176 (setq character-coding (downcase character-coding))) 217 (setq character-coding (downcase character-coding)))
177 218