This puts the forwarded message into a separate rmail message
following the containing message."
(interactive)
- (narrow-to-region (rmail-msgbeg rmail-current-message)
- (rmail-msgend rmail-current-message))
- (goto-char (point-min))
- (let (beg end (buffer-read-only nil) msg-string who-forwarded-it)
- (setq who-forwarded-it (mail-fetch-field "From"))
- (if (re-search-forward "^----" nil t)
- nil
- (error "No forwarded message"))
- (forward-line 1)
- (setq beg (point))
- (if (re-search-forward "^----" nil t)
- (setq end (match-beginning 0))
- (error "No terminator for forwarded message"))
- (widen)
- (setq msg-string (buffer-substring beg end))
- (goto-char (rmail-msgend rmail-current-message))
- (narrow-to-region (point) (point))
- (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
- (narrow-to-region (point) (point))
- (insert "Forwarded-by: " who-forwarded-it "\n")
- (insert msg-string)
- (goto-char (point-min))
- (while (not (eobp))
- (if (looking-at "- ")
- (delete-region (point) (+ 2 (point))))
- (forward-line 1))
- (let ((n rmail-current-message))
- (rmail-forget-messages)
- (rmail-show-message n)
- (if (rmail-summary-exists)
- (rmail-select-summary
- (rmail-update-summary))))))
+ ;; Don't use save-excursion because we don't want to restore point
+ ;; in the case where we do not switch buffers.
+ (let ((obuf (current-buffer)))
+ (unwind-protect
+ (progn
+ ;; If we are in a summary buffer, switch to the Rmail buffer.
+ (if (local-variable-p 'rmail-buffer)
+ (set-buffer rmail-buffer))
+ (narrow-to-region (rmail-msgbeg rmail-current-message)
+ (rmail-msgend rmail-current-message))
+ (goto-char (point-min))
+ (let (beg end (buffer-read-only nil) msg-string who-forwarded-it)
+ (setq who-forwarded-it (mail-fetch-field "From"))
+ (if (re-search-forward "^----" nil t)
+ nil
+ (error "No forwarded message"))
+ (forward-line 1)
+ (setq beg (point))
+ (if (re-search-forward "^----" nil t)
+ (setq end (match-beginning 0))
+ (error "No terminator for forwarded message"))
+ (widen)
+ (setq msg-string (buffer-substring beg end))
+ (goto-char (rmail-msgend rmail-current-message))
+ (narrow-to-region (point) (point))
+ (insert "\^_\^L\n0, unseen,,\n*** EOOH ***\n")
+ (narrow-to-region (point) (point))
+ (insert "Forwarded-by: " who-forwarded-it "\n")
+ (insert msg-string)
+ (goto-char (point-min))
+ (while (not (eobp))
+ (if (looking-at "- ")
+ (delete-region (point) (+ 2 (point))))
+ (forward-line 1))
+ (let ((n rmail-current-message))
+ (rmail-forget-messages)
+ (rmail-show-message n)
+ (if (rmail-summary-exists)
+ (rmail-select-summary
+ (rmail-update-summary))))))
+ (set-buffer obuf))))
;;; undigest.el ends here