Sieve filters and @Mail
Sieve is a language that can be used to create filters for electronic mail. It is not tied to any particular operating system or mail architecture, so it can be used with @Mail-Exim. This document details how to do it.
- open up the Exim configure file (/usr/local/atmail/mailserver/configure), and find the following:
#
# Optionally, send the user an SMS message of the email-alert
sms_delivery:
driver = accept
domains = ${lookup mysql {MYSQL_SMSREPLY}{$value}}
condition = ${if
- below this, add the following:
sieve_deliver:
driver = redirect
domains = +local_domains
local_part_suffix = "-*"
local_part_suffix_optional
sieve_subaddress = "${sg{$local_part_suffix}{^-}{}}"
sieve_useraddress = "$local_part"
require_files = ${lookup mysql{SELECT MailDir from Users where Account='${local_part}@${domain}'}}/sievefilter
file = ${lookup mysql{SELECT MailDir from Users where Account='${local_part}@${domain}'}}/sievefilter
check_ancestor
user = atmail
allow_filter
file_transport = sieve_user
reply_transport = mysql_autoreply
verify = false
- then, find the following line:
mysql_autoreply:
driver = autoreply
headers = Content-Type: text/plain; charset=utf-8
to = ${sender_address}
from = ${sender_address}
reply_to = "${local_part}@${domain}"
subject = "AutoReply from ${local_part}@${domain}"
text = ${lookup mysql {MYSQL_AUTOREPLY}{$value}}
once = ${lookup mysql{SELECT concat(MailDir, "/autoreply.db") from Users where Account='${local_part}@${domain}'}}
once_repeat = 1d
once_file_size = 500K
- below this, add the following:
sieve_user:
driver = appendfile
directory = ${lookup mysql{SELECT MailDir from Users where Account='${local_part}@${domain}'}}/${sg{$address_file}{^inbox}{}}
maildir_format
delivery_date_add
envelope_to_add
return_path_add
mode = 0600
- you can then add Sieve filter files to a user's Maildir. The Maildir is located in /usr/local/atmail/users, and is prefixed by the first two letters of an account. For example, the user foo@bar.com will have a sieve filter file at: /usr/local/atmail/users/f/o/foo@bar.com/sievefilter. Note that the sieve filter file needs to have the filename 'sievefilter'.
- a basic howto for Sieve filters can be found at: http://wiki.fastmail.fm/index.php/BasicSieve. Examples can be found at: http://wiki.fastmail.fm/index.php/SieveExamples. Below is a sample Sieve filter for moving emails to the Spam folder when they contain the string "foobar" in the headers:
# Sieve Filter
require ["fileinto"];
if header :contains "testing.com" {
fileinto ".Spam";
stop;
}
Notes:
- the "# Sieve filter" line at the beginning of each file is imperative
- IMAP folders need to be identified with a leading "." character

