[Dovecot] Sieve's spamtest always returns 0

martin f. krafft madduck at madduck.net
Sat Dec 28 01:43:29 EET 2013


also sprach Stephan Bosch <stephan at 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 at madduck.net
-------------- next part --------------
#!/bin/sh
set -eu

if find /tmp/dovecot-hack -mmin -1 | grep -q /; then
  exit 1
fi

# HACK because vnd.dovecot.filter needs the filter to soak up all input before
# it will even start reading its output. 

TMPFILE=$(tempfile -p spamc)
cleanup() { rm -f $TMPFILE; trap - EXIT; }
trap cleanup EXIT

cat > "$TMPFILE"
spamc "$@" < "$TMPFILE"

cleanup
-------------- next part --------------
require [ "vnd.dovecot.filter"];
require [ "spamtest", "relational", "comparator-i;ascii-numeric" ];
require [ "fileinto", "mailbox" ];
require [ "vnd.dovecot.debug" ];

filter "spamc" [ "--no-safe-fallback" ];

if header :contains "X-Spam-Status" "score" {
  debug_log "X-Spam-Status header present and contains 'score'";
}

if spamtest :value "eq" :comparator "i;ascii-numeric" "0" {
  debug_log "spamtest found no match!";
}
elsif spamtest :value
   "ge" :comparator "i;ascii-numeric" "2" {

  if spamtest :value "eq" :comparator "i;ascii-numeric" "1" { debug_log "spamtest value == 1"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "2" { debug_log "spamtest value == 2"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "3" { debug_log "spamtest value == 3"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "4" { debug_log "spamtest value == 4"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "5" { debug_log "spamtest value == 5"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "6" { debug_log "spamtest value == 6"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "7" { debug_log "spamtest value == 7"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "8" { debug_log "spamtest value == 8"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "9" { debug_log "spamtest value == 9"; }
  if spamtest :value "eq" :comparator "i;ascii-numeric" "10" { debug_log "spamtest value == 10"; }

#if header "X-Spam-Flag" "YES" {

  if mailboxexists "Junk" {
    debug_log "file spam into existing mailbox 'Junk'";
    fileinto "Junk";
  }
  elsif mailboxexists "junk" {
    debug_log "file spam into existing mailbox 'junk'";
    fileinto "junk";
  }
  elsif mailboxexists "spam" {
    debug_log "file spam into existing mailbox 'spam'";
    fileinto "spam";
  }
  else {
    debug_log "file spam into mailbox 'Spam'";
    fileinto :create "Spam";
  }
  stop;
  debug_log "after stop";
}
else {
  debug_log "spamtest asserts message free of spam";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: digital_signature_gpg.asc
Type: application/pgp-signature
Size: 1124 bytes
Desc: Digital signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)
URL: <http://dovecot.org/pipermail/dovecot/attachments/20131228/fbe86faf/attachment.bin>


More information about the dovecot mailing list