Cleaning up RMAIL

Keeping lots of messages in RMAIL causes several problems. The bigger the file, the longer it takes to read into emacs or to write out when you save it. Also, emacs keeps a pre-modified copy of your file around (as RMAIL.BAK or RMAIL~) in case something goes haywire when you're reading your mail. If you previously had many messages in your RMAIL, you'll have both the current and previous copies of all those messages on the disk, thus doubling your disk storage requirements. This impacts other users when disk space is short.

Deleting many messages

If all you want to do is delete a lot of old messages, then the following sequence of commands should be followed in RMAIL mode (the mode you're in when reading mail in emacs).
h
This creates a list of all the messages in your RMAIL file. You can poke around in here using all the normal emacs commands to see what range of messages you want to delete.
ESC <
("ESC" is the "escape" key.) This puts you back to the beginning of the buffer where it is presumed you want to start deleting messages. If this is not where you want to start deleting, position yourself before the first message you wish to delete now.
^X (
("^X" is control-X - hold down "CTRL" key while typing "x".) This begins the definition of a macro. A macro is a series of commands which can be done as a single command.
d
This deletes the message on the line at which the cursor appears and the cursor then moves to the next line. This is the entire body of the macro.
^X )
This ends the definition of the macro.
^X e
This executes the above defined macro one time.
^U 9 8 ^X e
This executes the above defined macro 98 times. (It is assumed you wished to delete 100 messages. Alter this number if you want to delete more or less.) You will have to wait after you type this. It takes time.
^X 0
(That's zero, not o.) This gets you out of two window mode, removes the display of the list of messages, and leaves you back in your RMAIL file buffer.
s
This expunges messages you deleted and saves the now smaller copy of the file.

Moving many messages to another file

If you want to keep your old messages, it's best to move them to another file so you're not creating another copy of all of them each time you read your mail. The following sequence of commands should be followed in RMAIL mode (the mode you're in when reading mail in emacs).
h
This creates a list of all the messages in your RMAIL file. You can poke around in here using all the normal emacs commands to see what range of messages you want to move.
^X 0
("^X" is control-X - hold down "CTRL" key while typing "x". And, that's zero, not o.) This gets you out of two window mode, removes the display of the list of messages, and leaves you back in your RMAIL file buffer.
1 j
This moves you to the first message of your RMAIL file. If this is not where you want to start moving messages from, position yourself to the first message you want to move.
o
This tells emacs to output the message to another file. Type in the file name you want to move the messages to followed by a carriage return.

Note 1: If the file doesn't already exist, emacs will ask you if you want to create it. Type yes followed by another carriage return.

Note 2: Some people configure their emacs to automatically delete messages when output to another file. If you are still looking at the message you just output to a file, you should now type d, which will mark this message as deleted from your RMAIL file and move on to the next message. (Most people need this d.)

^X (
This begins the definition of a macro. A macro is a series of commands which can be done as a single command.
o <CR>
(<CR> is the return key.) Here we tell emacs to output the current message to the file. The file we previously specified is given as the default, so all we need to type is a carriage return. Note: If you had to type d above, you should here too. (Most people need this d.)
^X )
This ends the definition of the macro.
^X e
This executes the above defined macro one time.
^U 9 8 ^X e
This executes the above defined macro 98 times. (It is assumed you wished to move 100 messages. Alter this number if you want to move more or less.) You will have to wait after you type this. It takes time.
s
This expunges messages you deleted and saves the now smaller copy of the file.
You can now read the new file into emacs using the command
    M-x rmail-input <CR> filename <CR>
All the usual RMAIL type commands will work in this buffer.