Dovecot

如何使用 MySQL 身份驗證配置 Dovecot/Pigeonhole

  • April 14, 2019

我有一個使用 Spamassassin 的 Dovecot 伺服器。我可以使用 Thunderbird 和 Bluemail 客戶端接收郵件。我使用 smtp2go 發送郵件。

我想配置 Pigeonhole Sieve,但發現配置非常艱鉅。

所有郵件都被傳遞到 MySQL 數據庫中定義的虛擬郵箱。他們去 /var/mail/vhosts。我現在只託管一個域。

那麼,最簡單的設置方法是什麼?我現在基本上想做的就是將垃圾郵件發送到每個使用者的垃圾郵件文件夾。dovecot -n 的輸出:

# 2.2.33.2 (d6601f4ec): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.4.21 (92477967)
# OS: Linux 4.15.0-47-generic x86_64 Ubuntu 18.04.2 LTS ext4
auth_mechanisms = plain login
log_path = /var/log/dovecot.log
mail_location = maildir:/var/mail/vhosts/%d/%n/
mail_privileged_group = mail
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 index ihave duplicate mime foreverypart extracttext
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 {
 args = /etc/dovecot/deny-users
 deny = yes
 driver = passwd-file
}
passdb {
 args = /etc/dovecot/dovecot-sql.conf.ext
 driver = sql
}
postmaster_address = dev@vietfeir.com
protocols = imap lmtp sieve
service auth-worker {
 user = vmail
}
service auth {
 unix_listener /var/spool/postfix/private/auth {
   group = postfix
   mode = 0666
   user = postfix
 }
 unix_listener auth-userdb {
   mode = 0600
   user = vmail
 }
 user = dovecot
}
service imap-login {
 inet_listener imap {
   port = 0
 }
 inet_listener imaps {
   port = 993
   ssl = yes
 }
}
service lmtp {
 unix_listener /var/spool/postfix/private/dovecot-lmtp {
   group = postfix
   mode = 0600
   user = postfix
 }
}
service pop3-login {
 inet_listener pop3 {
   port = 0
 }
 inet_listener pop3s {
   port = 995
   ssl = yes
 }
}
ssl = required
ssl_cert = </etc/letsencrypt/live/civicrm.vietfeir.com/fullchain.pem
ssl_client_ca_dir = /etc/ssl/certs
ssl_key =  # hidden, use -P to show it
userdb {
 driver = passwd
}
userdb {
 args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
 driver = static
}

這是目前的 dovecot -n 輸出:

# 2.2.33.2 (d6601f4ec): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.4.21 (92477967)
# OS: Linux 4.15.0-47-generic x86_64 Ubuntu 18.04.2 LTS ext4
auth_mechanisms = plain login
lda_mailbox_autocreate = yes
log_path = /var/log/dovecot.log
mail_location = maildir:/var/mail/vhosts/%d/%n/
mail_privileged_group = mail
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 index ihave duplicate mime foreverypart extracttext
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 Spam {
   auto = subscribe
   special_use = \Junk
 }
 mailbox Trash {
   special_use = \Trash
 }
 prefix = 
}
passdb {
 args = /etc/dovecot/deny-users
 deny = yes
 driver = passwd-file
}
passdb {
 args = /etc/dovecot/dovecot-sql.conf.ext
 driver = sql
}
plugin {
 sieve_before = /var/mail/before.svbin
 sieve_extensions = +fileinto
 sieve_trace_dir = /var/log
 sieve_trace_level = matching
}
postmaster_address = dev@vietfeir.com
protocols = imap lmtp
service auth-worker {
 user = vmail
}
service auth {
 unix_listener /var/spool/postfix/private/auth {
   group = postfix
   mode = 0666
   user = postfix
 }
 unix_listener auth-userdb {
   mode = 0600
   user = vmail
 }
 user = dovecot
}
service imap-login {
 inet_listener imap {
   port = 0
 }
 inet_listener imaps {
   port = 993
   ssl = yes
 }
}
service lmtp {
 unix_listener /var/spool/postfix/private/dovecot-lmtp {
   group = postfix
   mode = 0600
   user = postfix
 }
}
service pop3-login {
 inet_listener pop3 {
   port = 0
 }
 inet_listener pop3s {
   port = 995
   ssl = yes
 }
}
ssl = required
ssl_cert = </etc/letsencrypt/live/civicrm.vietfeir.com/fullchain.pem
ssl_client_ca_dir = /etc/ssl/certs
ssl_key =  # hidden, use -P to show it
userdb {
 driver = passwd
}
userdb {
 args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
 driver = static
}

注意:我嘗試過引用 before.sieve 和 before.svbin 沒有區別。

這是日誌:

     ## Started executing script 'before'
  2: header test
  2:   starting `:contains' match with `i;ascii-casemap' comparator:
  2:   extracting `X-Spam-Level' headers from message
  2:   matching value `**************************************************'
  2:     with key `*****' => 1
  2:   finishing match with result: matched
  2: jump if result is false
  2:   not jumping
  3: fileinto action
  3:   store message in mailbox `Hormel'
  4: stop command; end all script execution
     ## Finished executing script 'before'

它表示該消息儲存在郵箱“Hormel”中,但它沒有創建郵箱。

我在您目前的配置中看不到任何會阻止您在任何使用者配置的文件之前簡單地添加另一個篩子文件的內容:

protocol lmtp {
   mail_plugins = $mail_plugins sieve
}
plugin {
   sieve_before = /var/mail/before.sieve
   sieve_extensions = +fileinto +mailbox
}

這為您提供了一個/var/mail/before.sieve要在任何其他篩子腳本之前執行的文件。您可以根據您知道垃圾郵件過濾為您添加的某些標題移動郵件:

require ["fileinto", "mailbox"];
if header :contains "X-Spam-Level" "*****" {
     fileinto :create "Junk";
     stop;
}

這個文件不需要是可寫的,只要你使用sievec /var/mail/before.sieve(creating /var/mail/before.svbin)手動編譯它

在你實施這樣的事情之前,請檢查這是否對你的所有使用者真的有用——也許他們想以不同的方式過濾他們的郵件,那麼sieve_default可能更合適。

引用自:https://serverfault.com/questions/962890