summaryrefslogtreecommitdiffhomepage
path: root/dovecot/sieve
blob: b11f1cc8a8cf0da86b6b6bcdb323041a4e02a7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Sieve filter

# Declare the extensions used by this script.
require ["fileinto", "reject", "variables", "editheader"];

# If transport is not encrypted, add warning emoji at the beginning of the subject
if header :contains "Received" ["by topo.tw (Postfix) with ESMTP "]
{
  # Match the entire subject
  if header :matches "Subject" "*" {
    # Stored in a variable:
    set "subject" "${1}";
  }
  deleteheader "Subject";
  addheader :last "Subject" "⚠ ${subject}";
}

# Edit header for test
if header :contains "From" ["typebrook@gmail.com"] {
  # Match the entire subject ...
  if header :matches "Subject" "*" {
      # ... to get it in a match group that can then be stored in a variable:
      set "subject" "${1}";
  }
  deleteheader "Subject";
  addheader :last "Subject" "Warning: ${subject}";
}

# CAUTION!!
# Put this block at the top so unwanted mail are discarded
# Message which will trigger commands
# Discard them so we only have message in Sent
if allof (
    address :is ["To"] "mastodon@topo.tw",
    header :matches "X-Original-To" "mastodon@topo.tw"
) {
  discard;
}

elsif header :contains "From" [
  "HANCHOR",
  "info@members.netflix.com",
  "Amazon Web Services",
  "no-reply@wamazing.jp",
  "info@join.netflix.com",
  "noreply@steampowered.com"
] {
  fileinto "promotion";
}

elsif header :matches :comparator "i;ascii-casemap" "Subject" [
  "*login*",
  "*verify*",
  "*sign-in*",
  "*登入*",
  "*密碼*",
  "*安全性警示*",
  "*new IP Address*"
] {
  fileinto "login";
}

elsif header :matches :comparator "i;ascii-casemap" "Subject" [
  "*系統公告*"
] {
  fileinto "service";
}

elsif header :contains :comparator "i;ascii-casemap" "Subject" [
  "帳單",
  "付款",
  "繳款",
  "扣款",
  "交易",
  "費用",
  "eGUI",
  "Invoice",
  "發票",
  "Receipt",
  "Billing",
  "Expense"
] {
  fileinto "pay";
}

elsif header :matches :comparator "i;ascii-casemap" "Subject" ["*永豐*"] {
  fileinto "STOCK";
}

elsif address :is ["From"] "no-reply@hackmd.io" {
  fileinto "update";
}

elsif address :is ["From"] "notifications@github.com" {
  fileinto "github";
}

elsif address :contains ["To", "Cc"] "arch-general@lists.archlinux.org" {
  fileinto "mailing_list.arch-general";
}

elsif address :is ["From", "To", "Cc"] "mutt-users@mutt.org" {
  fileinto "mailing_list.mutt-users";
}

elsif address :is ["From", "To", "Cc"] "help-bash@gnu.org" {
  fileinto "mailing_list.bash";
}

elsif header :matches "Sender" "*~rjarry/aerc-discuss@lists.sr.ht*" {
  fileinto "mailing_list.aerc";
}

elsif header :matches "Chat-Version" ["*"] {
  fileinto "DeltaChat";
}

elsif header :matches "X-Original-To" ["cybersec@topo.tw"] {
  fileinto "cybersec";
}

elsif address :is ["To"] "lay9412206@gmail.com" {
  fileinto "hometeach";
}

# Spam Rule:
# Message does not contain my address in "To", "CC" or "BCC"
elsif anyof (
    not header :contains ["To", "Cc", "Bcc", "X-Original-To"] "topo.tw",
    header :contains "X-Original-To" "eocuk17"
) {
  fileinto "spam";
}
# Or fake header in "From"
elsif allof (
    header :matches "From" "*@topo.tw*",
    not header :contains "Received" [
      "from topo.tw",
      "from PC",
      "from [127.0.0.1]",
      "by topo.tw"
    ]
) {
  fileinto "spam";
}

else {
  fileinto "INBOX";
}