+ (with-current-buffer rmail-buffer
+ (widen)
+ (let ((error t)
+ (buffer-read-only nil))
+ (goto-char (rmail-msgend rmail-current-message))
+ (let ((msg-copy (buffer-substring (rmail-msgbeg rmail-current-message)
+ (rmail-msgend rmail-current-message))))
+ (narrow-to-region (point) (point))
+ (insert msg-copy))
+ (narrow-to-region (point-min) (1- (point-max)))
+ (unwind-protect
+ (progn
+ (save-restriction
+ (goto-char (point-min))
+ (delete-region (point-min)
+ (progn (search-forward "\n*** EOOH ***\n" nil t)
+ (point)))
+ (insert "\n" rmail-mail-separator)
+ (narrow-to-region (point)
+ (point-max))
+ (let ((fill-prefix "")
+ (case-fold-search t)
+ digest-name type start end separator fun-list sep-list)
+ (setq digest-name (mail-strip-quoted-names
+ (save-restriction
+ (search-forward "\n\n" nil 'move)
+ (setq start (point))
+ (narrow-to-region (point-min) start)
+ (or (mail-fetch-field "Reply-To")
+ (mail-fetch-field "To")
+ (mail-fetch-field "Apparently-To")
+ (mail-fetch-field "From")))))
+ (unless digest-name
+ (error "Message is not a digest--bad header"))
+
+ (setq fun-list rmail-digest-methods)
+ (while (and fun-list
+ (null (setq sep-list (funcall (car fun-list)))))
+ (setq fun-list (cdr fun-list)))
+ (unless sep-list
+ (error "Message is not a digest--no messages found"))
+
+ ;;; Split the digest into separate rmail messages
+ (while sep-list
+ (let ((start (caar sep-list))
+ (end (cdar sep-list)))
+ (delete-region start end)
+ (goto-char start)
+ (insert rmail-mail-separator)
+ (search-forward "\n\n" (caar (cdr sep-list)) 'move)
+ (save-restriction
+ (narrow-to-region end (point))
+ (unless (mail-fetch-field "To")
+ (goto-char start)
+ (insert "To: " digest-name "\n")))
+ (set-marker start nil)
+ (set-marker end nil))
+ (setq sep-list (cdr sep-list)))))
+
+ (setq error nil)
+ (message "Message successfully undigestified")
+ (let ((n rmail-current-message))
+ (rmail-forget-messages)
+ (rmail-show-message n)
+ (rmail-delete-forward)
+ (if (rmail-summary-exists)
+ (rmail-select-summary
+ (rmail-update-summary)))))
+ (cond (error
+ (narrow-to-region (point-min) (1+ (point-max)))
+ (delete-region (point-min) (point-max))
+ (rmail-show-message rmail-current-message)))))))
+\f
+;;;###autoload
+(defun unforward-rmail-message ()
+ "Extract a forwarded message from the containing message.
+This puts the forwarded message into a separate rmail message
+following the containing message."
+ (interactive)
+ ;; If we are in a summary buffer, switch to the Rmail buffer.
+ (unwind-protect
+ (with-current-buffer rmail-buffer
+ (goto-char (point-min))
+ (narrow-to-region (point)
+ (save-excursion (search-forward "\n\n") (point)))
+ (let ((buffer-read-only nil)
+ (old-fwd-from (mail-fetch-field "Forwarded-From" nil nil t))
+ (old-fwd-date (mail-fetch-field "Forwarded-Date" nil nil t))
+ (fwd-from (mail-fetch-field "From"))
+ (fwd-date (mail-fetch-field "Date"))
+ beg end prefix forward-msg)
+ (narrow-to-region (rmail-msgbeg rmail-current-message)
+ (rmail-msgend rmail-current-message))
+ (goto-char (point-min))
+ (cond ((re-search-forward rmail-forward-separator-regex nil t)
+ (forward-line 1)
+ (skip-chars-forward "\n")
+ (setq beg (point))
+ (setq end (if (re-search-forward "^----.*[^- \t\n]" nil t)
+ (match-beginning 0) (point-max)))
+ (setq forward-msg
+ (replace-regexp-in-string
+ "^- -" "-" (buffer-substring beg end))))
+ ((and (re-search-forward "^\\(> ?\\)[a-zA-Z-]+: .*\n" nil t)
+ (setq beg (match-beginning 0))
+ (setq prefix (match-string-no-properties 1))
+ (goto-char beg)
+ (looking-at (concat "\\(" prefix ".+\n\\)*"
+ prefix "Date: ."))
+ (looking-at (concat "\\(" prefix ".+\n\\)*"
+ prefix "From: .+\n"
+ "\\(" prefix ".+\n\\)*"
+ "\\(> ?\\)?\n" prefix)))
+ (re-search-forward "^[^>\n]" nil 'move)
+ (backward-char)
+ (skip-chars-backward " \t\n")
+ (forward-line 1)
+ (setq end (point))
+ (setq forward-msg
+ (replace-regexp-in-string
+ (if (string= prefix ">") "^>" "> ?")
+ "" (buffer-substring beg end))))
+ (t
+ (error "No forwarded message found")))
+ (widen)
+ (goto-char (rmail-msgend rmail-current-message))
+ (narrow-to-region (point) (point))
+ (insert rmail-mail-separator)
+ (narrow-to-region (point) (point))
+ (while old-fwd-from
+ (insert "Forwarded-From: " (car old-fwd-from) "\n")
+ (insert "Forwarded-Date: " (car old-fwd-date) "\n")
+ (setq old-fwd-from (cdr old-fwd-from))
+ (setq old-fwd-date (cdr old-fwd-date)))
+ (insert "Forwarded-From: " fwd-from "\n")
+ (insert "Forwarded-Date: " fwd-date "\n")
+ (insert forward-msg)