![dovecot + rspamd:学习 ham 和 spam](https://linux22.com/image/793686/dovecot%20%2B%20rspamd%EF%BC%9A%E5%AD%A6%E4%B9%A0%20ham%20%E5%92%8C%20spam.png)
我已经安装了我自己的邮件服务器。它使用 postfix、dovecot 和 rspamd。除了学习无害邮件和垃圾邮件外,电子邮件的传递已经非常顺利。
我发现以下内容指示在 dovecot 文档中。那里有一个 shell 脚本,由 sievelearn-ham.sh
调用learn-spam.sh
,其中包含用于根据所使用的垃圾邮件服务(例如 rspamd)学习电子邮件的相应命令。
我已经修改了脚本,以便将简单的行也记录在文件中,这样我就知道它已被执行。我注意到该脚本从未被调用过。
/usr/bin/learn-ham.sh:
#!/bin/sh
set -e
LOG_FILE="/var/log/dovecot/$(basename ${0}).log"
function logInfo() {
TIMESTAMP=$(date '+%Y-%m-%d_%H:%M:%S' )
echo "${TIMESTAMP}: INFO: ${1}"
echo "${TIMESTAMP}: INFO: ${1}" >> "${LOG_FILE}"
}
logInfo "Start learning ham"
exec /usr/bin/rspamc --connect "localhost:11333" --password "[masked]" learn_ham
logInfo "Finished learning ham"
我已经debug_log
向筛选脚本添加了消息。要查明至少两个筛选脚本是否已执行。我在文件中找不到相应的日志行debug.log
。
/var/vmail/sieve/global/report-ham.sieve:
# Documentation:
# https://doc.dovecot.org/configuration_manual/howto/antispam_with_sieve/#replacing-antispam-plugin-with-imapsieve
require ["vnd.dovecot.debug", "vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
debug_log "Start sieve script for learning ham.";
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
}
if string "${mailbox}" "Trash" {
stop;
}
if string "${mailbox}" "INBOX/Trash" {
stop;
}
if environment :matches "imap.user" "*" {
set "username" "${1}";
}
debug_log "Execute learn-ham.sh";
pipe :copy "learn-ham.sh" [ "${username}" ];
该指令表示筛选扩展sieve-pipe
只能由 指定目录内的程序调用sieve_pipe_bin_dir
。
Sieve 只允许您运行 sieve_pipe_bin_dir 下的脚本。您不能使用 /usr/local/bin/my-sieve-filter.sh,而必须将脚本放在 sieve_pipe_bin_dir 下并使用 my-sieve-filter.sh。
但是,由于sieve_pipe_bin_dir
定义了包含程序的目录sieve-pipe
,它应该指向/usr/bin
,因为sieve-filter
也存在于那里。
但是Arch Linux 上没有二进制文件sieve-pipe
。也不可用。 现在我问自己,这个程序是从哪里来的? 我在使用 的官方软件包中找不到或。/usr/bin
sieve-execute
sieve-pipe
sieve-execute
pacman --query --list | grep --perl-regexp '/usr/bin/sieve-(pipe|execute)'
文档中命名了一个 unix 套接字。Unix 套接字当然可以稍后创建。这是否仍需定义 - 如果需要,如何定义或在哪里定义?
# The directory where the program sockets are located for the
# vnd.dovecot.pipe, vnd.dovecot.filter and vnd.dovecot.execute extension
# respectively. The name of each unix socket contained in that directory
# directly maps to a program-name referenced from the Sieve script.
#sieve_pipe_socket_dir = sieve-pipe
#sieve_filter_socket_dir = sieve-filter
#sieve_execute_socket_dir = sieve-execute
# The directory where the scripts are located for direct execution by the
# vnd.dovecot.pipe, vnd.dovecot.filter and vnd.dovecot.execute extension
# respectively. The name of each script contained in that directory
# directly maps to a program-name referenced from the Sieve script.
#sieve_pipe_bin_dir = /usr/lib/dovecot/sieve-pipe
#sieve_filter_bin_dir = /usr/lib/dovecot/sieve-filter
#sieve_execute_bin_dir = /usr/lib/dovecot/sieve-execute
sieve_pipe_bin_dir = /usr/bin
sieve_filter_bin_dir = /usr/bin
sieve_execute_bin_dir = /usr/bin
}
dovecot插件配置:
plugin {
imapsieve_mailbox1_before = file:/var/vmail/sieve/global/report-spam.sieve
imapsieve_mailbox1_causes = COPY
imapsieve_mailbox1_name = Junk
imapsieve_mailbox2_before = file:/var/vmail/sieve/global/report-ham.sieve
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_from = Junk
imapsieve_mailbox2_name = *
sieve = file:~/sieve;active=~/.dovecot.sieve
sieve_before = /var/vmail/sieve/global/main.sieve
sieve_execute_bin_dir = /usr/bin
sieve_filter_bin_dir = /usr/bin
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
sieve_pipe_bin_dir = /usr/bin
sieve_plugins = sieve_imapsieve sieve_extprograms
}