summaryrefslogtreecommitdiffhomepage
path: root/dovecot
diff options
context:
space:
mode:
authorHsieh Chin Fan <typebrook@gmail.com>2022-02-02 13:34:47 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-11-30 21:09:29 +0800
commit9934dd538b0ce116e3b1600272cb46369b082246 (patch)
tree2f28c6c362201151eaf8218e566479ed7eb72070 /dovecot
init commit
Diffstat (limited to 'dovecot')
-rw-r--r--dovecot/90-sieve.conf206
-rw-r--r--dovecot/Makefile2
-rw-r--r--dovecot/dovecot.conf34
-rw-r--r--dovecot/sieve149
4 files changed, 391 insertions, 0 deletions
diff --git a/dovecot/90-sieve.conf b/dovecot/90-sieve.conf
new file mode 100644
index 0000000..8c0c244
--- /dev/null
+++ b/dovecot/90-sieve.conf
@@ -0,0 +1,206 @@
1##
2## Settings for the Sieve interpreter
3##
4
5# Do not forget to enable the Sieve plugin in 15-lda.conf and 20-lmtp.conf
6# by adding it to the respective mail_plugins= settings.
7
8# The Sieve interpreter can retrieve Sieve scripts from several types of
9# locations. The default `file' location type is a local filesystem path
10# pointing to a Sieve script file or a directory containing multiple Sieve
11# script files. More complex setups can use other location types such as
12# `ldap' or `dict' to fetch Sieve scripts from remote databases.
13#
14# All settings that specify the location of one ore more Sieve scripts accept
15# the following syntax:
16#
17# location = [<type>:]path[;<option>[=<value>][;...]]
18#
19# If the type prefix is omitted, the script location type is 'file' and the
20# location is interpreted as a local filesystem path pointing to a Sieve script
21# file or directory. Refer to Pigeonhole wiki or INSTALL file for more
22# information.
23
24plugin {
25 # The location of the user's main Sieve script or script storage. The LDA
26 # Sieve plugin uses this to find the active script for Sieve filtering at
27 # delivery. The "include" extension uses this location for retrieving
28 # :personal" scripts. This is also where the ManageSieve service will store
29 # the user's scripts, if supported.
30 #
31 # Currently only the 'file:' location type supports ManageSieve operation.
32 # Other location types like 'dict:' and 'ldap:' can currently only
33 # be used as a read-only script source ().
34 #
35 # For the 'file:' type: use the ';active=' parameter to specify where the
36 # active script symlink is located.
37 # For other types: use the ';name=' parameter to specify the name of the
38 # default/active script.
39 sieve = file:~/sieve;active=~/.dovecot.sieve
40
41 # The default Sieve script when the user has none. This is the location of a
42 # global sieve script file, which gets executed ONLY if user's personal Sieve
43 # script doesn't exist. Be sure to pre-compile this script manually using the
44 # sievec command line tool if the binary is not stored in a global location.
45 # --> See sieve_before for executing scripts before the user's personal
46 # script.
47 #sieve_default = /var/lib/dovecot/sieve/default.sieve
48
49 # The name by which the default Sieve script (as configured by the
50 # sieve_default setting) is visible to the user through ManageSieve.
51 #sieve_default_name =
52
53 # Location for ":global" include scripts as used by the "include" extension.
54 #sieve_global =
55
56 # The location of a Sieve script that is run for any message that is about to
57 # be discarded; i.e., it is not delivered anywhere by the normal Sieve
58 # execution. This only happens when the "implicit keep" is canceled, by e.g.
59 # the "discard" action, and no actions that deliver the message are executed.
60 # This "discard script" can prevent discarding the message, by executing
61 # alternative actions. If the discard script does nothing, the message is
62 # still discarded as it would be when no discard script is configured.
63 #sieve_discard =
64
65 # Location Sieve of scripts that need to be executed before the user's
66 # personal script. If a 'file' location path points to a directory, all the
67 # Sieve scripts contained therein (with the proper `.sieve' extension) are
68 # executed. The order of execution within that directory is determined by the
69 # file names, using a normal 8bit per-character comparison.
70 #
71 # Multiple script locations can be specified by appending an increasing number
72 # to the setting name. The Sieve scripts found from these locations are added
73 # to the script execution sequence in the specified order. Reading the
74 # numbered sieve_before settings stops at the first missing setting, so no
75 # numbers may be skipped.
76 #sieve_before = /var/lib/dovecot/sieve.d/
77 #sieve_before2 = ldap:/etc/sieve-ldap.conf;name=ldap-domain
78 #sieve_before3 = (etc...)
79
80 # Identical to sieve_before, only the specified scripts are executed after the
81 # user's script (only when keep is still in effect!). Multiple script
82 # locations can be specified by appending an increasing number.
83 #sieve_after =
84 #sieve_after2 =
85 #sieve_after2 = (etc...)
86
87 # Which Sieve language extensions are available to users. By default, all
88 # supported extensions are available, except for deprecated extensions or
89 # those that are still under development. Some system administrators may want
90 # to disable certain Sieve extensions or enable those that are not available
91 # by default. This setting can use '+' and '-' to specify differences relative
92 # to the default. For example `sieve_extensions = +imapflags' will enable the
93 # deprecated imapflags extension in addition to all extensions were already
94 # enabled by default.
95 sieve_extensions = +variables +editheader
96 sieve_editheader_max_header_size = 1k
97
98 # Which Sieve language extensions are ONLY available in global scripts. This
99 # can be used to restrict the use of certain Sieve extensions to administrator
100 # control, for instance when these extensions can cause security concerns.
101 # This setting has higher precedence than the `sieve_extensions' setting
102 # (above), meaning that the extensions enabled with this setting are never
103 # available to the user's personal script no matter what is specified for the
104 # `sieve_extensions' setting. The syntax of this setting is similar to the
105 # `sieve_extensions' setting, with the difference that extensions are
106 # enabled or disabled for exclusive use in global scripts. Currently, no
107 # extensions are marked as such by default.
108 #sieve_global_extensions =
109
110 # The Pigeonhole Sieve interpreter can have plugins of its own. Using this
111 # setting, the used plugins can be specified. Check the Dovecot wiki
112 # (wiki2.dovecot.org) or the pigeonhole website
113 # (http://pigeonhole.dovecot.org) for available plugins.
114 # The sieve_extprograms plugin is included in this release.
115 #sieve_plugins =
116
117 # The maximum size of a Sieve script. The compiler will refuse to compile any
118 # script larger than this limit. If set to 0, no limit on the script size is
119 # enforced.
120 #sieve_max_script_size = 1M
121
122 # The maximum number of actions that can be performed during a single script
123 # execution. If set to 0, no limit on the total number of actions is enforced.
124 #sieve_max_actions = 32
125
126 # The maximum number of redirect actions that can be performed during a single
127 # script execution. If set to 0, no redirect actions are allowed.
128 #sieve_max_redirects = 4
129
130 # The maximum number of personal Sieve scripts a single user can have. If set
131 # to 0, no limit on the number of scripts is enforced.
132 # (Currently only relevant for ManageSieve)
133 #sieve_quota_max_scripts = 0
134
135 # The maximum amount of disk storage a single user's scripts may occupy. If
136 # set to 0, no limit on the used amount of disk storage is enforced.
137 # (Currently only relevant for ManageSieve)
138 #sieve_quota_max_storage = 0
139
140 # The primary e-mail address for the user. This is used as a default when no
141 # other appropriate address is available for sending messages. If this setting
142 # is not configured, either the postmaster or null "<>" address is used as a
143 # sender, depending on the action involved. This setting is important when
144 # there is no message envelope to extract addresses from, such as when the
145 # script is executed in IMAP.
146 #sieve_user_email =
147
148 # The path to the file where the user log is written. If not configured, a
149 # default location is used. If the main user's personal Sieve (as configured
150 # with sieve=) is a file, the logfile is set to <filename>.log by default. If
151 # it is not a file, the default user log file is ~/.dovecot.sieve.log.
152 #sieve_user_log =
153
154 # Specifies what envelope sender address is used for redirected messages.
155 # The following values are supported for this setting:
156 #
157 # "sender" - The sender address is used (default).
158 # "recipient" - The final recipient address is used.
159 # "orig_recipient" - The original recipient is used.
160 # "user_email" - The user's primary address is used. This is
161 # configured with the "sieve_user_email" setting. If
162 # that setting is unconfigured, "user_mail" is equal to
163 # "recipient".
164 # "postmaster" - The postmaster_address configured for the LDA.
165 # "<user@domain>" - Redirected messages are always sent from user@domain.
166 # The angle brackets are mandatory. The null "<>" address
167 # is also supported.
168 #
169 # This setting is ignored when the envelope sender is "<>". In that case the
170 # sender of the redirected message is also always "<>".
171 #sieve_redirect_envelope_from = sender
172
173 ## TRACE DEBUGGING
174 # Trace debugging provides detailed insight in the operations performed by
175 # the Sieve script. These settings apply to both the LDA Sieve plugin and the
176 # IMAPSIEVE plugin.
177 #
178 # WARNING: On a busy server, this functionality can quickly fill up the trace
179 # directory with a lot of trace files. Enable this only temporarily and as
180 # selective as possible.
181
182 # The directory where trace files are written. Trace debugging is disabled if
183 # this setting is not configured or if the directory does not exist. If the
184 # path is relative or it starts with "~/" it is interpreted relative to the
185 # current user's home directory.
186 #sieve_trace_dir =
187
188 # The verbosity level of the trace messages. Trace debugging is disabled if
189 # this setting is not configured. Possible values are:
190 #
191 # "actions" - Only print executed action commands, like keep,
192 # fileinto, reject and redirect.
193 # "commands" - Print any executed command, excluding test commands.
194 # "tests" - Print all executed commands and performed tests.
195 # "matching" - Print all executed commands, performed tests and the
196 # values matched in those tests.
197 #sieve_trace_level =
198
199 # Enables highly verbose debugging messages that are usually only useful for
200 # developers.
201 #sieve_trace_debug = no
202
203 # Enables showing byte code addresses in the trace output, rather than only
204 # the source line numbers.
205 #sieve_trace_addresses = no
206}
diff --git a/dovecot/Makefile b/dovecot/Makefile
new file mode 100644
index 0000000..5d80849
--- /dev/null
+++ b/dovecot/Makefile
@@ -0,0 +1,2 @@
1all:
2 ln -f `pwd`/sieve ~/sieve
diff --git a/dovecot/dovecot.conf b/dovecot/dovecot.conf
new file mode 100644
index 0000000..e98b281
--- /dev/null
+++ b/dovecot/dovecot.conf
@@ -0,0 +1,34 @@
1listen = *
2
3ssl = required
4
5ssl_cert = </etc/mail/ssl/fullchain.cer
6ssl_key = </etc/mail/ssl/mail.topo.tw.key
7ssl_dh = </etc/ssl/dh.pem
8
9mail_location = maildir:~/Maildir
10
11passdb {
12 # This is where you define your password scheme.
13 # If you have used blowfish it needs to be 'BLF-CRYPT'.
14 args = scheme=sha512-crypt /etc/mail/passwd
15 driver = passwd-file
16}
17
18userdb {
19 args = uid=pham gid=pham home=/home/pham
20 driver = static
21}
22
23protocols = imap lmtp
24
25service imap-login {
26 inet_listener imaps {
27 port = 993
28 ssl = yes
29 }
30 # Disable imap
31 inet_listener imap {
32 port = 0
33 }
34}
diff --git a/dovecot/sieve b/dovecot/sieve
new file mode 100644
index 0000000..b11f1cc
--- /dev/null
+++ b/dovecot/sieve
@@ -0,0 +1,149 @@
1# Sieve filter
2
3# Declare the extensions used by this script.
4require ["fileinto", "reject", "variables", "editheader"];
5
6# If transport is not encrypted, add warning emoji at the beginning of the subject
7if header :contains "Received" ["by topo.tw (Postfix) with ESMTP "]
8{
9 # Match the entire subject
10 if header :matches "Subject" "*" {
11 # Stored in a variable:
12 set "subject" "${1}";
13 }
14 deleteheader "Subject";
15 addheader :last "Subject" "⚠ ${subject}";
16}
17
18# Edit header for test
19if header :contains "From" ["typebrook@gmail.com"] {
20 # Match the entire subject ...
21 if header :matches "Subject" "*" {
22 # ... to get it in a match group that can then be stored in a variable:
23 set "subject" "${1}";
24 }
25 deleteheader "Subject";
26 addheader :last "Subject" "Warning: ${subject}";
27}
28
29# CAUTION!!
30# Put this block at the top so unwanted mail are discarded
31# Message which will trigger commands
32# Discard them so we only have message in Sent
33if allof (
34 address :is ["To"] "mastodon@topo.tw",
35 header :matches "X-Original-To" "mastodon@topo.tw"
36) {
37 discard;
38}
39
40elsif header :contains "From" [
41 "HANCHOR",
42 "info@members.netflix.com",
43 "Amazon Web Services",
44 "no-reply@wamazing.jp",
45 "info@join.netflix.com",
46 "noreply@steampowered.com"
47] {
48 fileinto "promotion";
49}
50
51elsif header :matches :comparator "i;ascii-casemap" "Subject" [
52 "*login*",
53 "*verify*",
54 "*sign-in*",
55 "*登入*",
56 "*密碼*",
57 "*安全性警示*",
58 "*new IP Address*"
59] {
60 fileinto "login";
61}
62
63elsif header :matches :comparator "i;ascii-casemap" "Subject" [
64 "*系統公告*"
65] {
66 fileinto "service";
67}
68
69elsif header :contains :comparator "i;ascii-casemap" "Subject" [
70 "帳單",
71 "付款",
72 "繳款",
73 "扣款",
74 "交易",
75 "費用",
76 "eGUI",
77 "Invoice",
78 "發票",
79 "Receipt",
80 "Billing",
81 "Expense"
82] {
83 fileinto "pay";
84}
85
86elsif header :matches :comparator "i;ascii-casemap" "Subject" ["*永豐*"] {
87 fileinto "STOCK";
88}
89
90elsif address :is ["From"] "no-reply@hackmd.io" {
91 fileinto "update";
92}
93
94elsif address :is ["From"] "notifications@github.com" {
95 fileinto "github";
96}
97
98elsif address :contains ["To", "Cc"] "arch-general@lists.archlinux.org" {
99 fileinto "mailing_list.arch-general";
100}
101
102elsif address :is ["From", "To", "Cc"] "mutt-users@mutt.org" {
103 fileinto "mailing_list.mutt-users";
104}
105
106elsif address :is ["From", "To", "Cc"] "help-bash@gnu.org" {
107 fileinto "mailing_list.bash";
108}
109
110elsif header :matches "Sender" "*~rjarry/aerc-discuss@lists.sr.ht*" {
111 fileinto "mailing_list.aerc";
112}
113
114elsif header :matches "Chat-Version" ["*"] {
115 fileinto "DeltaChat";
116}
117
118elsif header :matches "X-Original-To" ["cybersec@topo.tw"] {
119 fileinto "cybersec";
120}
121
122elsif address :is ["To"] "lay9412206@gmail.com" {
123 fileinto "hometeach";
124}
125
126# Spam Rule:
127# Message does not contain my address in "To", "CC" or "BCC"
128elsif anyof (
129 not header :contains ["To", "Cc", "Bcc", "X-Original-To"] "topo.tw",
130 header :contains "X-Original-To" "eocuk17"
131) {
132 fileinto "spam";
133}
134# Or fake header in "From"
135elsif allof (
136 header :matches "From" "*@topo.tw*",
137 not header :contains "Received" [
138 "from topo.tw",
139 "from PC",
140 "from [127.0.0.1]",
141 "by topo.tw"
142 ]
143) {
144 fileinto "spam";
145}
146
147else {
148 fileinto "INBOX";
149}