Function: rmail-output
rmail-output is an autoloaded, interactive and byte-compiled function
defined in rmailout.el.gz.
Signature
(rmail-output FILE-NAME &optional COUNT NOATTRIBUTE NOT-RMAIL)
Documentation
Append this message to mail file FILE-NAME.
Writes mbox format, unless FILE-NAME exists and is Babyl format, in which case it writes Babyl.
Interactively, the default file name comes from rmail-default-file,
which is updated to the name you use in this command. In all uses, if
FILE-NAME is not absolute, it is expanded with the directory part of
rmail-default-file.
If a buffer is visiting FILE-NAME, adds the text to that buffer rather than saving the file directly. If the buffer is an Rmail buffer, updates it accordingly.
This command always outputs the complete message header, even if the header display is currently pruned.
If rmail-output-reset-deleted-flag is non-nil, the message's
deleted flag is reset in the message appended to the destination
file. Otherwise, the appended message will remain marked as
deleted if it was deleted before invoking this command.
Optional prefix argument COUNT (default 1) says to output that
many consecutive messages, starting with the current one (ignoring
deleted messages, unless rmail-output-reset-deleted-flag is
non-nil). If rmail-delete-after-output is non-nil, deletes
messages after output.
The optional third argument NOATTRIBUTE, if non-nil, says not to
set the filed attribute, and not to display a "Wrote file"
message (if writing a file directly).
Set the optional fourth argument NOT-RMAIL non-nil if you call this from a non-Rmail buffer. In this case, COUNT is ignored.
Probably introduced at or before Emacs version 18.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/mail/rmailout.el.gz
;;; There are functions elsewhere in Emacs that use this function;
;;; look at them before you change the calling method.
;;;###autoload
(defun rmail-output (file-name &optional count noattribute not-rmail)
"Append this message to mail file FILE-NAME.
Writes mbox format, unless FILE-NAME exists and is Babyl format, in which
case it writes Babyl.
Interactively, the default file name comes from `rmail-default-file',
which is updated to the name you use in this command. In all uses, if
FILE-NAME is not absolute, it is expanded with the directory part of
`rmail-default-file'.
If a buffer is visiting FILE-NAME, adds the text to that buffer
rather than saving the file directly. If the buffer is an Rmail
buffer, updates it accordingly.
This command always outputs the complete message header, even if
the header display is currently pruned.
If `rmail-output-reset-deleted-flag' is non-nil, the message's
deleted flag is reset in the message appended to the destination
file. Otherwise, the appended message will remain marked as
deleted if it was deleted before invoking this command.
Optional prefix argument COUNT (default 1) says to output that
many consecutive messages, starting with the current one (ignoring
deleted messages, unless `rmail-output-reset-deleted-flag' is
non-nil). If `rmail-delete-after-output' is non-nil, deletes
messages after output.
The optional third argument NOATTRIBUTE, if non-nil, says not to
set the `filed' attribute, and not to display a \"Wrote file\"
message (if writing a file directly).
Set the optional fourth argument NOT-RMAIL non-nil if you call this
from a non-Rmail buffer. In this case, COUNT is ignored."
(interactive
(list (rmail-output-read-file-name)
(prefix-numeric-value current-prefix-arg)))
(or count (setq count 1))
(setq file-name
(expand-file-name file-name
(and rmail-default-file
(file-name-directory rmail-default-file))))
;; Warn about creating new file.
(or (find-buffer-visiting file-name)
(file-exists-p file-name)
(yes-or-no-p (concat "\"" file-name "\" does not exist, create it? "))
(error "Output file does not exist"))
(if noattribute (setq noattribute 'nomsg))
(let ((babyl-format (and (file-readable-p file-name)
(mail-file-babyl-p file-name)))
(cur (current-buffer))
(buf (find-buffer-visiting file-name)))
;; If a babyl file is visited in a buffer, is it visited as babyl
;; or as mbox?
(and babyl-format buf
(with-current-buffer buf
(save-restriction
(widen)
(save-excursion
(goto-char (point-min))
(setq babyl-format
(looking-at "BABYL OPTIONS:"))))))
(if not-rmail ; eg via message-fcc-handler-function
(with-temp-buffer
(insert-buffer-substring cur)
;; Output in the appropriate format.
(if babyl-format
(progn
(goto-char (point-min))
;; rmail-convert-to-babyl-format errors if no From line,
;; whereas rmail-output-as-mbox inserts one.
(or (looking-at "From ")
(insert (mail-mbox-from)))
(rmail-output-as-babyl file-name noattribute))
(rmail-output-as-mbox file-name noattribute)))
;; Called from an Rmail buffer.
(if rmail-buffer
(set-buffer rmail-buffer)
(error "There is no Rmail buffer"))
(if (zerop rmail-total-messages)
(error "No messages to output"))
(let ((orig-count count)
beg end delete-attr-reset-p)
(while (> count 0)
(when (and rmail-output-reset-deleted-flag
(rmail-message-deleted-p rmail-current-message))
(rmail-set-attribute rmail-deleted-attr-index nil)
(setq delete-attr-reset-p t))
;; Make sure we undo our messing with the DELETED attribute.
(unwind-protect
(progn
(setq beg (rmail-msgbeg rmail-current-message)
end (rmail-msgend rmail-current-message))
;; All access to the buffer's local variables is now finished...
(save-excursion
;; ... so it is ok to go to a different buffer.
(if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
(setq cur (current-buffer))
(save-restriction
(widen)
(with-temp-buffer
(insert-buffer-substring cur beg end)
(if babyl-format
(rmail-output-as-babyl file-name noattribute)
(rmail-output-as-mbox file-name noattribute))))))
(if delete-attr-reset-p
(rmail-set-attribute rmail-deleted-attr-index t)))
(or noattribute ; mark message as "filed"
(rmail-set-attribute rmail-filed-attr-index t))
(setq count (1- count))
(let ((next-message-p
(if rmail-output-reset-deleted-flag
(progn
(if rmail-delete-after-output
(rmail-delete-message))
(if (>= count 0)
(let ((msgnum rmail-current-message))
(rmail-next-message 1)
(eq rmail-current-message (1+ msgnum)))))
(if rmail-delete-after-output
(rmail-delete-forward)
(if (> count 0)
(rmail-next-undeleted-message 1)))))
(num-appended (- orig-count count)))
(if (and (> count 0) (not next-message-p))
(error "Only %d message%s appended" num-appended
(if (= num-appended 1) "" "s")))))))))