maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

 1# IMAP filters
 2
 3Most storage backends support application of custom code late in delivery
 4process. As opposed to using SMTP pipeline modifiers or checks, it allows
 5modifying IMAP-specific message attributes. In particular, it allows
 6code to change target folder and add IMAP flags (keywords) to the message.
 7
 8There is no way to reject message using IMAP filters, this should be done
 9earlier in SMTP pipeline logic. Quarantined messages are not processed
10by IMAP filters and are unconditionally delivered to Junk folder (or other
11folder with \Junk special-use attribute).
12
13To use an IMAP filter, specify it in the 'imap\_filter' directive for the
14used storage backend, like this:
15```
16storage.imapsql local_mailboxes {
17   ...
18   
19   imap_filter {
20       command /etc/maddy/sieve.sh {account_name}
21   }
22}
23```
24
25## System command filter (imap.filter.command)
26
27This filter is similar to check.command module
28and runs a system command to obtain necessary information.
29
30Usage:
31```
32command executable_name args... { }
33```
34
35Same as check.command, following placeholders are supported for command
36arguments: {source\_ip}, {source\_host}, {source\_rdns}, {msg\_id}, {auth\_user},
37{sender}. Note: placeholders
38in command name are not processed to avoid possible command injection attacks.
39
40Additionally, for imap.filter.command, {account\_name} placeholder is replaced
41with effective IMAP account name, {rcpt_to}, {original_rcpt_to} provide
42access to the SMTP envelope recipient (before and after any rewrites),
43{subject} is replaced with the Subject header, if it is present.
44
45Note that if you use provided systemd units on Linux, maddy executable is
46sandboxed - all commands will be executed with heavily restricted filesystem
47access and other privileges. Notably, /tmp is isolated and all directories
48except for /var/lib/maddy and /run/maddy are read-only. You will need to modify
49systemd unit if your command needs more privileges.
50
51Command output should consist of zero or more lines. First one, if non-empty, overrides
52destination folder. All other lines contain additional IMAP flags to add
53to the message. If command wants to add flags without changing folder - first
54line should be empty.
55
56It is valid for command to not write anything to stdout. In this case its
57execution will have no effect on delivery.
58
59Output example:
60```
61Junk
62```
63In this case, message will be placed in the Junk folder.
64
65```
66
67$Label1
68```
69In this case, message will be placed in inbox and will have
70'$Label1' added.