User Tools

Site Tools


exim4:sieve_filter

Exim4 - Sieve Filter

Exim4 Sieve filter.

The filter contains an automatic response and a forwarding.

router

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}}}}

Transport

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

active_script

# 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 =

or

# 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 ;

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 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.
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}

The following router is installed to /etc/exim4/conf.d/router/350_local_sieve

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 

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

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

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

exim4/sieve_filter.txt · Last modified: 2020/07/15 10:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki