gnus: Splitting Mail
6.4.3 Splitting Mail
--------------------
The ‘nnmail-split-methods’ variable says how the incoming mail is to be
split into groups.
(setq nnmail-split-methods
'(("mail.junk" "^From:.*Lars Ingebrigtsen")
("mail.crazy" "^Subject:.*die\\|^Organization:.*flabby")
("mail.other" "")))
This variable is a list of lists, where the first element of each of
these lists is the name of the mail group (they do not have to be called
something beginning with ‘mail’, by the way), and the second element is
a regular expression used on the header of each mail to determine if it
belongs in this mail group. The first string may contain ‘\\1’ forms,
like the ones used by ‘replace-match’ to insert sub-expressions from the
matched text. For instance:
("list.\\1" "From:.* \\(.*\\)-list@majordomo.com")
In that case, ‘nnmail-split-lowercase-expanded’ controls whether the
inserted text should be made lowercase. Fancy Mail Splitting.
The second element can also be a function. In that case, it will be
called narrowed to the headers with the first element of the rule as the
argument. It should return a non-‘nil’ value if it thinks that the mail
belongs in that group.
The last of these groups should always be a general one, and the
regular expression should _always_ be ‘""’ so that it matches any mails
that haven’t been matched by any of the other regexps. (These rules are
processed from the beginning of the alist toward the end. The first
rule to make a match will “win”, unless you have crossposting enabled.
In that case, all matching rules will “win”.) If no rule matched, the
mail will end up in the ‘bogus’ group. When new groups are created by
splitting mail, you may want to run ‘gnus-group-find-new-groups’ to see
the new groups. This also applies to the ‘bogus’ group.
If you like to tinker with this yourself, you can set this variable
to a function of your choice. This function will be called without any
arguments in a buffer narrowed to the headers of an incoming mail
message. The function should return a list of group names that it
thinks should carry this mail message.
This variable can also be a fancy split method. For the syntax, see
Fancy Mail Splitting.
Note that the mail back ends are free to maul the poor, innocent,
incoming headers all they want to. They all add ‘Lines’ headers; some
add ‘X-Gnus-Group’ headers; most rename the Unix mbox ‘From<SPACE>’ line
to something else.
The mail back ends all support cross-posting. If several regexps
match, the mail will be “cross-posted” to all those groups.
‘nnmail-crosspost’ says whether to use this mechanism or not. Note that
no articles are crossposted to the general (‘""’) group.
‘nnmh’ and ‘nnml’ makes crossposts by creating hard links to the
crossposted articles. However, not all file systems support hard links.
If that’s the case for you, set ‘nnmail-crosspost-link-function’ to
‘copy-file’. (This variable is ‘add-name-to-file’ by default.)
If you wish to see where the previous mail split put the messages,
you can use the ‘M-x nnmail-split-history’ command. If you wish to see
where re-spooling messages would put the messages, you can use
‘gnus-summary-respool-trace’ and related commands (Mail Group
Commands).
Header lines longer than the value of
‘nnmail-split-header-length-limit’ are excluded from the split function.
By default, splitting does not decode headers, so you can not match
on non-ASCII strings. But it is useful if you want to match articles
based on the raw header data. To enable it, set the
‘nnmail-mail-splitting-decodes’ variable to a non-‘nil’ value. In
addition, the value of the ‘nnmail-mail-splitting-charset’ variable is
used for decoding non-MIME encoded string when
‘nnmail-mail-splitting-decodes’ is non-‘nil’. The default value is
‘nil’ which means not to decode non-MIME encoded string. A suitable
value for you will be ‘undecided’ or be the charset used normally in
mails you are interested in.
By default, splitting is performed on all incoming messages. If you
specify a ‘directory’ entry for the variable ‘mail-sources’ (Mail
Source Specifiers), however, then splitting does _not_ happen by
default. You can set the variable ‘nnmail-resplit-incoming’ to a
non-‘nil’ value to make splitting happen even in this case. (This
variable has no effect on other kinds of entries.)
Gnus gives you all the opportunity you could possibly want for
shooting yourself in the foot. Let’s say you create a group that will
contain all the mail you get from your boss. And then you accidentally
unsubscribe from the group. Gnus will still put all the mail from your
boss in the unsubscribed group, and so, when your boss mails you “Have
that report ready by Monday or you’re fired!”, you’ll never see it and,
come Tuesday, you’ll still believe that you’re gainfully employed while
you really should be out collecting empty bottles to save up for next
month’s rent money.