comparison lisp/mail/rmailedit.el @ 105602:6e207d2a8bc6

(rmail-cease-edit): Give an error if the end of the headers cannot be located. Simplify, subtracting superflous save-excursions. (See http://lists.gnu.org/archive/html/bug-gnu-emacs/2009-10/msg00182.html)
author Glenn Morris <rgm@gnu.org>
date Thu, 15 Oct 2009 06:00:20 +0000
parents b9bdbb16b3fa
children 1d1d5d9bd884
comparison
equal deleted inserted replaced
105601:68686d39c93a 105602:6e207d2a8bc6
124 (interactive) 124 (interactive)
125 (if (rmail-summary-exists) 125 (if (rmail-summary-exists)
126 (with-current-buffer rmail-summary-buffer 126 (with-current-buffer rmail-summary-buffer
127 (rmail-summary-enable))) 127 (rmail-summary-enable)))
128 (widen) 128 (widen)
129 (goto-char (point-min))
130 ;; This is far from ideal. The edit may have inadvertently
131 ;; removed the blank line at the end of the headers, but there
132 ;; are almost certainly other blank lines.
133 (or (search-forward "\n\n" nil t)
134 (error "There must be a blank line at the end of the headers"))
129 ;; Disguise any "From " lines so they don't start a new message. 135 ;; Disguise any "From " lines so they don't start a new message.
130 (save-excursion 136 (goto-char (point-min))
131 (goto-char (point-min)) 137 (or rmail-old-pruned (forward-line 1))
132 (or rmail-old-pruned (forward-line 1)) 138 (while (re-search-forward "^>*From " nil t)
133 (while (re-search-forward "^>*From " nil t) 139 (beginning-of-line)
134 (beginning-of-line) 140 (insert ">")
135 (insert ">") 141 (forward-line))
136 (forward-line)))
137 ;; Make sure buffer ends with a blank line so as not to run this 142 ;; Make sure buffer ends with a blank line so as not to run this
138 ;; message together with the following one. 143 ;; message together with the following one.
139 (save-excursion 144 (goto-char (point-max))
140 (goto-char (point-max)) 145 (rmail-ensure-blank-line)
141 (rmail-ensure-blank-line))
142 (let ((old rmail-old-text) 146 (let ((old rmail-old-text)
143 (pruned rmail-old-pruned) 147 (pruned rmail-old-pruned)
144 ;; People who know what they are doing might have modified the 148 ;; People who know what they are doing might have modified the
145 ;; buffer's encoding if editing the message included inserting 149 ;; buffer's encoding if editing the message included inserting
146 ;; characters that were unencodable by the original message's 150 ;; characters that were unencodable by the original message's
166 ;; If text has really changed, mark message as edited. 170 ;; If text has really changed, mark message as edited.
167 (unless (and (= (length old) (- (point-max) (point-min))) 171 (unless (and (= (length old) (- (point-max) (point-min)))
168 (string= old (buffer-substring (point-min) (point-max)))) 172 (string= old (buffer-substring (point-min) (point-max))))
169 (setq old nil) 173 (setq old nil)
170 (goto-char (point-min)) 174 (goto-char (point-min))
171 ;; FIXME the edit may have inadvertently removed this.
172 (search-forward "\n\n") 175 (search-forward "\n\n")
173 (setq headers-end (point-marker)) 176 (setq headers-end (point-marker))
174 (goto-char (point-min)) 177 (goto-char (point-min))
175 (save-restriction 178 (save-restriction
176 (narrow-to-region (point) headers-end) 179 (narrow-to-region (point) headers-end)
202 ((not (coding-system-equal (coding-system-base old-coding) 205 ((not (coding-system-equal (coding-system-base old-coding)
203 new-coding)) 206 new-coding))
204 (goto-char mime-end) 207 (goto-char mime-end)
205 (delete-region mime-beg mime-end) 208 (delete-region mime-beg mime-end)
206 (insert mime-charset))))) 209 (insert mime-charset)))))
207 (goto-char headers-end)
208 (setq new-headers (rmail-edit-headers-alist t)) 210 (setq new-headers (rmail-edit-headers-alist t))
209 (rmail-swap-buffers-maybe) 211 (rmail-swap-buffers-maybe)
210 (narrow-to-region (rmail-msgbeg rmail-current-message) 212 (narrow-to-region (rmail-msgbeg rmail-current-message)
211 (rmail-msgend rmail-current-message)) 213 (rmail-msgend rmail-current-message))
214 (goto-char (point-min))
215 (setq limit (search-forward "\n\n"))
212 (save-restriction 216 (save-restriction
213 (setq limit
214 (save-excursion
215 (goto-char (point-min))
216 ;; FIXME this should not be using NOERROR.
217 (search-forward "\n\n" nil t)))
218 ;; All 3 of the functions we call below assume the buffer was 217 ;; All 3 of the functions we call below assume the buffer was
219 ;; narrowed to just the headers of the message. 218 ;; narrowed to just the headers of the message.
220 (narrow-to-region (rmail-msgbeg rmail-current-message) limit) 219 (narrow-to-region (point-min) limit)
221 (setq character-coding 220 (setq character-coding
222 (mail-fetch-field "content-transfer-encoding") 221 (mail-fetch-field "content-transfer-encoding")
223 is-text-message (rmail-is-text-p) 222 is-text-message (rmail-is-text-p)
224 coding-system (if (and edited-coding 223 coding-system (if (and edited-coding
225 (not (coding-system-equal 224 (not (coding-system-equal
254 (error "uuencoded messages are not supported")))) 253 (error "uuencoded messages are not supported"))))
255 (rmail-set-attribute rmail-edited-attr-index t)) 254 (rmail-set-attribute rmail-edited-attr-index t))
256 ;;??? BROKEN perhaps. 255 ;;??? BROKEN perhaps.
257 ;;; (if (boundp 'rmail-summary-vector) 256 ;;; (if (boundp 'rmail-summary-vector)
258 ;;; (aset rmail-summary-vector (1- rmail-current-message) nil)) 257 ;;; (aset rmail-summary-vector (1- rmail-current-message) nil))
259 (save-excursion 258 (rmail-show-message)
260 (rmail-show-message) 259 (rmail-toggle-header (if pruned 1 0)))
261 (rmail-toggle-header (if pruned 1 0))))
262 (run-hooks 'rmail-mode-hook)) 260 (run-hooks 'rmail-mode-hook))
263 261
264 (defun rmail-abort-edit () 262 (defun rmail-abort-edit ()
265 "Abort edit of current message; restore original contents." 263 "Abort edit of current message; restore original contents."
266 (interactive) 264 (interactive)