使用 Bogofilter、Procmail 和 Mutt 反垃圾邮件,再探
2002 年 11 月,我写了一篇名为“使用 Bogofilter、Procmail 和 Mutt 反垃圾邮件”的文章。 其中包含一个特别方便的配置,可以减少在 bogofilter 中将邮件标记为垃圾邮件或非垃圾邮件的大量工作。 基本前提是您配置您的邮件程序,将您回复或保存的所有邮件标记为非垃圾邮件,因为大多数人只会保存或回复好的内容。
这篇文章在 Google 上获得了相当多的流量,并已成为该主题的几个常见搜索查询的首选。 这本来是件好事,但 bogofilter 的更新日志中列出的一个小细节除外
----8<---- 0.11.0 2003-03-03 * Separated message registration options from unregistration options. '-S' and '-N' have been changed and now just do unregistration. To move a message from one wordlist to the other, use '-S -n' or '-N -s' (as appropriate) ----8<----
此注释意味着 Eric Raymond 更改了 bogofilter 的命令行开关,因此它们现在具有完全相反的效果。 之前的 -S 现在是 -Ns,之前的 -N 现在是 -Sn。
这意味着偶然发现我 2002 年 11 月的文章,但使用的是 2003 年 3 月或更高版本的 bogofilter 的人,会发现这是一个相当令人沮丧的体验。 文章开头列出的宏现在将保存的邮件标记为垃圾邮件,而 X 键将邮件删除为非垃圾邮件。
这个灾难性的更改违反了 Raymond 最近出版的UNIX 编程艺术中阐述的最小惊讶原则。 关于最小惊讶原则的部分引用了 Henry Spencer 的警告,反对那些以熟悉的方式做事但实际上做着非常不同的事情的程序。 bogofilter 命令现在接受与 2002 年 11 月相同的命令行开关,但是,突然之间,2003 年 3 月 3 日,变成了相反的一天。
诚然,bogofilter 尚未达到 1.0 版本,因此预计会有一些更改。 无论如何,这个隐秘的小开关几乎肯定会导致人们错过被错误归类为垃圾邮件的合法邮件。
在我妻子抱怨她无法一次性标记要保存的消息集合后,我对 bogofilter 宏添加了第二个改进。 出现问题的原因是 mutt 宏不会将标记前缀(通常是标准配置上的分号键)的状态传播到宏的组成命令。 因此,标记的消息已在 bogofilter 中归档,但仅保存了光标所在的消息。
作为一种解决方法,以下宏将其标记前缀插入到其索引版本中。 这意味着如果您没有标记任何消息,这些宏会在对当前消息进行操作之前发出哔哔声。 此外,如果您标记了消息但尝试保存单个消息,它们会保存所有标记的消息。 这并不理想,但 mutt 开发人员没有表现出对在 mutt 宏中提供更好的标记前缀钩子的兴趣。
----8<---- macro index s "<enter-command>unset wait_key\n<tag-prefix><pipe-entry>bogofilter -MSn\n<enter-command>set wait_key\n<tag-prefix><save-entry>" macro pager s "<enter-command>unset wait_key\n<pipe-entry>bogofilter -MSn\n<enter-command>set wait_key\n<save-entry>" macro index r "<enter-command>unset wait_key\n<tag-prefix><pipe-entry>bogofilter -Mn\n<enter-command>set wait_key\n<tag-prefix><reply>" macro pager r "<enter-command>unset wait_key\n<pipe-entry>bogofilter -Mn\n<enter-command>set wait_key\n<reply>" macro index g "<enter-command>unset wait_key\n<tag-prefix><pipe-entry>bogofilter -Mn\n<enter-command>set wait_key\n<tag-prefix><group-reply>" macro pager g "<enter-command>unset wait_key\n<pipe-entry>bogofilter -Mn\n<enter-command>set wait_key\n<group-reply>" macro index l "<enter-command>unset wait_key\n<tag-prefix><pipe-entry>bogofilter -Mn\n<enter-command>set wait_key\n<tag-prefix><list-reply>" macro pager l "<enter-command>unset wait_key\n<pipe-entry>bogofilter -Mn\n<enter-command>set wait_key\n<list-reply>" macro index X "<enter-command>unset wait_key\n<tag-prefix><pipe-entry>bogofilter -MNs\n<enter-command>set wait_key\n<tag-prefix><delete-message>" macro pager X "<enter-command>unset wait_key\n<pipe-entry>bogofilter -MNs\n<enter-command>set wait_key\n<delete-message>" ----8<----
幸运的是,关于 procmail 的部分仍然正确,并且在负载较轻的系统上不应引起任何问题。 如果您发现大量的 bogofilter 进程正在拖累您的系统,您可能希望更改第一个节来使用锁文件,如下所示
----8<---- :0fw: bogofilter.lock | bogofilter -u -e -p ----8<----
我的原始配置中的其他两个节可以保持原样。