- (case-fold-search t))
- (save-excursion
- (set-buffer tembuf)
- (erase-buffer)
- ;; If we can do it, read a little of the file
- ;; to check whether it is an RMAIL file.
- ;; If it is, don't mess it up.
- (if (fboundp 'insert-partial-file-contents)
- (progn
- (insert-partial-file-contents file-name 0 20)
- (if (looking-at "BABYL OPTIONS:\n")
- (error (save-excursion
- (set-buffer rmailbuf)
- (substitute-command-keys
- "File %s is an RMAIL file; use the \\[rmail-output-to-rmail-file] command"))
- file-name))
- (erase-buffer)))
- (insert-buffer-substring rmailbuf)
- (insert "\n")
- (goto-char (point-min))
- (insert "From "
- (mail-strip-quoted-names (or (mail-fetch-field "from")
- (mail-fetch-field "really-from")
- (mail-fetch-field "sender")
- "unknown"))
- " " (or (mail-fetch-field "date") (current-time-string)) "\n")
- ;; ``Quote'' "\nFrom " as "\n>From "
- ;; (note that this isn't really quoting, as there is no requirement
- ;; that "\n[>]+From " be quoted in the same transparent way.)
- (while (search-forward "\nFrom " nil t)
- (forward-char -5)
- (insert ?>))
- (append-to-file (point-min) (point-max) file-name))
- (kill-buffer tembuf))
+ (original-headers-p
+ (and (not from-gnus)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
+ (goto-char (point-min))
+ (forward-line 1)
+ (= (following-char) ?0)))))
+ header-beginning
+ mail-from mime-version content-type)
+ (while (> count 0)
+ ;; Preserve the Mail-From and MIME-Version fields
+ ;; even if they have been pruned.
+ (or from-gnus
+ (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char (rmail-msgbeg rmail-current-message))
+ (setq header-beginning (point))
+ (search-forward "\n*** EOOH ***\n")
+ (narrow-to-region header-beginning (point))
+ (setq mail-from (mail-fetch-field "Mail-From"))
+ (unless rmail-enable-mime
+ (setq mime-version (mail-fetch-field "MIME-Version")
+ content-type (mail-fetch-field "Content-type"))))))
+ (save-excursion
+ (set-buffer tembuf)
+ (erase-buffer)
+ (insert-buffer-substring rmailbuf)
+ (when rmail-enable-mime
+ (if original-headers-p
+ (delete-region (goto-char (point-min))
+ (if (search-forward "\n*** EOOH ***\n")
+ (match-end 0)))
+ (goto-char (point-min))
+ (forward-line 2)
+ (delete-region (point-min)(point))
+ (search-forward "\n*** EOOH ***\n")
+ (delete-region (match-beginning 0)
+ (if (search-forward "\n\n")
+ (1- (match-end 0)))))
+ (setq buffer-file-coding-system (or rmail-file-coding-system
+ 'raw-text)))
+ (rmail-delete-unwanted-fields t)
+ (or (bolp) (insert "\n"))
+ (goto-char (point-min))
+ (if mail-from
+ (insert mail-from "\n")
+ (insert "From "
+ (mail-strip-quoted-names (or (mail-fetch-field "from")
+ (mail-fetch-field "really-from")
+ (mail-fetch-field "sender")
+ "unknown"))
+ " " (current-time-string) "\n"))
+ (if mime-version
+ (insert "MIME-Version: " mime-version
+ "\nContent-type: " content-type "\n"))
+ ;; ``Quote'' "\nFrom " as "\n>From "
+ ;; (note that this isn't really quoting, as there is no requirement
+ ;; that "\n[>]+From " be quoted in the same transparent way.)
+ (let ((case-fold-search nil))
+ (while (search-forward "\nFrom " nil t)
+ (forward-char -5)
+ (insert ?>)))
+ (write-region (point-min) (point-max) file-name t
+ (if noattribute 'nomsg)))
+ (or noattribute
+ (if (equal major-mode 'rmail-mode)
+ (rmail-set-attribute "filed" t)))
+ (setq count (1- count))
+ (or from-gnus
+ (let ((next-message-p
+ (if rmail-delete-after-output
+ (rmail-delete-forward)
+ (if (> count 0)
+ (rmail-next-undeleted-message 1))))
+ (num-appended (- orig-count count)))
+ (if (and next-message-p original-headers-p)
+ (rmail-toggle-header))
+ (if (and (> count 0) (not next-message-p))
+ (progn
+ (error
+ (save-excursion
+ (set-buffer rmailbuf)
+ (format "Only %d message%s appended" num-appended
+ (if (= num-appended 1) "" "s"))))
+ (setq count 0))))))
+ (kill-buffer tembuf))))
+
+;;;###autoload
+(defun rmail-output-body-to-file (file-name)
+ "Write this message body to the file FILE-NAME.
+FILE-NAME defaults, interactively, from the Subject field of the message."
+ (interactive
+ (let ((default-file
+ (or (mail-fetch-field "Subject")
+ rmail-default-body-file)))
+ (list (setq rmail-default-body-file
+ (read-file-name
+ "Output message body to file: "
+ (and default-file (file-name-directory default-file))
+ default-file
+ nil default-file)))))
+ (setq file-name
+ (expand-file-name file-name
+ (and rmail-default-body-file
+ (file-name-directory rmail-default-body-file))))
+ (save-excursion
+ (goto-char (point-min))
+ (search-forward "\n\n")
+ (and (file-exists-p file-name)
+ (not (y-or-n-p (message "File %s exists; overwrite? " file-name)))
+ (error "Operation aborted"))
+ (write-region (point) (point-max) file-name)