When you use the nnml backend, you can split your mail into various folders. SplitMail shows you how to set nnmail-split-methods accordingly.

You can have fancy mail splitting, too, however. In order to do that, set nnmail-split-methods to the symbol nnmail-split-fancy (ie. you need to quote it), and set the variable nnmail-split-fancy (no quoting) to the rules you want to use.

Here is a small example. First we disable crossposting, and then we use the following rules:

 (setq nnmail-crosspost nil
       nnmail-split-methods 'nnmail-split-fancy
       `(| ("Subject" "color-theme" "mail.emacs")
	   (any ,gnus-ignored-from-addresses "mail.misc")
	   (any ".*" "")

Note that ‘any’ is an abbreviation. See the variable nnmail-split-abbrev-alist.

Dynamic Group Names

From the manual node “Fancy Mail Splitting”:

If you want to have Gnus create groups dynamically based on some information in the headers (i.e., do ‘replace-match’-like substitutions in the group names), you can say things like:

     (any "debian-\\b\\(\\w+\\)" "mail.debian.\\1")

In this example, messages sent to `’ will be filed in `’.

Mailing list on, and many-many others, includes notification from SVN and CVS, uses List-ID header (for ex. List-Id: Boost announce-only mailing list <> ) so it’s easy to sort it just by:

     ;; split by header List-Id
     ("List-Id" ".*<\\(.+\\)>.*" "lists.\\1")

If the string contains the element `\&’, then the previously matched string will be substituted. Similarly, the elements `
1’ up to `
9’ will be substituted with the text matched by the groupings 1 through 9.

A question to this: when this dynamic method creates a new group, will it be subscribed and displayed automatically? At least on my system (where I create new groups for new colleagues that send an email to me) it doesn’t – StefanKamphausen


Here’s an example that illustrates filtering out spam with nnmail-split-fancy:

 (setq nnmail-split-methods 'nnmail-split-fancy
         ;; spam detected by spam-use-regex-headers goes to ‘regex-spam’             
         (: spam-split "regex-spam" 'spam-use-regex-headers)
         ;; all other spam detected by spam-split goes to spam-split-group           
         (: spam-split)
         ;; default mailbox                                                          


For even more advanced setups, see SplitMailUsingBbdb.

If you maintain a blacklist of spammers and want to generate a fancy split rule from it see BlacklistSpammers.


Don’t split to INBOX (even as your default split). You will get emails being moved around from INBOX to INBOX causing all sorts of confusion.