[sieve][regex] Matching multiple strings in the "Received" header
Hi,
I'm trying to use this expression in Sieve, but for some reason the filter doesn't work:
require ["fileinto","regex"];
# rule:[gmail-outlook-yahoo-aol-friends] if header :regex "received" ".from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)." { fileinto "INBOX.gmail-hotmail-yahoo-aol-friends"; stop; }
However, it's working fine with egrep: egrep ".from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)." * 1525657297.M401428P1459.host01.quick.net.au,S=10073,W=10275:2,S:Received: from APC01-PU1-obe.outbound.protection.outlook.com (mail-oln040092254061.outbound.protection.outlook.com [40.92.254.61])
Am I using Sieve correctly here? Is ".from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)." expression valid for Sieve? Or do I have to split it in an array as per https://wiki2.dovecot.org/Pigeonhole/Sieve/Examples#Flagging_or_Highlighting... example?
Thanks,
-- Adi Pircalabu
On 07-05-2018 12:13, Adi Pircalabu wrote:
I'm trying to use this expression in Sieve, but for some reason the filter doesn't work:
require ["fileinto","regex"];
# rule:[gmail-outlook-yahoo-aol-friends] if header :regex "received" ".from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)." { fileinto "INBOX.gmail-hotmail-yahoo-aol-friends"; stop; }
Update: this works:
if header :regex "received" "from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)" { fileinto "INBOX.gmail-hotmail-yahoo-aol-friends"; stop; }
How should I write it to also match the space character at both the beginning and end of the expression?
Adi Pircalabu
On 08-05-2018 2:43, Benny Pedersen wrote:
Adi Pircalabu skrev den 2018-05-07 05:10:
How should I write it to also match the space character at both the beginning and end of the expression?
use \ before space char
Tks. Just tried these two, unsuccessfully: "\.from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)\." "\ from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)\ "
However, this expression always matches: "from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)"
What am I missing?
Adi Pircalabu
Hello Adi,
did you try:
" from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com) "
If you need to specify the posix character class:
[[:blank:]] means space and tab. With pcre it would be like [ \t] [[:space:]] includes space, tab, newline, linefeed, formfeed, vertical tab (in pcre like [ \t\n\r\f\v])
"[[:blank:]]from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)[[:blank:]]"
Best regards, Gerald
Am 08.05.2018 um 03:38 schrieb Adi Pircalabu adi@ddns.com.au:
On 08-05-2018 2:43, Benny Pedersen wrote:
Adi Pircalabu skrev den 2018-05-07 05:10:
How should I write it to also match the space character at both the beginning and end of the expression? use \ before space char
Tks. Just tried these two, unsuccessfully: "\.from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)\." "\ from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)\ "
However, this expression always matches: "from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)"
What am I missing?
Adi Pircalabu
On 08-05-2018 16:20, Gerald Galster wrote:
Hello Adi,
did you try:
" from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com) "
If you need to specify the posix character class:
[[:blank:]] means space and tab. With pcre it would be like [ \t] [[:space:]] includes space, tab, newline, linefeed, formfeed, vertical tab (in pcre like [ \t\n\r\f\v])
"[[:blank:]]from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)[[:blank:]]"
Thanks Gerald, none of your solutions worked, but I've just figured it out now. In the expression the space should only be added at the end, *not* at the beginning! In the Received header the first character isn't [[:blank:]], but "f", so I've been chasing the wild goose all this time because I started with the wrong assumption :) Sorry for the noise, all good now.
Cheers,
Adi Pircalabu
Op 08/05/2018 om 08:42 schreef Adi Pircalabu:
On 08-05-2018 16:20, Gerald Galster wrote:
Hello Adi,
did you try:
" from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com) "
If you need to specify the posix character class:
[[:blank:]] means space and tab. With pcre it would be like [ \t] [[:space:]] includes space, tab, newline, linefeed, formfeed, vertical tab (in pcre like [ \t\n\r\f\v])
"[[:blank:]]from.*(outbound.protection.outlook.com|.google.com|.yahoo.com|mx.aol.com)[[:blank:]]"
Thanks Gerald, none of your solutions worked, but I've just figured it out now. In the expression the space should only be added at the end, *not* at the beginning! In the Received header the first character isn't [[:blank:]], but "f", so I've been chasing the wild goose all this time because I started with the wrong assumption :) Sorry for the noise, all good now.
Also keep in mind that "\" is first used for escaping the string itself, meaning that these need to be duplicated.
https://tools.ietf.org/html/rfc5228#section-2.4.2 https://tools.ietf.org/html/draft-murchison-sieve-regex-08#section-3
Regards,
Stephan.
participants (4)
-
Adi Pircalabu
-
Benny Pedersen
-
Gerald Galster
-
Stephan Bosch