summaryrefslogtreecommitdiff
path: root/lisp/mail/rmailedit.el
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2009-10-06 02:37:22 +0000
committerGlenn Morris <rgm@gnu.org>2009-10-06 02:37:22 +0000
commit25ab03020175918134bf9ba7f63c5e00750baa84 (patch)
tree3a87d2e3d79e19dd8aefb9ac52895fdf01fc0926 /lisp/mail/rmailedit.el
parent00169eb6835a00ca198aea8d3d6816d6dda5e4c0 (diff)
(rmail-cease-edit): If there is a Content-Type header we don't
understand, don't insert another. (Bug#4624) If changing mime charset, insert the new one in the right place.
Diffstat (limited to 'lisp/mail/rmailedit.el')
-rw-r--r--lisp/mail/rmailedit.el65
1 files changed, 37 insertions, 28 deletions
diff --git a/lisp/mail/rmailedit.el b/lisp/mail/rmailedit.el
index e119ed2f133..48df2c2e951 100644
--- a/lisp/mail/rmailedit.el
+++ b/lisp/mail/rmailedit.el
@@ -168,35 +168,43 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
(string= old (buffer-substring (point-min) (point-max))))
(setq old nil)
(goto-char (point-min))
- ;; If they changed the message's encoding, rewrite the charset=
- ;; header for them, so that subsequent rmail-show-message
- ;; decodes it correctly.
- (let ((buffer-read-only nil)
- (new-coding (coding-system-base edited-coding))
- old-coding mime-charset mime-beg mime-end)
- (when (re-search-forward rmail-mime-charset-pattern
- (1- (save-excursion (search-forward "\n\n")))
- 'move)
- (setq mime-beg (match-beginning 1)
- mime-end (match-end 1)
- old-coding (coding-system-from-name (match-string 1))))
- (setq mime-charset
- (symbol-name
- (or (coding-system-get new-coding :mime-charset)
- (if (coding-system-equal new-coding 'undecided)
- 'us-ascii
- new-coding))))
- (cond
- ((null old-coding)
- ;; If there was no charset= spec, insert one.
- (insert "Content-type: text/plain; charset=" mime-charset "\n"))
- ((not (coding-system-equal (coding-system-base old-coding)
- new-coding))
- (delete-region mime-beg mime-end)
- (insert mime-charset))))
- (goto-char (point-min))
+ ;; FIXME the edit may have inadvertently removed this.
(search-forward "\n\n")
- (setq headers-end (point))
+ (setq headers-end (point-marker))
+ (goto-char (point-min))
+ (save-restriction
+ (narrow-to-region (point) headers-end)
+ ;; If they changed the message's encoding, rewrite the charset=
+ ;; header for them, so that subsequent rmail-show-message
+ ;; decodes it correctly.
+ (let* ((buffer-read-only nil)
+ (new-coding (coding-system-base edited-coding))
+ (mime-charset (symbol-name
+ (or (coding-system-get new-coding :mime-charset)
+ (if (coding-system-equal new-coding
+ 'undecided)
+ 'us-ascii
+ new-coding))))
+ old-coding mime-beg mime-end content-type)
+ (if (re-search-forward rmail-mime-charset-pattern nil 'move)
+ (setq mime-beg (match-beginning 1)
+ mime-end (match-end 1)
+ old-coding (coding-system-from-name (match-string 1)))
+ (setq content-type (mail-fetch-field "Content-Type")))
+ (cond
+ ;; No match for rmail-mime-charset-pattern, but there was some
+ ;; other Content-Type. We should not insert another. (Bug#4624)
+ (content-type)
+ ((null old-coding)
+ ;; If there was no charset= spec, insert one.
+ (backward-char 1)
+ (insert "Content-type: text/plain; charset=" mime-charset "\n"))
+ ((not (coding-system-equal (coding-system-base old-coding)
+ new-coding))
+ (goto-char mime-end)
+ (delete-region mime-beg mime-end)
+ (insert mime-charset)))))
+ (goto-char headers-end)
(setq new-headers (rmail-edit-headers-alist t))
(rmail-swap-buffers-maybe)
(narrow-to-region (rmail-msgbeg rmail-current-message)
@@ -205,6 +213,7 @@ This function runs the hooks `text-mode-hook' and `rmail-edit-mode-hook'.
(setq limit
(save-excursion
(goto-char (point-min))
+ ;; FIXME this should not be using NOERROR.
(search-forward "\n\n" nil t)))
;; All 3 of the functions we call below assume the buffer was
;; narrowed to just the headers of the message.