User Tools

Site Tools


exim4:sieve_filter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
exim4:sieve_filter [2016/11/14 14:31] – created peterexim4:sieve_filter [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Exim4 - Sieve Filter ====== ====== Exim4 - Sieve Filter ======
  
 +Exim4 Sieve filter.
 +
 +The filter contains an automatic response and a forwarding.
 +
 +router
 +
 +<code>
 +userforward:
 +  driver = redirect
 +  allow_filter
 +  user = mail
 +  group = mail
 +  file = /var/vmail/${domain}/${local_part}/${if exists{/var/vmail/${domain}/${local_part}/active_script}{active_script{}}}{forward}}
 +  no_verify
 +  no_expn
 +  check_ancestor
 +  file_transport = local_delivery
 +  pipe_transport = address_pipe
 +  reply_transport = address_reply
 +  condition = ${if exists{/var/vmail/${domain}/${local_part}/forward}{yes}{${if exists{/var/vmail/${domain}/${local_part}/active_script}{yes}{no}}}}
 +</code>
 +
 +Transport
 +
 +<code>
 +local_delivery:
 +  driver = appendfile
 +  check_string = ""
 +  delivery_date_add
 +  directory = /var/vmail/${domain}/${local_part}/${sg{${sg{/${address_file}}{/+}{.}}}{(?i)^.inbox}{}}
 +  directory_mode = 770
 +  envelope_to_add
 +  group = mail
 +  maildir_format
 +  maildir_tag = ,S=$message_size
 +  message_prefix = ""
 +  message_suffix = ""
 +  mode = 0660
 +</code>
 +
 +active_script
 +
 +<code>
 +# Sieve filter
 +require ["fileinto", "copy", "vacation"] ;
 +
 +#begin = forward =
 +#data=1~dGlub0BuYXVtaXguZGU=                                                                                                                                                                                                                  
 +redirect :copy "copy@domain.tld";
 +
 +#end = forward =
 +
 +#begin = autoresponder =
 +#data=1~YXV0b3Jlc3BvbmQAZGFzIGlzdCBlaW5lIGF1dG9tYXRpc2NoZSBtYWls
 +vacation :days 1 :subject "Automatic Mail" "This is automatic Mail";
 +#end = autoresponder =
 +</code>
 +
 +or
 +
 +<code>
 +# Sieve filter
 +require ["fileinto", "copy", "vacation"] ;
 +
 +#begin = forward =
 +#data=1~bmF1bWl4QGdteC5kZA==
 +redirect :copy "test@domain.de";
 +#end = forward =
 +
 +#begin = autoresponder =
 +#data=1~VGVzdC1CZXRyZWZmAFRlc3QtVGV4dQ==
 +vacation :days 1 :subject "Test-Betreff" "Test-Text";
 +#end = autoresponder =
 +
 +#begin = filters =
 +#sieve filter
 +
 +
 +#sieve_filter:1;0;2;Test;3;INBOX.Trash
 +if header :contains ["Subject"] "Test" {
 +fileinto "INBOX.Trash" ;
 +stop ;
 +}
 +
 +#end sieve filter
 +
 +#end = filters =
 +keep ;
 +</code>
 +
 +===== Another approach =====
 +
 +Should you want to use Exim's Sieve support there are three main caveats:
 +
 +  * Sieve files accessed from redirect routers need to be readable by the uid of the process that handles the SMTP connection, (e.g. Debian-exim)
 +  * While the [[http://tools.ietf.org/html/rfc5228|Sieve RFC]] specifies that files use CRLF as linebreaks, Exim filters usually require the use of LF only.
 +  * Exim requires that sieve filter files identify themselves with "# Sieve filter" which is not part of the Sieve spec.
 +
 +<code>
 +ACTIVE_SIEVE = /var/lib/sieve/${domain}/${local_part}/active
 +VACATION_DIR = /var/lib/sieve/${domain}/${local_part}/vacation
 +VDOM_MAILDIR = /var/vmail/${domain}/${local_part}
 +</code>
 +
 +The following router is installed to /etc/exim4/conf.d/router/350_local_sieve
 +
 +<code>
 +vdom_sieve:
 +  debug_print = "R: vdom_sieve for $local_part@$domain"
 +  driver = redirect
 +  domains = +local_domains
 +  require_files = ACTIVE_SIEVE
 +  no_verify
 +  no_expn
 +  check_ancestor
 +  allow_filter = true
 +  local_part_suffix = +* : -*
 +  local_part_suffix_optional 
 +  data = "#Sieve filter\n${sg{${readfile{ACTIVE_SIEVE}}}{\r}{}}"
 +  sieve_useraddress = "$local_part"
 +  sieve_subaddress = "${sg{$local_part_suffix}{^.}{}}"
 +  sieve_vacation_directory = VACATION_DIR
 +  pipe_transport = address_pipe
 +  reply_transport = address_reply
 +  file_transport = vdom_sieve_file 
 +</code>
 +
 +Note, the redirect router allows either "+" or "-" as a suffix, which may need to be tweaked depending on site requirements.
 +
 +/etc/exim4/conf.d/transport/40_local_sieve
 +
 +<code>
 +vdom_sieve_file:
 +    debug_print = "T: vdom_sieve_file for $local_part@$domain ($address_file)"
 +    driver = appendfile
 +    delivery_date_add
 +    envelope_to_add
 +    return_path_add
 +    directory = VDOM_MAILDIR/${sg {.${sg {$address_file}{/}{.}}/} \
 +      {^.(INBOX|inbox)/} {}}
 +    maildir_format = true
 +    user = vmail
 +    group = vmail
 +</code>
 +    
 +Note: The directory line might need a little fixing to fully support Maildir, but currently it replaces "/" characters with dots and assumes "inbox" as the user maildir root.
 +
 +
 +===== References =====
 +
 +http://www.exim.org/exim-html-current/doc/html/spec_html/filter_ch02.html
 +
 +https://debian-administration.org/users/lee/weblog/43
 +
 +https://github.com/Exim/exim/blob/master/doc/doc-txt/README.SIEVE
 +
 +https://tty1.net/blog/2011/sieve-tutorial_en.html
exim4/sieve_filter.1479133919.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki