ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial

36.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. 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 Rmail Display. 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. 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.)

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 returns a file name as a string. rmail-output-file-alist applies to both o and C-o.

blog comments powered by Disqus