]> git.proxmox.com Git - pmg-docs.git/blame - pmg-mail-filter.adoc
faq: update support table
[pmg-docs.git] / pmg-mail-filter.adoc
CommitLineData
4a08dffe 1[[chapter_mailfilter]]
af0f1800
SI
2Rule-Based Mail Filter
3======================
62e86eb6 4
f86a08de
DW
5{pmg} ships with a highly configurable mail filter. This provides an
6easy but powerful way to define filter rules by user, domain, time
7frame, content type, and resulting action.
62e86eb6 8
a695a527 9[thumbnail="pmg-gui-mail-filter-rules.png", big=1]
62e86eb6 10
f86a08de 11Every rule has 5 categories ('FROM', 'TO', 'WHEN', 'WHAT', and
c9d28a2b
DM
12'ACTION'), and each category may contain several objects to match
13certain criteria:
62e86eb6 14
a16d5544 15'Who' - objects::
62e86eb6 16
6994b407 17Who is the sender or recipient of the email? Those objects can be used
62e86eb6
DM
18for the 'TO' and/or 'FROM' category.
19+
20====
6994b407 21Example: EMail-object - Who is the sender or recipient of the email?
62e86eb6
DM
22====
23
a16d5544 24'What' - objects::
62e86eb6 25
6994b407 26What is in the email?
62e86eb6
DM
27+
28====
6994b407 29Example: Does the email contain spam?
62e86eb6
DM
30====
31
a16d5544 32'When' - objects::
62e86eb6 33
6994b407 34When is the email received by {pmg}?
62e86eb6
DM
35+
36====
37Example: Office Hours - Mail is received between 8:00 and 16:00.
38====
39
a16d5544 40'Action' - objects::
62e86eb6
DM
41
42Defines the final actions.
43+
44====
6994b407 45Example: Mark email with “SPAM:” in the subject.
62e86eb6 46====
c9d28a2b
DM
47
48Rules are ordered by priority, so rules with higher priority are
49executed first. It is also possible to set a processing direction:
50
f86a08de 51'In':: Rule applies to all incoming emails
c9d28a2b 52
f86a08de 53'Out':: Rule applies to all outgoing emails
c9d28a2b 54
f86a08de 55'In & Out':: Rule applies to both directions
c9d28a2b 56
f86a08de
DW
57You can also disable a rule completely, which is mostly useful for
58testing and debugging. The 'Factory Defaults' button allows you to
c9d28a2b
DM
59reset the filter rules.
60
61
4a08dffe 62[[pmg_mailfilter_action]]
a16d5544
DM
63'Action' - objects
64------------------
c9d28a2b 65
a695a527 66[thumbnail="pmg-gui-mail-filter-actions.png", big=1]
c9d28a2b 67
6994b407 68Please note that some actions stop further rule processing. We call
c9d28a2b
DM
69such actions 'final'.
70
71Accept
72~~~~~~
73
74Accept mail for Delivery. This is a 'final' action.
75
76
77Block
78~~~~~
79
80Block mail. This is a 'final' action.
81
82
83Quarantine
84~~~~~~~~~~
85
f86a08de 86Move to quarantine (virus mails are moved to the “virus quarantine”;
c9d28a2b
DM
87other mails are moved to “spam quarantine”). This is also a 'final' action.
88
89
90Notification
91~~~~~~~~~~~~
92
93Send notifications. Please note that object configuration can use
94xref:rule_system_macros[macros], so it is easy to include additional
95information. For example, the default 'Notify Admin' object sends the
96following information:
97
98.Sample notification action body:
99----
100Proxmox Notification:
101Sender: __SENDER__
102Receiver: __RECEIVERS__
103Targets: __TARGETS__
104Subject: __SUBJECT__
105Matching Rule: __RULE__
106
107__RULE_INFO__
108
109__VIRUS_INFO__
110__SPAM_INFO__
111----
112
113Notification can also include a copy of the original mail.
114
115
116Blind Carbon Copy (BCC)
117~~~~~~~~~~~~~~~~~~~~~~~
118
119The BCC object simply sends a copy to another target. It is possible to
120send the original unmodified mail, or the processed result. Please
f86a08de 121note that this can be quite different, for instance, when a previous rule
c9d28a2b
DM
122removed attachments.
123
124
125Header Attributes
126~~~~~~~~~~~~~~~~~
127
f86a08de
DW
128This object is able to add or modify mail header attributes. As with
129Notifications above, you can use xref:rule_system_macros[macros],
130making this a very powerful object. For example, the 'Modify Spam
131Level' actions add detailed information about detected Spam
132characteristics to the `X-SPAM-LEVEL` header.
c9d28a2b 133
733e5b36 134.'Modify Spam Level' Header Attribute
c9d28a2b
DM
135----
136Field: X-SPAM-LEVEL
137Value: __SPAM_INFO__
138----
139
140Another prominent example is the 'Modify Spam Subject' action. This
141simply adds the 'SPAM:' prefix to the original mail subject:
142
733e5b36 143.'Modify Spam Subject' Header Attribute
c9d28a2b
DM
144----
145Field: subject
146Value: SPAM: __SUBJECT__
147----
148
149
150Remove attachments
151~~~~~~~~~~~~~~~~~~
152
153Remove attachments can either remove all attachments, or only those
f86a08de
DW
154matched by the rule's 'What' - object. You can also specify the
155replacement text, if you want.
c9d28a2b 156
f86a08de 157You can optionally move these mails into the attachment quarantine, where
f7d90c0a 158the original mail with all attachments will be stored. The mail with the
f86a08de 159attachments removed will continue through the rule system.
f7d90c0a 160
f86a08de 161NOTE: The Attachment Quarantine lifetime is the same as for the Spam Quarantine.
f7d90c0a 162
c9d28a2b
DM
163
164Disclaimer
165~~~~~~~~~~
166
167Add a Disclaimer.
66b48b3a 168
7b56a71c
TL
169The disclaimer can contain HTML markup. It will be added to the first
170`text/html` and `text/plain` part of an email. A disclaimer only gets added if
171its text can be encoded in the mail's character encoding.
9b18c05f 172
66b48b3a 173
4a08dffe 174[[pmg_mailfilter_who]]
f86a08de
DW
175'Who' objects
176-------------
66b48b3a 177
a695a527 178[thumbnail="pmg-gui-mail-filter-who-objects.png", big=1]
66b48b3a 179
f86a08de 180These types of objects can be used for the 'TO' and/or 'FROM' category,
6994b407 181and match the sender or recipient of the email. A single object can
66b48b3a
DM
182combine multiple items, and the following item types are available:
183
184EMail::
185
186Allows you to match a single mail address.
187
188Domain::
189
190Only match the domain part of the mail address.
191
192Regular Expression::
193
194This one uses a regular expression to match the whole mail address.
195
196IP Address or Network::
197
198This can be used to match the senders IP address.
199
200LDAP User or Group::
201
6994b407 202Test if the mail address belongs to a specific LDAP user or group.
66b48b3a 203
f86a08de 204We have two important 'Who' objects called 'Blacklist' and
6994b407 205'Whitelist'. These are used in the default ruleset to globally block
3228913a
DM
206or allow specific senders.
207
40ed107a 208
4a08dffe 209[[pmg_mailfilter_what]]
f86a08de
DW
210'What' objects
211--------------
40ed107a 212
a695a527 213[thumbnail="pmg-gui-mail-filter-what-objects.png", big=1]
40ed107a 214
f86a08de 215'What' objects are used to classify the mail's content. A single
a16d5544 216object can combine multiple items, and the following item types are
40ed107a
DM
217available:
218
219Spam Filter::
220
f86a08de
DW
221Matches if the detected spam level is greater than or equal to the
222configured value.
40ed107a
DM
223
224Virus Filter::
225
226Matches on infected mails.
227
fc900299
DM
228Match Field::
229
f86a08de 230Match specified mail header fields (for example, `Subject:`, `From:`, ...)
fc900299 231
40ed107a
DM
232Content Type Filter::
233
234Can be used to match specific content types.
235
236Match Filename::
237
238Uses regular expressions to match attachment filenames.
239
240Archive Filter::
241
242Can be used to match specific content types inside archives.
883ec2c4 243This also matches the content-types of all regular (non-archived) attachments.
40ed107a 244
d5c0557a
DC
245Match Archive Filename::
246
247Uses regular expressions to match attachment filenames inside archives.
248This also matches the filenames for all regular (non-archived) attachments.
249
40ed107a 250
4a08dffe 251[[pmg_mailfilter_when]]
f86a08de
DW
252'When' objects
253--------------
3228913a 254
a695a527 255[thumbnail="pmg-gui-mail-filter-when-objects.png", big=1]
3228913a 256
f86a08de
DW
257'When' objects are used to activate rules at specific times of the
258day. You can compose them from one or more time frame items.
3228913a
DM
259
260The default ruleset defines 'Office Hours', but this is not used by
261the default rules.
99fd4bd4
DM
262
263
4a08dffe 264[[pmg_mailfilter_regex]]
99fd4bd4
DM
265Using regular expressions
266-------------------------
267
f86a08de
DW
268A regular expression is a string of characters which represents a list
269of text patterns which you would like to match. The following is a
270short introduction to the syntax of regular expressions used by some
271objects. If you are familiar with Perl, you will already know the
272syntax.
99fd4bd4
DM
273
274Simple regular expressions
275~~~~~~~~~~~~~~~~~~~~~~~~~~
276
277In its simplest form, a regular expression is just a word or phrase to
278search for. `Mail` would match the string "Mail". The search is case
279sensitive so "MAIL", "Mail", "mail" would not be matched.
280
281Metacharacters
282~~~~~~~~~~~~~~
283
284Some characters have a special meaning. These characters are called
285metacharacters. The Period (`.`) is a commonly used metacharacter. It
286matches exactly one character, regardless of what the character is.
6994b407
OB
287`e.mail` would match either "e-mail" or "e2mail" but not
288"e-some-mail" or "email".
99fd4bd4
DM
289
290The question mark (`?`) indicates that the character immediately
6994b407 291preceding it shows up either zero or one time. `e?mail` would match
99fd4bd4
DM
292either "email" or "mail" but not "e-mail".
293
f86a08de 294Another metacharacter is the asterisk (`*`). This indicates that the
6994b407 295character immediately preceding it may be repeated any number of times,
f86a08de 296including zero. `e*mail` would match "email", "mail", and
99fd4bd4
DM
297"eeemail".
298
f86a08de
DW
299The plus (`+`) metacharacter indicates that the character immediately
300preceding it appears one or more times. So `e+mail` does not match
301"mail".
99fd4bd4 302
f86a08de
DW
303Metacharacters can also be combined. A common combination includes the
304period and asterisk metacharacters (`.*`), with the asterisk
305immediately following the period. This is used to match an arbitrary
306string of any length, including the null string. For example:
307`.*company.*` matches "company@domain.com" or "company@domain.co.uk"
308or "department.company@domain.com".
0601bef2 309
6994b407 310The book xref:Friedl97[] provides a more comprehensive introduction.