[Dovecot] sieve filters
Hi all,
I'm trying to figure out a way of filtering mail from a commercial anti-spam platform. Unfortunately you need to compare part of one header against part of another header. I figured I could solve this using sieve variables and pattern matching, however I'm having little luck and don't know how to debug sieve issues.
# example headers: must compare 0.00799 against 1:0000 (the 2nd number in the 2nd header) # X-pstn-levels: (S: 0.00799/98.42547 CV:99.9000 FC:95.5390 LC:95.5390 R:95.9108 P:95.9108 M:97.0282 C:98.6951 ) # X-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c
if header :matches "X-pstn-levels" "(S: */*" { set "score" "${1}"; if header :matches "X-pstn-settings" " ? (*:*) *" { fileinto "somewhere"; } }
The first if appears to match, as if I move the fileinto up there it works - however it doesn't work as it shown here. Can anyone suggest why? Can I achieve what I'm trying to do with sieve? How can I go about debugging scripts?
Thanks,
Ian
2009/2/19 Ian P. Christian pookey@pookey.co.uk:
The first if appears to match, as if I move the fileinto up there it works - however it doesn't work as it shown here. Can anyone suggest why? Can I achieve what I'm trying to do with sieve? How can I go about debugging scripts?
I've made some progress, but now I'm wondering if it's actually possible....
# X-pstn-levels: (S: 0.00799/98.42547 CV:99.9000 FC:95.5390 LC:95.5390 R:95.9108 P:95.9108 M:97.0282 C:98.6951 ) # X-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c
if header :matches "X-pstn-levels" "(S: */*" { set "score" "${1}"; if header :matches "X-pstn-settings" "? (*:*) *" { set "threshold" "${3}";
if "${score}" :under "${threshold}"
{
}
} }
There doesn't appear to be a way of comparing the value of 2 floating point numeric variables (or integers for that matter).
Any suggestions?
Thanks again,
Ian
Hi Ian,
Ian P. Christian wrote:
2009/2/19 Ian P. Christian pookey@pookey.co.uk:
The first if appears to match, as if I move the fileinto up there it works - however it doesn't work as it shown here. Can anyone suggest why? Can I achieve what I'm trying to do with sieve? How can I go about debugging scripts? You can use the sieve-test command line tool for that. It sure beats sending test mails through deliver all the time. The debugging experience needs improvement though, as trace debug output is a bit cryptic (relates to binary dump) and being able to print debug messages and variables to the console would be a nice thing to have.
I've made some progress, but now I'm wondering if it's actually possible....
# X-pstn-levels: (S: 0.00799/98.42547 CV:99.9000 FC:95.5390 LC:95.5390 R:95.9108 P:95.9108 M:97.0282 C:98.6951 ) # X-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c
if header :matches "X-pstn-levels" "(S: */*" { set "score" "${1}"; if header :matches "X-pstn-settings" "? (*:*) *" { set "threshold" "${3}";
if "${score}" :under "${threshold}" { }
} }
There doesn't appear to be a way of comparing the value of 2 floating point numeric variables (or integers for that matter). Floating point, hmm ... unfortunately no.
If the values were integers you could have done the following:
-- require "relational"; require "variables"; require "comparator-i;ascii-numeric"; require "fileinto";
if header :matches "X-pstn-levels" "(S: */*" { set "score" "${1}";
if header :matches "X-pstn-settings" "? (*:*) *" {
set "threshold" "${3}";
if not string :value "lt" "${score}" "${threshold}" {
/* Do whatever */
fileinto "Not spam";
}
}
}
You could do some nasty string matching to explicitly match the decimal separator and match the integer and fractional part separately.
Now I am wondering. What software produces such headers? :)
Regards,
Stephan.
participants (2)
-
Ian P. Christian
-
Stephan Bosch