[Dovecot] Sieve's spamtest always returns 0
I am a bit at a loss here with Sieve (pigeonhole) and the spamtest extension. I am using Dovecot 2.1.7 (backported to Debian squeeze), which comes with Pigeonhole 0.3.0.
Messages are scanned with SpamAssassin, which adds a header like
X-Spam-Status: Yes, score=84.6 required=5.0 tests=…
and so I configured spamtest in conf.d/90-plugin.conf like so:
sieve_spamtest_status_type = score sieve_spamtest_status_header = X-Spam-Status: [^,]*, score=(-?[[:digit:]]+\.[[:digit:]]).* sieve_spamtest_max_header = X-Spam-Status: [^,]*, score=[^[:space:]]+ required=(-?[[:digit:]]+\.[[:digit:]]).*
I tested those regular expressions with sed -r, e.g.
% sed -rne "s@^X-Spam-Status: [^,]*, score=-?[[:digit:]]+\.[[:digit:]] required=(-?[[:digit:]]+\.[[:digit:]]).*@\1@p" mailfile 5.0
and they work.
Unfortunately, in sieve scripts, the spamtest value is always 0, which is indicative of the spamtest "not having run", which in this case I assume means that the regular expression didn't match.
Am I right in assuming that the matching happens at the time of evaluation, and so adding the headers using vnd.dovecot.filter just before works?
Or does the spamtest matching happen before the sieve scripts are executed?
Can you see any other reason why spamtest always yields a value of 0?
Thanks,
-- martin | http://madduck.net/ | http://two.sentenc.es/
"those who are faithful know only the trivial side of love: it is the faithless who know love's tragedies." -- oscar wilde
spamtraps: madduck.bogus@madduck.net
also sprach martin f krafft madduck@madduck.net [2013-12-27 18:04 +1300]:
I tested those regular expressions with sed -r, e.g.
% sed -rne "s@^X-Spam-Status: [^,]*, score=-?[[:digit:]]+\.[[:digit:]] required=(-?[[:digit:]]+\.[[:digit:]]).*@\1@p" mailfile 5.0
and they work.
Unfortunately, in sieve scripts, the spamtest value is always 0, which is indicative of the spamtest "not having run", which in this case I assume means that the regular expression didn't match.
The documentation talks about "POSIX regular expressions", but the examples use extended regexps. This should probably be clarified.
However, even if I remove the -r in the above sed call and escape the characters +?(), it does not work. Character classes, such as [:digit:] are available in regular POSIX regexps, to my knowledge.
So: the documentation needs clarification, but my problem remains.
Yes, I could just "text"-match against X-Spam-Flag (which I now do), but I'd prefer it if the user could match against a spam probability, e.g. already filter if SpamAssassin assigns 6 out of 10 required points.
Thanks,
-- martin | http://madduck.net/ | http://two.sentenc.es/
"geld ist das brecheisen der macht." - friedrich nietzsche
spamtraps: madduck.bogus@madduck.net
On 12/27/2013 6:04 AM, martin f krafft wrote:
X-Spam-Status: Yes, score=84.6 required=5.0 tests=…
and so I configured spamtest in conf.d/90-plugin.conf like so:
sieve_spamtest_status_type = score sieve_spamtest_status_header = X-Spam-Status: [^,]*, score=(-?[[:digit:]]+\.[[:digit:]]).*
This configuration is incomplete. Your logs should show an error about that. Testing with sieve-test shows:
stephan@klara:~/src/devel$ sieve-test ~/frop.sieve ~/frop.eml sieve-test(stephan): Error: sieve: spamtest: none of sieve_spamtest_max_header or sieve_spamtest_max_value is configured sieve-test(stephan): Error: sieve: spamtest: none of sieve_spamtest_max_header or sieve_spamtest_max_value is configured [...]
For example, your config should look like this (with max value 10; i.e., the value beyond which it is spam with 100% certainty):
sieve_spamtest_status_type = score sieve_spamtest_status_header = X-Spam-Status: [^,]*, score=(-?[[:digit:]]+\.[[:digit:]]).* sieve_spamtest_max_value = 10
The sieve-test tool can be used to verify:
stephan@klara:~/src/devel$ sieve-test -t - -Tlevel=matching ~/frop.sieve ~/frop.eml
## Started executing script 'frop'
3: spamtest test [percent=false]
3: extracted score=84.600, max=10.000, ratio=100 %
3: starting :is' match with
i;ascii-casemap' comparator:
3: matching value 10' 3: with key
0' => 0
3: finishing match with result: not matched
3: jump if result is false
3: jumping to line 4
## Finished executing script 'frop'
[...]
Regards,
Stephan.
also sprach Stephan Bosch stephan@rename-it.nl [2013-12-28 08:31 +1300]:
This configuration is incomplete. Your logs should show an error about that. Testing with sieve-test shows:
Oh, thank you for introducing me to sieve-test, somehow I have missed that. Sorry!
And thank you also for your quick reply!
Unfortunately, the problem remains, and sieve-test is not as helpful as I had hoped. My script is attached, as well as the wrapper I use for spamc.
Here is the output generated by sieve-test. The spam message is bare and does *not* contain the wanted headers, because those are added by vnd.dovecot.filter invoking spamc:
% sieve-test -D -t- -Tlevel=matching -x +spamtest /tmp/spam.sieve /tmp/spam.msg sieve-test(madduck): Debug: sieve: include: sieve_global_dir is not set; it is currently not possible to include `:global' scripts. sieve-test(madduck): Debug: sieve: Pigeonhole Sieve Extprograms plugin version 0.1.0 loaded debug: script binary /tmp/spam.svbin successfully loaded. debug: binary save: not saving binary /tmp/spam.svbin, because it is already stored.
## Started executing script 'spam'
6: filter action
6: execute program `spamc'
debug: filter action: piping message to program: spamc.
debug: filter action: running program: spamc.
debug: filter action: piping data to forked program /etc/dovecot/sieve-filter/spamc'. 6: executed program successfully 6: changed message 8: header test 8: starting
:contains' match with i;ascii-casemap' comparator: 8: extracting
X-Spam-Status' headers from message
8: matching value Yes, score=66.5/5.0 tests=ADVANCE_FEE_2_NEW_FORM, ADVANCE_FEE_2_NEW_FRM_MNY,A...' 8: with key
score' => 1
8: finishing match with result: matched
8: jump if result is false
8: not jumping
9: debug_log "X-Spam-Score header present and contains 'score'"
spam: line 9: info: DEBUG: X-Spam-Score header present and contains 'score'.
12: spamtest test [percent=false]
12: spamtest: header 'X-Spam-Status' not found in message
12: starting :value-eq' match with
i;ascii-numeric' comparator:
12: matching value 0' 12: with key
0' => 1
12: finishing match with result: matched
12: jump if result is false
12: not jumping
13: debug_log "spamtest found no match!"
spam: line 13: info: DEBUG: spamtest found no match!.
13: jumping to line 51
## Finished executing script 'spam'
Performed actions:
(none)
Implicit keep:
- store message in folder: INBOX sieve-test(madduck): Info: final result: success
So, as I had suspected in the original message, spamtest seems to look at the original message, not the one returned from the vnd.dovecot.filter. The regular sieve header match, however, *does* consult the filtered output.
So I think that in addition to the clarification about regular vs. extended expressions in the docs, this is also a bug in need of fixing…
… or am I still doing something wrong?
-- martin | http://madduck.net/ | http://two.sentenc.es/
"a man's very highest moment is, i have no doubt at all, when he kneels in the dust, and beats his breast, and tells all the sins of his life." -- oscar wilde
spamtraps: madduck.bogus@madduck.net
On 12/28/2013 12:43 AM, martin f. krafft wrote:
also sprach Stephan Bosch stephan@rename-it.nl [2013-12-28 08:31 +1300]:
This configuration is incomplete. Your logs should show an error about that. Testing with sieve-test shows: Oh, thank you for introducing me to sieve-test, somehow I have missed that. Sorry!
And thank you also for your quick reply!
So, as I had suspected in the original message, spamtest seems to look at the original message, not the one returned from the vnd.dovecot.filter. The regular sieve header match, however, *does* consult the filtered output.
You are right. This should fix it (and improves test suite):
http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/f9fd5606b3e7
So I think that in addition to the clarification about regular vs. extended expressions in the docs, this is also a bug in need of fixing…
Did that too.
Regards,
Stephan.
participants (3)
-
martin f krafft
-
martin f. krafft
-
Stephan Bosch