|
FastMail Forum All posts relating to FastMail.FM should go here: suggestions, comments, requests for help, complaints, technical issues etc. |
|
Thread Tools |
2 Sep 2019, 10:28 PM | #1 |
Cornerstone of the Community
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
|
Sieve Rule weirdness
Hi all,
Can anyone please tell me what I am doing wrong, such that this email: notifications-noreplyATlinkedin.comgoes into my subscriptions folder despite these rules: I thought the use of elsif meant that a subsequent elsif isn't tested if the previous if or elsif is successful. thanks, James. Last edited by JamesHenderson : 2 Sep 2019 at 10:29 PM. Reason: typos |
3 Sep 2019, 02:36 AM | #2 |
Essential Contributor
Join Date: Jan 2017
Posts: 278
|
Firstly I don't think you can have a trailing comma on the end of a list.
Secondly, I don't see anything in RFC 5228 to suggest that [.@] is supported. |
3 Sep 2019, 03:28 AM | #3 | ||
Cornerstone of the Community
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
|
Quote:
Quote:
|
||
3 Sep 2019, 03:40 AM | #4 | ||
Essential Contributor
Join Date: Jan 2017
Posts: 278
|
Quote:
Quote:
:matches doesn't use a regular expression, it's a basic glob. You need :regex. |
||
3 Sep 2019, 03:52 AM | #5 | |
Cornerstone of the Community
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
|
Hi,
Thanks for the fast replies. Quote:
and Yes, just worked that out - thanks! |
|
3 Sep 2019, 07:08 AM | #6 |
Essential Contributor
Join Date: May 2018
Posts: 478
|
Commas are only needed to separate multiple tests, i.e., a list of tests. It has nothing to do with multiple lines. You can put the list items on multiple lines, single lines, any combination.
I keep looking at the construct, :matches "From" "*[.@]linkedin.com" So is the intent here to look for anything or nothing followed by a dot or @ followed by linkedin.com? What's wrong with just "*@linkedin.com"? Personally I never used square brackets within a globing expression so that's what threw me off. For matches brackets are also for specifying a list of alternatives, i.e., ["a", "b", "c']. In regex brackets enclose a list of characters or character ranges. But as shown that is not a valid regex expression. The equivalent regex to a matches "*@linkedin.com" would be would be ".*@linkedin.com" or if you're a purist maybe ".+@linkedin.com". Last edited by xyzzy : 3 Sep 2019 at 07:27 AM. |
3 Sep 2019, 10:11 AM | #7 | ||
Essential Contributor
Join Date: Jan 2017
Posts: 278
|
Quote:
Quote:
Note the double backslash. An extended regular expression would only need one to escape the dot, but the backslash character itself needs to be escaped in sieve strings if it's not escaping a double quote. |
||
3 Sep 2019, 12:03 PM | #8 | ||
Essential Contributor
Join Date: May 2018
Posts: 478
|
Quote:
["*@linkedin.com", "*@*.linkedin.com"] Quote:
".+@(.*\\.)?linkedin\\.com$" taking into account that case you mentioned for the matches, i.e., any email address whose parent domain is linkedin.com. At this point then the regex is probably more concise than the matches. Of course in the real world, IMO, a matches on "*@*linkedin.com" is probably "good enough". Note, I created the following sieve tester script for these cases: Code:
require ["regex", "fileinto"]; #if header :regex "From" ".+@(.*\\.)?linkedin\\.com$" { if header :matches "From" ["*@linkedin.com", "*@*.linkedin.com"] { fileinto "match"; } |
||
3 Sep 2019, 05:02 PM | #9 | |||
Cornerstone of the Community
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
|
Thanks for your reply!
Quote:
Quote:
name@domain.tld Quote:
"." and "@' are my alternatives. |
|||
3 Sep 2019, 05:12 PM | #10 |
Cornerstone of the Community
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
|
I get that I forgot to escape the ".", but don't get either "\\" - could you please explain that as I would have thought the following would have worked:
Code:
.+@(.+\.)?linkedin\.com$ James. btw, I am not actually looking for subdomains of LinkedIn - it was just an example to use. [edit: added my proposed version] Last edited by JamesHenderson : 3 Sep 2019 at 05:36 PM. |
3 Sep 2019, 05:21 PM | #11 | |
Cornerstone of the Community
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
|
Quote:
cheers, James. |
|
3 Sep 2019, 06:51 PM | #12 | ||
Essential Contributor
Join Date: May 2018
Posts: 478
|
Quote:
Quote:
And yes, I really meant address, not header. My mind has a tendency to mean one thing and write another too. |
||
3 Sep 2019, 07:04 PM | #13 | |
Cornerstone of the Community
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
|
Quote:
I got the gist of your code (thanks). but my question was specifically why two slahes were needed in succession. I can see that Fastmail translates my single slash into two, but why? ...I cannot see any reference to double-shlashing having a special meaning in regex (it seems to me that the first slash escapes the second slash). thanks for being so helpful :-) |
|
3 Sep 2019, 09:20 PM | #14 | |
Junior Member
Join Date: Jul 2016
Posts: 23
|
Quote:
That's why I stay away from regex in sieve whenever possible. What about this alternative approach? Code:
if anyof( address :domain :matches "From" ["linkedin.com", "*.linkedin.com"] ){ fileinto "INBOX.work"; } elsif anyof( exists "List-Unsubscribe", body :text :contains "unsubscribe", body :text :contains "Newsletter" ){ fileinto "INBOX.subscriptions"; } Last edited by hbs : 3 Sep 2019 at 10:09 PM. Reason: Correction: backslash instead of slash |
|
3 Sep 2019, 09:26 PM | #15 |
Cornerstone of the Community
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
|
thanks, hbs.
I was not aware of :domain, but that is certainly a robust way of doing it. Whilst I was trying to implement a rule, I was also trying to use it as a way to further my regex/sieve knowledge. Knowing that "this is how fastmail does it" is a bit of a relief as I could not find documentation anywhere for the double-slash. By the way, would the line not be: Code:
address :domain :matches "From" ["@linkedin.com", "*.linkedin.com"] cheers, James. |