Skip to content

Instantly share code, notes, and snippets.

@darac
Last active July 3, 2023 13:59
Show Gist options
  • Save darac/d9b4df6f609e76d2257d1df146fbd7b0 to your computer and use it in GitHub Desktop.
Save darac/d9b4df6f609e76d2257d1df146fbd7b0 to your computer and use it in GitHub Desktop.
Sieve filters for automatic mailinglist identification
# I can't remember where I originally got this from, but it's worked for me for > 10 years
# The concept here is that we try to extract the "List ID" from a message,
# this is then lower-cased (for consistency), and the message is sent to a mailbox
# named after the mailinglist.
require [ "regex", "variables", "fileinto", "envelope", "mailbox", "imap4flags" ];
# Mailinglist Killfile
if anyof (header :contains "from" "spammer@example.com",
header :contains "from" "anotherone@example.net"){
discard;
stop;
}
# Feel free to adjust to whatever spam system you use
if anyof (header :contains "x-spam-flag" "yes",
allof (header :regex "X-DSPAM-Result" "^(Spam|Virus|Bl[ao]cklisted)$",
not header :contains "X-DSPAM-Reclassified" "Innocent")){
# Spam goes into the spam folder
setflag "\\Seen";
fileinto :create "spam";
stop;
}
# split out the various list forms
# Apparently, mutt-users has some odd format, so handle it specially.
if exists "list-post" {
if header :regex "list-post" "<mailto:([a-z_0-9-]+)[.@]" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
}
# Mailman & other lists using list-id
elsif 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 {
keep;
}
}
stop;
}
# Listar and mailman like
elsif exists "x-list-id" {
if header :regex "x-list-id" "<([a-z_0-9-]+)\\\\." {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;
}
# Ezmlm
elsif exists "mailing-list" {
if header :regex "mailing-list" "([a-z_0-9-]+)@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;
}
# York lists service
elsif exists "x-mailing-list" {
if header :regex "x-mailing-list" "^\\s*([a-z_0-9-]+)@?" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;
}
# Smartlist
elsif exists "x-loop" {
if header :regex "x-loop" "^\\s*(a-z_0-9-]+)@?" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;
}
# poorly identified
elsif envelope :contains "from" "owner-" {
if envelope :regex "from" "owner-([a-z_0-9-]+)-outgoing@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} elsif envelope :regex "from" "owner-([a-z_0-9-]+)@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} elsif header :regex "Sender" "owner-([a-z_0-9-]+)@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;
}
# other poorly identified
elsif envelope :contains "from" "-request" {
if envelope :regex "from" "([a-z_0-9-]+)-request@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment