fb852bc95576883121b0ab15b8bfe606f0b65927
[distro-setup] / .dovecot.sieve
1 # Sieve filter
2 ##
3 require [ "regex", "variables", "fileinto", "envelope", "mailbox", "imap4flags" ];
4
5 # Mailinglist Killfile
6 if anyof (header :contains "from" "unwanted at example.com",
7 header :contains "from" "spammer at example.net",
8 header :contains "from" "troll at example.org"){
9 discard;
10 stop;
11 }
12
13 if anyof (header :contains "x-spam-flag" "yes",
14 allof (header :regex "X-DSPAM-Result" "^(Spam|Virus|Bl[ao]cklisted)$",
15 not header :contains "X-DSPAM-Reclassified" "Innocent")){
16 # Spam goes into the spam folder
17 setflag "\\Seen";
18 fileinto :create "spam";
19 stop;
20 }
21
22 # split out the various list forms
23 # Mailman & other lists using list-id
24 if exists "list-id" {
25 if header :regex "list-id" "<([a-z_0-9-]+)[.@]" {
26 set :lower "listname" "${1}";
27 fileinto :create "${listname}";
28 } elsif header :regex "list-id" "^\\s*<?([a-z_0-9-]+)[.@]" {
29 set :lower "listname" "${1}";
30 fileinto :create "${listname}";
31 } else {
32 keep;
33 }
34 stop;}
35 # Listar and mailman like
36 elsif exists "x-list-id" {
37 if header :regex "x-list-id" "<([a-z_0-9-]+)\\\\." {
38 set :lower "listname" "${1}";
39 fileinto :create "${listname}";
40 } else {
41 keep;
42 }
43 stop;}
44 # Ezmlm
45 elsif exists "mailing-list" {
46 if header :regex "mailing-list" "([a-z_0-9-]+)@" {
47 set :lower "listname" "${1}";
48 fileinto :create "${listname}";
49 } else {
50 keep;
51 }
52 stop;}
53 # York lists service
54 elsif exists "x-mailing-list" {
55 if header :regex "x-mailing-list" "^\\s*([a-z_0-9-]+)@?" {
56 set :lower "listname" "${1}";
57 fileinto :create "${listname}";
58 } else {
59 keep;
60 }
61 stop;}
62 # Smartlist
63 elsif exists "x-loop" {
64 if header :regex "x-loop" "^\\s*(a-z_0-9-]+)@?" {
65 set :lower "listname" "${1}";
66 fileinto :create "${listname}";
67 } else {
68 keep;
69 }
70 stop;}
71 # poorly identified
72 elsif envelope :contains "from" "owner-" {
73 if envelope :regex "from" "owner-([a-z_0-9-]+)-outgoing@" {
74 set :lower "listname" "${1}";
75 fileinto :create "${listname}";
76 } elsif envelope :regex "from" "owner-([a-z_0-9-]+)@" {
77 set :lower "listname" "${1}";
78 fileinto :create "${listname}";
79 } elsif header :regex "Sender" "owner-([a-z_0-9-]+)@" {
80 set :lower "listname" "${1}";
81 fileinto :create "${listname}";
82 } else {
83 keep;
84 }
85 stop;}
86 # other poorly identified
87 elsif envelope :contains "from" "-request" {
88 if envelope :regex "from" "([a-z_0-9-]+)-request@" {
89 set :lower "listname" "${1}";
90 fileinto :create "${listname}";
91 } else {
92 keep;
93 }
94 stop;
95 }