33.7 Copying Messages Out to Files
These commands copy messages from an Rmail file into another file.
o file RET
Append a full copy of the current message to the file file
( rmail-output
).
C-o file RET
Append a copy of the current message, as displayed, to the file
file ( rmail-output-as-seen
).
w file RET
Output just the message body to the file file, taking the default
file name from the message ‘ Subject
’ header.
The commands o
and C-o
copy the current message into a
specified file, adding it at the end. A positive prefix argument
serves as a repeat count: that many consecutive messages will be
copied to the specified file, starting with the current one and
ignoring deleted messages.
The two commands differ mainly in how much to copy: o
copies the
full message headers, even if they are not all visible, while
C-o
copies exactly the headers currently displayed and no more.
See Display of Messages. In addition, o
converts the message to
Babyl format (used by Rmail in Emacs version 22 and before) if the
file is in Babyl format; C-o
cannot output to Babyl files at
all.
If the output file is currently visited in an Emacs buffer, the output commands append the message to that buffer. It is up to you to save the buffer eventually in its file.
Sometimes you may receive a message whose body holds the contents of a
file. You can save the body to a file (excluding the message header)
with the w
command ( rmail-output-body-to-file
). Often
these messages contain the intended file name in the ‘ Subject
’
field, so the w
command uses the ‘ Subject
’ field as the
default for the output file name (after replacing some characters that
cannot be portably used in file names). However, the file name is
read using the minibuffer, so you can specify a different name if you
wish.
You can also output a message to an Rmail file chosen with a menu.
In the Classify menu, choose the Output Rmail File menu item; then
choose the Rmail file you want. This outputs the current message to
that file, like the o
command. The variables
rmail-secondary-file-directory
and
rmail-secondary-file-regexp
specify which files to offer in the
menu: the first variable says which directory to find them in; the
second says which files in that directory to offer (all those that
match the regular expression). If no files match, you cannot select
this menu item.
Copying a message with o
or C-o
gives the original copy
of the message the ‘ filed
’ attribute, so that ‘ filed
’
appears in the mode line when such a message is current.
If you like to keep just a single copy of every mail message, set
the variable rmail-delete-after-output
to t
; then the
o
, C-o
and w
commands delete the original message
after copying it. (You can undelete it afterward if you wish, see
Deleting Messages.)
By default, o
will leave the deleted status of a message it
outputs as it was on the original message; thus, a message deleted
before it was output will appear as deleted in the output file.
Setting the variable rmail-output-reset-deleted-flag
to a
non- nil
value countermands that: the copy of the message will
have its deleted status reset, so the message will appear as undeleted
in the output file. In addition, when this variable is
non- nil
, specifying a positive argument to o
will not
ignore deleted messages when looking for consecutive messages to
output.
The variable rmail-output-file-alist
lets you specify
intelligent defaults for the output file, based on the contents of the
current message. The value should be a list whose elements have this
form:
(regexp . name-exp)
If there’s a match for regexp in the current message, then the
default file name for output is name-exp. If multiple elements
match the message, the first matching element decides the default file
name. The subexpression name-exp may be a string constant giving
the file name to use, or more generally it may be any Lisp expression
that yields a file name as a string. rmail-output-file-alist
applies to both o
and C-o
.
Rmail can automatically save messages from your primary Rmail file
(the one that rmail-file-name
specifies) to other files, based
on the value of the variable rmail-automatic-folder-directives
.
This variable is a list of elements (‘ directives
’) that say which
messages to save where. Each directive is a list consisting of an
output file, followed by one or more pairs of a header name and a regular
expression. If a message has a header matching the specified regular
expression, that message is saved to the given file. If the directive
has more than one header entry, all must match. Rmail checks directives
when it shows a message from the file rmail-file-name
, and
applies the first that matches (if any). If the output file is
nil
, the message is deleted, not saved. For example, you can use
this feature to save messages from a particular address, or with a
particular subject, to a dedicated file.