|
FastMail Forum All posts relating to FastMail.FM should go here: suggestions, comments, requests for help, complaints, technical issues etc. |
|
Thread Tools |
7 Jan 2019, 02:40 PM | #1 |
Essential Contributor
Join Date: May 2018
Posts: 474
|
Using regex match variables
I was experimenting with regex match variables and I have a test that doesn't work and I am not sure why.
Code:
if header :regex "From" "(^|,)([[:space:]])*\"?.*\"?[[:space:]]*<" { set "f" "${3}"; if string :is "${f}" "xxxx" { fileinto "INBOX.test1; } else { fileinto "INBOX.test2"; } stop; } Match variable documentation says a "The list will contain one string for each wildcard ("?" and "*") in the match pattern". So the first "*" should be ${1}, the "?" is ${2} and what I want should I think be ${3}. But it never seems to match with "xxxx" (appropriately censored here) and it files into test2. So what's wrong with this picture? Note, I am not necessarily going to use this construct but I am just trying to understand what I can and cannot do with sieve by playing around. Last edited by xyzzy : 8 Jan 2019 at 11:30 AM. |
7 Jan 2019, 05:02 PM | #2 |
The "e" in e-mail
Join Date: Jul 2002
Location: VK4
Posts: 2,995
|
I am no expert but try using keep, instead of stop.
|
7 Jan 2019, 05:54 PM | #3 |
Essential Contributor
Join Date: May 2018
Posts: 474
|
The problem is not the fileinto's. The problem is I am not seeing what I expect to see in the match variables and it's going down the wrong path.
I've since done a little more experimentation and it's beginning to look like match variables are set for glob patterns but not for regex, contrary to what the documentation states. In other words I may have stumbled into a sieve implementation bug. |
16 Jan 2019, 01:01 PM | #4 |
Essential Contributor
Join Date: May 2018
Posts: 474
|
Problem solved. What I was forgetting is that match variables for regex's correspond to parenthesized terms within the regex expression. In the expression I wrote I was after what the .* matched. So it should have been written as (.*). Once I did that I could see what the .* was matching.
It turns out that a From: with a non-blank name without enclosing quotes was sucking up the space between the end of the name and the < introducing the email address. The fix was to turn the * into a "lazy *", i.e., .*?. So the final test expression is: Code:
header :regex "From" "(^|,)[[:space:]]*\"?(.*?)\"?[[:space:]]*<" |
Thread Tools | |
|
|