aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2001-06-29 03:17:10 +0000
committerRichard M. Stallman2001-06-29 03:17:10 +0000
commited104a87a987f4e1c557a29a4c44060e72baa8fe (patch)
tree9cf5192db2aece8a3e34145eadcbdc27728d510c
parent6519817ea6e949b4f99f03cbea8391acfde3073d (diff)
downloademacs-ed104a87a987f4e1c557a29a4c44060e72baa8fe.tar.gz
emacs-ed104a87a987f4e1c557a29a4c44060e72baa8fe.zip
(rmail-reformat-message): Bind inhibit-read-only to t.
(rmail-msg-restore-non-pruned-header): Likewise. If point was in the old pruned header, put it at the top. (rmail-msg-prune-header): If point was at the top, keep it there. (rmail-narrow-to-non-pruned-header): New function. (rmail-retry-failure): Use rmail-narrow-to-non-pruned-header.
-rw-r--r--lisp/mail/rmail.el253
1 files changed, 136 insertions, 117 deletions
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index a69ac40ae5c..7fd90ff965b 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -1876,7 +1876,7 @@ It returns t if it got any new messages."
1876 (forward-line 1) 1876 (forward-line 1)
1877 (if (/= (following-char) ?0) 1877 (if (/= (following-char) ?0)
1878 (error "Bad format in RMAIL file.")) 1878 (error "Bad format in RMAIL file."))
1879 (let ((buffer-read-only nil) 1879 (let ((inhibit-read-only t)
1880 (delta (- (buffer-size) end))) 1880 (delta (- (buffer-size) end)))
1881 (delete-char 1) 1881 (delete-char 1)
1882 (insert ?1) 1882 (insert ?1)
@@ -1947,9 +1947,12 @@ Otherwise, delete all header fields whose names match `rmail-ignored-headers'."
1947 (= (following-char) ?1)))) 1947 (= (following-char) ?1))))
1948 1948
1949(defun rmail-msg-restore-non-pruned-header () 1949(defun rmail-msg-restore-non-pruned-header ()
1950 (save-excursion 1950 (let ((old-point (point))
1951 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max)) 1951 new-point
1952 (let (new-start) 1952 new-start
1953 (inhibit-read-only t))
1954 (save-excursion
1955 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1953 (goto-char (point-min)) 1956 (goto-char (point-min))
1954 (forward-line 1) 1957 (forward-line 1)
1955 ;; Change 1 to 0. 1958 ;; Change 1 to 0.
@@ -1968,14 +1971,23 @@ Otherwise, delete all header fields whose names match `rmail-ignored-headers'."
1968 (forward-line -1) 1971 (forward-line -1)
1969 (let ((start (point))) 1972 (let ((start (point)))
1970 (search-forward "\n\n") 1973 (search-forward "\n\n")
1974 (if (and (<= start old-point)
1975 (<= old-point (point)))
1976 (setq new-point new-start))
1971 (delete-region start (point))) 1977 (delete-region start (point)))
1972 ;; Narrow to after the new EOOH line. 1978 ;; Narrow to after the new EOOH line.
1973 (narrow-to-region new-start (point-max))))) 1979 (narrow-to-region new-start (point-max)))
1980 (if new-point
1981 (goto-char new-point))))
1974 1982
1975(defun rmail-msg-prune-header () 1983(defun rmail-msg-prune-header ()
1976 (save-excursion 1984 (let ((new-point
1977 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max)) 1985 (= (point) (point-min))))
1978 (rmail-reformat-message (point-min) (point-max)))) 1986 (save-excursion
1987 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
1988 (rmail-reformat-message (point-min) (point-max)))
1989 (if new-point
1990 (goto-char (point-min)))))
1979 1991
1980(defun rmail-toggle-header (&optional arg) 1992(defun rmail-toggle-header (&optional arg)
1981 "Show original message header if pruned header currently shown, or vice versa. 1993 "Show original message header if pruned header currently shown, or vice versa.
@@ -2035,6 +2047,25 @@ otherwise, show it in full."
2035 (- (window-height) 2)))))))))) 2047 (- (window-height) 2))))))))))
2036 (rmail-highlight-headers)))) 2048 (rmail-highlight-headers))))
2037 2049
2050(defun rmail-narrow-to-non-pruned-header ()
2051 "Narrow to the whole (original) header of the current message."
2052 (let (start end)
2053 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
2054 (goto-char (point-min))
2055 (forward-line 1)
2056 (if (= (following-char) ?1)
2057 (progn
2058 (forward-line 1)
2059 (setq start (point))
2060 (search-forward "*** EOOH ***\n")
2061 (setq end (match-beginning 0)))
2062 (forward-line 2)
2063 (setq start (point))
2064 (search-forward "\n\n")
2065 (setq end (1- (point))))
2066 (narrow-to-region start end)
2067 (goto-char start)))
2068
2038;; Lifted from repos-count-screen-lines. 2069;; Lifted from repos-count-screen-lines.
2039;; Return number of screen lines between START and END. 2070;; Return number of screen lines between START and END.
2040(defun rmail-count-screen-lines (start end) 2071(defun rmail-count-screen-lines (start end)
@@ -3347,115 +3378,103 @@ specifying headers which should not be copied into the new message."
3347 (require 'mail-utils) 3378 (require 'mail-utils)
3348 (let ((rmail-this-buffer (current-buffer)) 3379 (let ((rmail-this-buffer (current-buffer))
3349 (msgnum rmail-current-message) 3380 (msgnum rmail-current-message)
3350 (pruned (rmail-msg-is-pruned)) 3381 bounce-start bounce-end bounce-indent resending
3351 bounce-start bounce-end bounce-indent resending) 3382 ;; Fetch any content-type header in current message
3352 (unwind-protect 3383 ;; Must search thru the whole unpruned header.
3353 (progn 3384 (content-type
3354 (save-excursion 3385 (save-excursion
3355 ;; Un-prune the header; we need to search the whole thing. 3386 (save-restriction
3356 (if pruned 3387 (rmail-narrow-to-non-pruned-header)
3357 (rmail-toggle-header 0)) 3388 (mail-fetch-field "Content-Type") ))))
3358 (goto-char (rmail-msgbeg msgnum)) 3389 (save-excursion
3359 (let* ((case-fold-search t) 3390 (goto-char (point-min))
3360 (top (point)) 3391 (let ((case-fold-search t))
3361 (content-type 3392 (if (and content-type
3362 (save-restriction 3393 (string-match
3363 ;; Fetch any content-type header in current message 3394 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3364 (search-forward "\n\n") (narrow-to-region top (point)) 3395 content-type))
3365 (mail-fetch-field "Content-Type") )) ) 3396 ;; Handle a MIME multipart bounce message.
3366 ;; Handle MIME multipart bounce messages 3397 (let ((codestring
3367 (if (and content-type 3398 (concat "\n--"
3368 (string-match 3399 (substring content-type (match-beginning 1)
3369 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?" 3400 (match-end 1)))))
3370 content-type)) 3401 (unless (re-search-forward mail-mime-unsent-header nil t)
3371 (let ((codestring 3402 (error "Cannot find beginning of header in failed message"))
3372 (concat "\n--" 3403 (unless (search-forward "\n\n" nil t)
3373 (substring content-type (match-beginning 1) 3404 (error "Cannot find start of Mime data in failed message"))
3374 (match-end 1))))) 3405 (setq bounce-start (point))
3375 (unless (re-search-forward mail-mime-unsent-header nil t) 3406 (if (search-forward codestring nil t)
3376 (error "Cannot find beginning of header in failed message")) 3407 (setq bounce-end (match-beginning 0))
3377 (unless (search-forward "\n\n" nil t) 3408 (setq bounce-end (point-max))))
3378 (error "Cannot find start of Mime data in failed message")) 3409 ;; Non-MIME bounce.
3379 (setq bounce-start (point)) 3410 (or (re-search-forward mail-unsent-separator nil t)
3380 (if (search-forward codestring nil t) 3411 (error "Cannot parse this as a failure message"))
3381 (setq bounce-end (match-beginning 0)) 3412 (skip-chars-forward "\n")
3382 (setq bounce-end (point-max))) 3413 ;; Support a style of failure message in which the original
3383 ) 3414 ;; message is indented, and included within lines saying
3384 ;; non-MIME bounce 3415 ;; `Start of returned message' and `End of returned message'.
3385 (or (re-search-forward mail-unsent-separator nil t) 3416 (if (looking-at " +Received:")
3386 (error "Cannot parse this as a failure message")) 3417 (progn
3387 (skip-chars-forward "\n") 3418 (setq bounce-start (point))
3388 ;; Support a style of failure message in which the original 3419 (skip-chars-forward " ")
3389 ;; message is indented, and included within lines saying 3420 (setq bounce-indent (- (current-column)))
3390 ;; `Start of returned message' and `End of returned message'. 3421 (goto-char (point-max))
3391 (if (looking-at " +Received:") 3422 (re-search-backward "^End of returned message$" nil t)
3392 (progn 3423 (setq bounce-end (point)))
3393 (setq bounce-start (point)) 3424 ;; One message contained a few random lines before
3394 (skip-chars-forward " ") 3425 ;; the old message header. The first line of the
3395 (setq bounce-indent (- (current-column))) 3426 ;; message started with two hyphens. A blank line
3396 (goto-char (point-max)) 3427 ;; followed these random lines. The same line
3397 (re-search-backward "^End of returned message$" nil t) 3428 ;; beginning with two hyphens was possibly marking
3398 (setq bounce-end (point))) 3429 ;; the end of the message.
3399 ;; One message contained a few random lines before 3430 (if (looking-at "^--")
3400 ;; the old message header. The first line of the 3431 (let ((boundary (buffer-substring-no-properties
3401 ;; message started with two hyphens. A blank line 3432 (point)
3402 ;; followed these random lines. The same line 3433 (progn (end-of-line) (point)))))
3403 ;; beginning with two hyphens was possibly marking 3434 (search-forward "\n\n")
3404 ;; the end of the message. 3435 (skip-chars-forward "\n")
3405 (if (looking-at "^--") 3436 (setq bounce-start (point))
3406 (let ((boundary (buffer-substring-no-properties 3437 (goto-char (point-max))
3407 (point) 3438 (search-backward (concat "\n\n" boundary) bounce-start t)
3408 (progn (end-of-line) (point))))) 3439 (setq bounce-end (point)))
3409 (search-forward "\n\n") 3440 (setq bounce-start (point)
3410 (skip-chars-forward "\n") 3441 bounce-end (point-max)))
3411 (setq bounce-start (point)) 3442 (unless (search-forward "\n\n" nil t)
3412 (goto-char (point-max)) 3443 (error "Cannot find end of header in failed message"))))))
3413 (search-backward (concat "\n\n" boundary) bounce-start t) 3444 ;; We have found the message that bounced, within the current message.
3414 (setq bounce-end (point))) 3445 ;; Now start sending new message; default header fields from original.
3415 (setq bounce-start (point) 3446 ;; Turn off the usual actions for initializing the message body
3416 bounce-end (point-max))) 3447 ;; because we want to get only the text from the failure message.
3417 (unless (search-forward "\n\n" nil t) 3448 (let (mail-signature mail-setup-hook)
3418 (error "Cannot find end of header in failed message")) 3449 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
3419 )))) 3450 (list (list 'rmail-mark-message
3420 ;; Start sending new message; default header fields from original. 3451 rmail-this-buffer
3421 ;; Turn off the usual actions for initializing the message body 3452 (aref rmail-msgref-vector msgnum)
3422 ;; because we want to get only the text from the failure message. 3453 "retried")))
3423 (let (mail-signature mail-setup-hook) 3454 ;; Insert original text as initial text of new draft message.
3424 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer 3455 ;; Bind inhibit-read-only since the header delimiter
3425 (list (list 'rmail-mark-message 3456 ;; of the previous message was probably read-only.
3426 rmail-this-buffer 3457 (let ((inhibit-read-only t)
3427 (aref rmail-msgref-vector msgnum) 3458 rmail-displayed-headers
3428 "retried"))) 3459 rmail-ignored-headers)
3429 ;; Insert original text as initial text of new draft message. 3460 (erase-buffer)
3430 ;; Bind inhibit-read-only since the header delimiter 3461 (insert-buffer-substring rmail-this-buffer
3431 ;; of the previous message was probably read-only. 3462 bounce-start bounce-end)
3432 (let ((inhibit-read-only t) 3463 (goto-char (point-min))
3433 rmail-displayed-headers 3464 (if bounce-indent
3434 rmail-ignored-headers) 3465 (indent-rigidly (point-min) (point-max) bounce-indent))
3435 (erase-buffer) 3466 (rmail-clear-headers rmail-retry-ignored-headers)
3436 (insert-buffer-substring rmail-this-buffer 3467 (rmail-clear-headers "^sender:\\|^return-path:\\|^received:")
3437 bounce-start bounce-end) 3468 (mail-sendmail-delimit-header)
3438 (goto-char (point-min)) 3469 (save-restriction
3439 (if bounce-indent 3470 (narrow-to-region (point-min) (mail-header-end))
3440 (indent-rigidly (point-min) (point-max) bounce-indent)) 3471 (setq resending (mail-fetch-field "resent-to"))
3441 (rmail-clear-headers rmail-retry-ignored-headers) 3472 (if mail-self-blind
3442 (rmail-clear-headers "^sender:\\|^return-path:\\|^received:") 3473 (if resending
3443 (mail-sendmail-delimit-header) 3474 (insert "Resent-Bcc: " (user-login-name) "\n")
3444 (save-restriction 3475 (insert "BCC: " (user-login-name) "\n"))))
3445 (narrow-to-region (point-min) (mail-header-end)) 3476 (goto-char (point-min))
3446 (setq resending (mail-fetch-field "resent-to")) 3477 (mail-position-on-field (if resending "Resent-To" "To") t))))))
3447 (if mail-self-blind
3448 (if resending
3449 (insert "Resent-Bcc: " (user-login-name) "\n")
3450 (insert "BCC: " (user-login-name) "\n"))))
3451 (goto-char (point-min))
3452 (mail-position-on-field (if resending "Resent-To" "To") t)))))
3453 ;; save-window-excursion is needed because of the switch-to-buffer
3454 ;; in rmail-toggle-header.
3455 (save-window-excursion
3456 (with-current-buffer rmail-this-buffer
3457 (if pruned
3458 (rmail-toggle-header 1)))))))
3459 3478
3460(defun rmail-summary-exists () 3479(defun rmail-summary-exists ()
3461 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists. 3480 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.