33.12 Sorting the Rmail File
C-c C-s C-dβ
M-x rmail-sort-by-dateβ
Sort messages of current Rmail buffer by date.
C-c C-s C-sβ
M-x rmail-sort-by-subjectβ
Sort messages of current Rmail buffer by subject.
C-c C-s C-aβ
M-x rmail-sort-by-authorβ
Sort messages of current Rmail buffer by authorβs name.
C-c C-s C-rβ
M-x rmail-sort-by-recipientβ
Sort messages of current Rmail buffer by recipientβs name.
C-c C-s C-cβ
M-x rmail-sort-by-correspondentβ
Sort messages of current Rmail buffer by the name of the other correspondent.
C-c C-s C-lβ
M-x rmail-sort-by-linesβ
Sort messages of current Rmail buffer by number of lines.
C-c C-s C-k RET labels RETβ
M-x rmail-sort-by-labels RET labels RETβ
Sort messages of current Rmail buffer by labels. The argument labels should be a comma-separated list of labels. The order of these labels specifies the order of messages; messages with the first label come first, messages with the second label come second, and so on. Messages that have none of these labels come last.
The Rmail sort commands perform a stable sort: if there is no reason to prefer either one of two messages, their order remains unchanged. You can use this to sort by more than one criterion. For example, if you use rmail-sort-by-date and then rmail-sort-by-author, messages from the same author appear in order by date.
With a prefix argument, all these commands reverse the order of comparison. This means they sort messages from newest to oldest, from biggest to smallest, or in reverse alphabetical order.
The same keys in the summary buffer run similar functions; for example, C-c C-s C-l runs rmail-summary-sort-by-lines. These commands always sort the whole Rmail buffer, even if the summary is only showing a subset of messages.
Note that you cannot undo a sort, so you may wish to save the Rmail buffer before sorting it.