| 1 |
Filters |
| 2 |
======= |
| 3 |
|
| 4 |
The default filter set (if you don't specify anything in the config) is: |
| 5 |
|
| 6 |
.. code-block:: ini |
| 7 |
|
| 8 |
[SpamFilter] |
| 9 |
[KillThreadsFilter] |
| 10 |
[ListMailsFilter] |
| 11 |
[ArchiveSentMailsFilter] |
| 12 |
[InboxFilter] |
| 13 |
|
| 14 |
The standard filter :doc:`configuration` can be applied to these filters as |
| 15 |
well. Though note that most of the filters below set their own value for |
| 16 |
message, query and/or tags, and some ignore some of the standard settings. |
| 17 |
|
| 18 |
ArchiveSentMailsFilter |
| 19 |
---------------------- |
| 20 |
|
| 21 |
It extends `SentMailsFilter` with the following feature: |
| 22 |
|
| 23 |
* Emails filtered by this filter have the **new** tag removed, so will not have |
| 24 |
the **inbox** tag added by the InboxFilter. |
| 25 |
|
| 26 |
DKIMValidityFilter |
| 27 |
------------------ |
| 28 |
|
| •29 |
This filter verifies DKIM signatures of E-Mails with DKIM header, and adds `dkim-ok` or `dkim-fail` tags. |
| 30 |
|
| 31 |
DMARCReportInspectionFilter |
| 32 |
--------------------------- |
| 33 |
|
| 34 |
DMARC reports usually come in ZIP files. To check the report you have to |
| 35 |
unpack and search thru XML document which is very tedious. This filter tags the |
| 36 |
message as follows: |
| 37 |
|
| 38 |
if there's any SPF failure in any attachment, tag the message with |
| 39 |
"dmarc-spf-fail" tag, otherwise tag with "dmarc-spf-ok" |
| 40 |
|
| 41 |
if there's any DKIM failure in any attachment, tag the message with |
| 42 |
"dmarc-dkim-fail" tag, otherwise tag with "dmarc-dkim-ok" |
| 43 |
|
| 44 |
FolderNameFilter |
| 45 |
---------------- |
| 46 |
|
| 47 |
For each email, it looks at all folders it is in, and uses the path and filename |
| 48 |
as a tag, for the email. So if you have a procmail or sieve set up that puts emails |
| 49 |
in folders for you, this might be useful. |
| 50 |
|
| 51 |
* folder_explicit_list = <folder list> |
| 52 |
|
| 53 |
* Tag mails with tag in <folder list> only. <folder list> is a space separated |
| 54 |
list, not enclosed in quotes or any other way. |
| 55 |
* Empty list means all folders (of course blacklist still applies). |
| 56 |
* The default is empty list. |
| 57 |
* You may use it e.g. to set tags only for specific folders like 'Sent'. |
| 58 |
|
| 59 |
* folder_blacklist = <folder list> |
| 60 |
|
| 61 |
* Never tag mails with tag in <folder list>. <folder list> is a space separated |
| 62 |
list, not enclosed in quotes or any other way. |
| 63 |
* The default is to blacklist no folders. |
| 64 |
* You may use it e.g. to avoid mails being tagged as 'INBOX' when there is the more |
| 65 |
standard 'inbox' tag. |
| 66 |
|
| 67 |
* folder_transforms = <transformation rules> |
| 68 |
|
| 69 |
* Transform folder names according to the specified rules before tagging mails. |
| 70 |
<transformation rules> is a space separated list consisting of |
| 71 |
'folder:tag' style pairs. The colon separates the name of the folder to be |
| 72 |
transformed from the tag it is to be transformed into. |
| 73 |
* The default is to transform to folder names. |
| 74 |
* You may use the rules e.g. to transform the name of your 'Junk' folder into your |
| 75 |
'spam' tag or fix capitalization of your draft and sent folder: |
| 76 |
|
| 77 |
.. code-block:: ini |
| 78 |
|
| 79 |
folder_transforms = Junk:spam Drafts:draft Sent:sent |
| 80 |
|
| 81 |
* folder_lowercases = true |
| 82 |
|
| 83 |
* Use lowercase tags for all folder names |
| 84 |
|
| 85 |
* maildir_separator = <sep> |
| 86 |
|
| 87 |
* Use <sep> to split your maildir hierarchy into individual tags. |
| 88 |
* The default is to split on '.' |
| 89 |
* If your maildir hierarchy is represented in the filesystem as collapsed dirs, |
| 90 |
<sep> is used to split it again before applying tags. If your maildir looks |
| 91 |
like this: |
| 92 |
|
| 93 |
.. code-block:: ini |
| 94 |
|
| 95 |
[...] |
| 96 |
/path/to/maildir/devel.afew/[cur|new|tmp]/... |
| 97 |
/path/to/maildir/devel.alot/[cur|new|tmp]/... |
| 98 |
/path/to/maildir/devel.notmuch/[cur|new|tmp]/... |
| 99 |
[...] |
| 100 |
|
| 101 |
the mails in your afew folder will be tagged with 'devel' and 'afew'. |
| 102 |
|
| 103 |
If instead your hierarchy is split by a more conventional '/' or any |
| 104 |
other divider |
| 105 |
|
| 106 |
.. code-block:: ini |
| 107 |
|
| 108 |
[...] |
| 109 |
/path/to/maildir/devel/afew/[cur|new|tmp]/... |
| 110 |
/path/to/maildir/devel/alot/[cur|new|tmp]/... |
| 111 |
/path/to/maildir/devel/notmuch/[cur|new|tmp]/... |
| 112 |
[...] |
| 113 |
|
| 114 |
you need to configure that divider to have your mails properly tagged: |
| 115 |
|
| 116 |
.. code-block:: ini |
| 117 |
|
| 118 |
maildir_separator = / |
| 119 |
|
| 120 |
HeaderMatchingFilter |
| 121 |
-------------------- |
| 122 |
|
| 123 |
This filter adds tags to a message if the named header matches the regular expression |
| 124 |
given. The tags can be set, or based on the match. The settings you can use are: |
| 125 |
|
| 126 |
* header = <header_name> |
| 127 |
* pattern = <regex_pattern> |
| 128 |
* tags = <tag_list> |
| 129 |
|
| 130 |
If you surround a tag with `{}` then it will be replaced with the named match. |
| 131 |
|
| 132 |
Some examples are: |
| 133 |
|
| 134 |
.. code-block:: ini |
| 135 |
|
| 136 |
[HeaderMatchingFilter.1] |
| 137 |
header = X-Spam-Flag |
| 138 |
pattern = YES |
| 139 |
tags = +spam |
| 140 |
|
| 141 |
[HeaderMatchingFilter.2] |
| 142 |
header = List-Id |
| 143 |
pattern = <(?P<list_id>.*)> |
| 144 |
tags = +lists;+{list_id} |
| 145 |
|
| 146 |
[HeaderMatchingFilter.3] |
| 147 |
header = X-Redmine-Project |
| •148 |
pattern = (?P<project>.+) |
| 149 |
tags = +redmine;+{project} |
| 150 |
|
| 151 |
SpamFilter and ListMailsFilter are implemented using HeaderMatchingFilter, and are |
| 152 |
only slightly more complicated than the above examples. |
| 153 |
|
| 154 |
InboxFilter |
| 155 |
----------- |
| 156 |
|
| 157 |
This removes the **new** tag, and adds the **inbox** tag, to any message that isn't |
| 158 |
killed or spam. (The new tags are set in your notmuch config, and default to |
| 159 |
just **new**.) |
| 160 |
|
| 161 |
KillThreadsFilter |
| 162 |
----------------- |
| 163 |
|
| 164 |
If the new message has been added to a thread that has already been tagged |
| 165 |
**killed** then add the **killed** tag to this message. This allows for ignoring |
| 166 |
all replies to a particular thread. |
| 167 |
|
| 168 |
ListMailsFilter |
| 169 |
--------------- |
| 170 |
|
| 171 |
This filter looks for the `List-Id` header, and if it finds it, adds a tag |
| 172 |
**lists** and a tag named **lists/<list-id>**. |
| 173 |
|
| 174 |
MeFilter |
| 175 |
-------- |
| 176 |
|
| 177 |
Add filter tagging mail sent directly to any of addresses defined in |
| 178 |
Notmuch config file: `primary_email` or `other_email`. |
| 179 |
Default tag is `to-me` and can be customized with `me_tag` option. |
| 180 |
|
| 181 |
SentMailsFilter |
| 182 |
--------------- |
| 183 |
|
| 184 |
The settings you can use are: |
| 185 |
|
| 186 |
* sent_tag = <tag> |
| 187 |
|
| 188 |
* Add <tag> to all mails sent from one of your configured mail addresses, *and |
| 189 |
not* to any of your addresses. |
| 190 |
* The default is to add no tag, so you need to specify something. |
| 191 |
* You may e.g. use it to tag all mails sent by you as 'sent'. This may make |
| 192 |
special sense in conjunction with a mail client that is able to not only search |
| 193 |
for threads but individual mails as well. |
| 194 |
|
| 195 |
* to_transforms = <transformation rules> |
| 196 |
|
| 197 |
* Transform `To`/`Cc`/`Bcc` e-mail addresses to tags according to the |
| 198 |
specified rules. <transformation rules> is a space separated list consisting |
| 199 |
of 'user_part@domain_part:tags' style pairs. The colon separates the e-mail |
| 200 |
address to be transformed from tags it is to be transformed into. ':tags' |
| 201 |
is optional and if empty, 'user_part' is used as tag. 'tags' can be |
| 202 |
a single tag or semi-colon separated list of tags. |
| 203 |
|
| 204 |
* It can be used for example to easily tag posts sent to mailing lists which |
| 205 |
at this stage don't have `List-Id` field. |
| 206 |
|
| 207 |
SpamFilter |
| 208 |
---------- |
| 209 |
|
| 210 |
The settings you can use are: |
| 211 |
|
| 212 |
* spam_tag = <tag> |
| 213 |
|
| 214 |
* Add <tag> to all mails recognized as spam. |
| 215 |
* The default is 'spam'. |
| 216 |
* You may use it to tag your spam as 'junk', 'scum' or whatever suits your mood. |
| 217 |
Note that only a single tag is supported here. |
| 218 |
|
| 219 |
Email will be considered spam if the header `X-Spam-Flag` is present. |
| 220 |
|
| 221 |
Customizing filters |
| 222 |
------------------- |
| 223 |
|
| 224 |
To customize these filters, there are basically two different |
| 225 |
possibilities: |
| 226 |
|
| 227 |
Let's say you like the SpamFilter, but it is way too polite |
| 228 |
|
| 229 |
1. Create an filter object and customize it |
| 230 |
|
| 231 |
.. code-block:: ini |
| 232 |
|
| 233 |
[SpamFilter.0] # note the index |
| 234 |
message = meh |
| 235 |
|
| 236 |
The index is required if you want to create a new SpamFilter *in |
| 237 |
addition to* the default one. If you need just one customized |
| 238 |
SpamFilter, you can drop the index and customize the default instance. |
| 239 |
|
| 240 |
2. Create a new type... |
| 241 |
|
| 242 |
.. code-block:: ini |
| 243 |
|
| 244 |
[ShitFilter(SpamFilter)] |
| 245 |
message = I hatez teh spam! |
| 246 |
|
| 247 |
and create an object or two |
| 248 |
|
| 249 |
.. code-block:: ini |
| 250 |
|
| 251 |
[ShitFilter.0] |
| 252 |
[ShitFilter.1] |
| 253 |
message = Me hatez it too. |
| 254 |
|
| 255 |
You can provide your own filter implementations too. You have to register |
| 256 |
your filters via entry points. See the afew setup.py for examples on how |
| 257 |
to register your filters. To add your filters, you just need to install your |
| 258 |
package in the context of the afew application. |