Use sieve to move all mail automatically based on List-Id

Matthias Fechner idefix at
Sat Feb 9 20:11:07 EET 2019

Dear all,

I currently use the following rule to automatically sort email into
folders based on mailing lists:

# split out the various list forms
# Mailman & other lists using list-id
if exists "list-id" {
    if header :regex "list-id" "<([a-z_0-9-]+)[.@]" {
        set :lower "listname" "${1}";
        fileinto :create "${listname}";
    } else {
        if header :regex "list-id" "^\\s*<?([a-z_0-9-]+)[.@]" {
            set :lower "listname" "${1}";
            fileinto :create "${listname}";
        } else {

This works really nice.
The only problem I have here is that it does use the ID, but not the
name and this can lead to strange folder names.
If an email has e.g. the following header:

List-Id: mfechner/ci-test <>

it moves the email to the folder 142 as the regex matches inside the <> string till the none-letter/none-number/_/- is matching.
I do not understand the expresion [.@] so it is nearly impossible for my to extend that query.

What I would like to do is using the ID as folder name as fallback.
So in this case I would like that the email is moved to folder `mfechner/ci-test`.
I'm not sure if sieve can handle the `/` correctly.

Thanks a lot for any tip.



"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying to
produce bigger and better idiots. So far, the universe is winning." --
Rich Cook

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the dovecot mailing list