## 10 Sorting Messages ¶

In order to make numerous related messages easier to cope with, VM provides the command `G` (`vm-sort-messages`), which sorts all messages in a folder using one or more sort keys. By default the actual order of the messages in the folder is not altered; that is, if you looked at the folder file outside of VM the message order would be unchanged. VM numbers and presents the messages in a different order internally. If you want the message order to be changed in the folder so that other programs can see the change, you can either invoke `vm-sort-messages` with a prefix argument, or you can set `vm-move-messages-physically` non-`nil` before sorting. Either way, VM will shift the actual messages around in the folder buffer, and when you save the folder, the order change will be visible to other programs.

Valid sort keys are:

date | reversed-date
activity | reversed-activity
author | reversed-author
subject | reversed-subject
recipients | reversed-recipients
line-count | reversed-line-count
byte-count | reversed-byte-count
physical-order | reversed-physical-order
spam-score | reversed-spam-score

The sort key `date` represents the date and time of the message. Normally, this is the date when the message was sent by the sender. Note that the message could have been “queued” after it was sent, either on the sender’s machine, on some server on the network, or in a mailing list moderator’s tray. It is not uncommon for messages to arrive much later than their sent date. Setting the variable `vm-sort-messages-by-delivery-date` to `t` causes VM to use the delivery dates of messages rather than sent dates for sorting purposes. (This assumes that your own mail server records the delivery date in a ‘`Delivery-Date`’ header. If no such header is present, then VM uses the sent date.)

The sort key `activity` represents the date of the most recent activity. This is the default sort order used with threads. See Threading. It allows even old threads that have recent messages to be brought to the front.

When sorting by subject (or threading using subjects, or killing messages by subject) the subject of the message is normalized before comparisons are done. A normalized subject has uninteresting prefixes and suffixes stripped off, and multiple consecutive white space characters are collapsed to a single space. The variable `vm-subject-ignored-prefix` should be a regular expression that matches all strings at the beginning of a subject that you do not want to be considered when message subjects are compared. A `nil` value means VM should not ignore any prefixes. The analogous variable for subject suffixes is `vm-subject-ignored-suffix`.

Once the subject has been normalized, the variable `vm-subject-significant-chars` controls how much of what remains is considered significant for matching purposes. The first `vm-subject-significant-chars` will be considered significant. Characters beyond this point in the subject string will be ignored. A `nil` value for this variable means all characters in the subject are significant.

The sorting by `spam-score` is done by extracting spam scores listed in the headers of the message, which are usually placed there by external spam scoring programs such as SpamAssassin. Spam scores are expected to be numbers, either integers or real numbers. The headers that should be used for extracting spam scores are listed in the variable `vm-spam-score-headers`. The variable is a list of triples, where each triples contains a regular expression identifying the name of the header, a regular expression matching the spam-score string on that header and a function that VM can invoke to convert the spam-score string to a number. Here is an example triple:

    ("X-Spam-Status:" "[-+]?[0-9]*\\.?[0-9]+" string-to-number)

This triple causes VM to extract a spam-score from `X-Spam-Status` headers. The first string on the header line that matches the second regular expression is extracted and converted to a number using the `string-to-number` function. The order in which the headers are listed in `vm-spam-score-headers` is significant. The first header that is found in the message is used as the spam score.

If you want to move messages around by hand, use `C-M-n` (`vm-move-message-forward`) and `C-M-p` (`vm-move-message-backward`). The default is to move the current message forward or backward by one message in the message list. A prefix argument n can specify a longer move. The value of `vm-move-messages-physically` applies to these commands.

### 10.1 Threading ¶

A thread is a group of messages that are either related by subject or that have a common ancestor. Threading is the process of determining the relationship between such messages and displaying them so that those relationships are evident.

To enable and disable threading, type `C-t` (`vm-toggle-threads-display`). You will find that, in the summary buffer, all related messages are grouped together and the subject titles are indented to show hierarchical relationships.

Message relationships are discovered by examining the `References`, `In-Reply-To`, and `Subject` headers. The first two headers are more reliable sources of information but not all mailers provide them. Therefore, all messages with similar `Subject` headers are also grouped into threads. If you don’t want VM to use Subject headers for threading, set the variable `vm-thread-using-subject` to `nil`.

Unlike in previous versions of VM, threading is not a form of sorting. You can sort threads by the usual sort keys and the sort order will apply to at least the root messages of threads. Sorting threads by subject, for instance, can be a quick way to find threads with similar subject lines. Sorting them by date would sort them chronologically according to when the threads were initiated. Sorting them by activity is a variant of the chronological order where the dates of latest activity are given prominence instead of the dates of the initial messages.

Normally, thread-based grouping applies to entire threads as well as all their subthreads. You can block subthread grouping by setting the variable `vm-sort-subthreads` to `nil`. In that case, all the internal messages of the threads are sorted by the chosen sort order, e.g., by date, author etc. instead of being grouped into subthreads.

The value of the variable `vm-move-messages-physically` applies to threading just as it applies to sorting.