如何使用 MySQL 身份验证配置 Dovecot/Pigeonhole

如何使用 MySQL 身份验证配置 Dovecot/Pigeonhole

我有一个运行着 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 = [email protected]
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 = [email protected]
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”中,但它并未创建邮箱。

答案1

在您当前的配置中我没有看到任何内容可以阻止您在任何用户配置的文件前面简单地添加另一个筛选文件:

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(创建/var/mail/before.svbin)手动编译它,此文件就不需要可写

在实施这样的操作之前,请检查这对所有用户是否真的有用 - 也许他们想要以不同的方式过滤他们的邮件,那么sieve_default可能更合适。

相关内容