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:]]*<" { 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. |
I am no expert but try using keep, instead of stop.
|
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. |
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:]]*<" |
All times are GMT +9. The time now is 02:12 PM. |
Copyright EmailDiscussions.com 1998-2022. All Rights Reserved. Privacy Policy