[英]using sylfilter with procmail
I have been using sylfilter for over a year now (it is available from http://sylpheed.sraoss.jp/sylfilter/ ) and it works great as a filtering tool (no complaints).我已经使用 sylfilter 一年多了(它可以从http://sylpheed.sraoss.jp/sylfilter/ 获得)并且它作为过滤工具非常有效(没有抱怨)。 However, I have been trying to use procmail with sylfilter, but have been having a lot of trouble.
但是,我一直在尝试将 procmail 与 sylfilter 一起使用,但是遇到了很多麻烦。
The web page for the filter shows:过滤器的网页显示:
sylfilter ~/Mail/inbox/1234
as the example to classify a message.作为对消息进行分类的示例。
The return values are as following:返回值如下:
0 junk (spam) 0 垃圾邮件(垃圾邮件)
1 clean (non-spam) 1 个清洁(非垃圾邮件)
2 uncertain 2 不确定
127 other errors 127 其他错误
I have been trying to incorporate sylfilter with procmail but not with much success.我一直在尝试将 sylfilter 与 procmail 合并,但没有取得太大的成功。 The big issue as compared with some other spam tool like bogofilter is that sylfilter does not make any changes to the e-mail message itself (unlike bogofilter, for which examples abound on the web, and which puts in a X-Bogosity field in the message header).
与 bogofilter 等其他垃圾邮件工具相比,最大的问题是 sylfilter 不会对电子邮件本身进行任何更改(与 bogofilter 不同,bogofilter 的示例在网络上比比皆是,并且在消息头)。 I want everything that is classified as Junk to go to $HOME/Mail/Junk and everything that is not to be further classified into folders such as procmail rules.
我希望所有归类为垃圾邮件的内容都转到 $HOME/Mail/Junk,而所有不会进一步归类到文件夹(例如 procmail 规则)的内容。 Perhaps the stuff that returns 2 can go to $HOME/Mail/uncertain.
也许返回 2 的东西可以去 $HOME/Mail/uncertain。
Here is my latest attempt based on suggestions made in the Fedora mailing list.这是我基于 Fedora 邮件列表中提出的建议的最新尝试。
:0 Wc
| /usr/bin/sylfilter /dev/stdin
:0 a
$HOME/Mail/Junk/.
However, this does not process the e-mail message using sylfilter (and the logfile says "No input file." before going on to process the other rules).但是,这不会使用 sylfilter 处理电子邮件消息(并且在继续处理其他规则之前,日志文件会显示“无输入文件。”)。 So, I was wondering if anyone here knew of a similar case and knew the answer to this question.
所以,我想知道这里是否有人知道类似的案例并知道这个问题的答案。
I am not familiar with sylfilter
, and the (somewhat vague) problem description makes me think there is something wrong with feeding it a message on standard input.我不熟悉
sylfilter
,并且(有些模糊的)问题描述让我认为在标准输入上向它提供消息有问题。 But if you can make that work, the following is how you examine a program's exit code in Procmail.但是,如果您可以做到这一点,以下是您在 Procmail 中检查程序退出代码的方法。
:0
* ? sylfilter /dev/stdin
$HOME/Mail/Junk/.
# You should now have the exit code in $? if you want it for further processing
SYLSTATUS=$?
:0
* SYLSTATUS ?? ^^1^^
$HOME/Mail/INBOX/.
# ... etc
The condition succeeds if sylfilter
returns a success (zero) exit code;如果
sylfilter
返回成功(零)退出代码,则条件成功; if it fails, we fall through to subsequent recipes.如果它失败了,我们就会进入后续的食谱。 We save
$?
我们节省
$?
to a named variable so that we can examine its value even if a subsequent recipe resets the system global $?
到一个命名变量,以便我们可以检查它的值,即使后续配方重置系统全局
$?
by invoking some other external program.通过调用其他一些外部程序。
By the by, you should not need to hard-code the path to sylfilter
. sylfilter
,您不需要硬编码sylfilter
的路径。 If it's in a nonstandard location, amend the PATH
at the beginning of your .procmailrc
rather than littering your code with explicit paths to executables.如果它位于非标准位置,请修改
.procmailrc
开头的PATH
,而不是使用指向可执行文件的显式路径来乱扔代码。 So if it's in /usr/local/really/sf/sylfilter
, you'd put所以如果它在
/usr/local/really/sf/sylfilter
,你会放
PATH=/usr/local/really/sf:$PATH
If you need the message in a temporary file, try something like this;如果您需要临时文件中的消息,请尝试这样的操作;
TMP=`mktemp -t sylf.XXXXXXXX`
TRAP='rm -f $TMP'
:0c
$TMP
:0
* ? sylfilter $TMP
$HOME/Mail/Junk/.
# etc as above
The mktemp
command creates a unique temporary file. mktemp
命令创建一个唯一的临时文件。 The TRAP
assignment sets up a command sequence to run when Procmail terminates; TRAP
分配设置了一个命令序列以在 Procmail 终止时运行; this takes care of cleaning out the temporary file when we are done.这会在我们完成后清理临时文件。 Because we will be the only writer to this file, we don't care about locking while writing a copy of the message to this file.
因为我们将是该文件的唯一写入者,所以在将消息副本写入该文件时我们不关心锁定。
For more nitty-gritty syntax details, see also http://www.iki.fi/era/procmail/quickref.html有关详细的语法细节,另请参阅http://www.iki.fi/era/procmail/quickref.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.