Перейти к содержанию

Dovecot with DSPAM

Материал из Solipse Wiki

Dovecot

Install

Configs

/etc/dovecot/dovecot.conf

# 2.0.18: /etc/dovecot/dovecot.conf
# OS: Linux 2.6.32-5-amd64 x86_64 Debian wheezy/sid ext4
auth_mechanisms = plain login cram-md5
disable_plaintext_auth = yes
listen = *
log_timestamp = "%Y-%m-%d %H:%M:%S "
mail_location = maildir:/home/vmail/%d/%n
mail_privileged_group = vmail
ssl_cert=</etc/ssl/certs/dovecot.pem
ssl_key=</etc/ssl/private/dovecot.pem
mail_uid = 5000
mail_gid = 5000
passdb {
  args = /etc/dovecot/dovecot-sql.conf
  driver = sql
}
protocols = imap pop3
mail_plugins = $mail_plugins quota
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0660
    user = postfix
  }
  unix_listener auth-master {
    mode = 0600
    user = vmail
  }
  user = vmail
}
service auth-worker {
  # Auth worker process is run as root by default, so that it can access
  # /etc/shadow. If this isn't necessary, the user should be changed to
  # $default_internal_user.
  user = $default_internal_user
  unix_listener auth-worker {
     user = vmail
     mode = 0660
  }
}
service dict {
  unix_listener dict {
    user = vmail
    group = vmail
  }
}
userdb {
  args = uid=5000 gid=5000 home=/home/vmail/%d/%n allow_all_users=yes
  driver = static
}
protocol lda {
  mail_plugins = sieve quota
  auth_socket_path = /var/run/dovecot/auth-master
  postmaster_address = glorin@solipse.ru
  hostname = mx.solipse.ru
  log_path = /home/vmail/dovecot-deliver.log
}
protocol imap {
    mail_plugins = $mail_plugins imap_quota antispam autocreate
}
plugin {
  quota = maildir:user quota
  quota2 = dict:::proxy::quota
  trash = /etc/dovecot/trash.conf
  autocreate = Trash
  autocreate2 = Spam
  #autocreate3 = ..etc..
  autosubscribe = Trash
  autosubscribe2 = Spam
  #autosubscribe3 = ..etc..
  sieve_global_path = /home/vmail/default.sieve
  antispam_backend = dspam
  antispam_signature = X-DSPAM-Signature
  antispam_signature_missing = error
  antispam_trash = trash;Trash;Deleted Items; Deleted Messages
  antispam_spam = Spam
  antispam_dspam_binary = /usr/bin/dspam
  antispam_dspam_args = --deliver;--user;%u
}
dict {
  quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}

/etc/dovecot/dovecot-sql.conf with quota support

driver = mysql
connect = host=127.0.0.1 dbname=postfixadmin user=postfixadmin password=password
default_pass_scheme = PLAIN
password_query = SELECT 5000 as uid, 5000 as gid, username as user, password, CONCAT('*:storage=', quota, 'b') AS userdb_quota_rule FROM mailbox WHERE username = '%u'

Sieve

/home/vmail/default.sieve

require ["regex", "fileinto", "imap4flags"];

# Catch mail tagged as Spam, except Spam retrained and delivered to the mailbox
if allof (header :regex "X-DSPAM-Result" "^(Spam|Virus|Bl[ao]cklisted)$",
          not header :contains "X-DSPAM-Reclassified" "Innocent") {

  # Mark as read
  setflag "\\Seen";

  # Move into the Junk folder
  fileinto "Spam";

  # Stop processing here
  stop;
}

Check rules

sievec /home/vmail/default.sieve

Quota for Postfixadmin

/etc/dovecot/dovecot-dict-sql.conf.ext

connect = host=127.0.0.1 dbname=postfixadmin user=postfixadmin password=password
map {
  pattern = priv/quota/storage
  table = quota2
  username_field = username
  value_field = bytes
}
map {
  pattern = priv/quota/messages
  table = quota2
  username_field = username
  value_field = messages
}

Clean trash if quota exceeded

/etc/dovecot/trash.conf

1 Spam
2 Trash
3 Sent