Sieve filtering SPAM and redirect

Andre Luiz Paiz andre.paiz at iqm.unicamp.br
Mon Sep 12 13:07:27 UTC 2016


Hi every body. I'm having difficulties to setup my filters correctly  
and I really need some help.

This is my environment:

Mail that is received on the system passes through a sieve_before  
script that checks the message header for SPAM tag and store it into  
the "Junk" folder. If no spam tag is found, mail goes to inbox.
My horde webmail is integrated with sieve, so this allow users to  
create their own scripts to store mail in other folders or forward  
them to external accounts. And this are the problems I'm having:

1 - When users create a forward filter to redirect to external mail,  
mail that is stored inside the Junk folder are not forwarded;
2 - If I insert a "keep" parameter inside the sieve_before script to  
keep processing the rules, the mail is forwarded, but becomes  
duplicated and stored inside the inbox or other folders, if the user  
has more filters.
3 - If I move my sieve_before script to sieve_after, the same thing  
happened, one copy is stored on the user selected folder (inbox or  
filtered), including mail marked as SPAM.

My needs are: I need to separate SPAM and HAM e-mail before users  
intervention (so I need sieve_before). But this SPAM e-mail has to be  
forwarded if a forward filter is created.
Is it possible to use a sieve_after script that moves (instead of  
copy) the user mail marked as SPAM to the Junk folder even if it was  
stored in a different folder?

Is that possible?

Thanks a lot.

Here is my config:

sieve_after content:
require "fileinto";
if header :contains "X-Spam-Flag" "YES" {
  fileinto "Junk";
}

dovecot --version
2.2.10

# 2.2.10: /etc/dovecot/dovecot.conf
# OS: Linux 3.10.0-327.28.2.el7.x86_64 x86_64 CentOS Linux release  
7.2.1511 (Core)
auth_cache_negative_ttl = 0
auth_cache_size = 10 M
auth_mechanisms = plain login
auth_username_format = %Ln
default_client_limit = 1024
default_process_limit = 1024
default_vsz_limit = 1 G
mail_location = maildir:~/Maildir:INDEX=/var/indexes/dovecot/%u
mail_plugins = " mail_log notify quota"
mail_temp_dir = /var/tmp
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope  
encoded-character vacation subaddress comparator-i;ascii-numeric  
relational regex imap4flags copy include variables body
enotify environment mailbox date ihave imapflags notify
mbox_write_locks = fcntl
mmap_disable = yes
namespace inbox {
  inbox = yes
  location =
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
  mailbox Trash {
    special_use = \Trash
  }
  prefix =
}
passdb {
  driver = pam
}
passdb {
  args = /etc/dovecot/dovecot-ldap.conf.ext
  driver = ldap
}
plugin {
  mail_log_events = delete undelete expunge copy mailbox_delete mailbox_rename
  mail_log_fields = uid box msgid size
  quota = maildir
  quota_exceeded_message = Cota de armazenamento de e-mails excedida.  
Quota exceeded for mail store.
  quota_warning = storage=95%% quota-warning 95 %u
  quota_warning2 = storage=85%% quota-warning 85 %u
  quota_warning3 = storage=75%% quota-warning 75 %u
  sieve = ~/.dovecot.sieve
  sieve_before = /var/lib/dovecot/sieve/default.sieve
  sieve_default = /var/lib/dovecot/sieve/default.sieve
  sieve_dir = ~/sieve
  sieve_extensions = +notify +imapflags
}
protocols = imap pop3 lmtp sieve
service anvil {
  client_limit = 14100
  process_limit = 1
}
service auth-worker {
  client_limit = 1
  process_limit = 50
  service_count = 1
}
service auth {
  client_limit = 15100
  process_limit = 1
}
service dict {
  client_limit = 1
}
service imap-login {
  inet_listener imap {
    port = 143
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
  process_limit = 6000
  process_min_avail = 10
  service_count = 1
  vsz_limit = 256 M
}
service imap {
  process_limit = 3000
  vsz_limit = 1 G
}
service lmtp {
  client_limit = 1
  inet_listener lmtp {
    port = 24
  }
  unix_listener lmtp {
    mode = 0666
  }
}
service managesieve-login {
  inet_listener sieve {
    port = 4190
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 110
  }
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
  process_limit = 6000
  process_min_avail = 10
  service_count = 1
}
service pop3 {
  process_limit = 3000
}
service quota-warning {
  executable = script /usr/local/bin/quota-warning.sh
  unix_listener quota-warning {
    mode = 0666
    user = dovecot
  }
  user = root
}
ssl = required
ssl_cert = **************
ssl_key = **************
userdb {
  driver = passwd
}
userdb {
  args = /etc/dovecot/dovecot-ldap.conf.ext
  driver = ldap
}
protocol lmtp {
  mail_plugins = " mail_log notify quota sieve quota"
}
protocol imap {
  mail_plugins = " mail_log notify quota imap_quota"
}
  Atenciosamente
 
André Luiz Paiz
Administração de Redes
Instituto de Química – Unicamp
andre.paiz at iqm.unicamp.br
Telefone: (19)3521-0197


More information about the dovecot mailing list