EmailDiscussions.com

EmailDiscussions.com (http://www.emaildiscussions.com/index.php)
-   FastMail Forum (http://www.emaildiscussions.com/forumdisplay.php?f=27)
-   -   Using regex match variables (http://www.emaildiscussions.com/showthread.php?t=74122)

xyzzy 7 Jan 2019 01:40 PM

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;
}

The pattern is what the UI would generate if you specified "The sender's name matches glob pattern *". So I used it in the above snippet of sieve code. Both test1 and test2 exist.

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.

Terry 7 Jan 2019 04:02 PM

I am no expert but try using keep, instead of stop.

xyzzy 7 Jan 2019 04:54 PM

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.

xyzzy 16 Jan 2019 12:01 PM

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:]]*<"
and ${2} contains the name.


All times are GMT +9. The time now is 02:12 PM.


Copyright EmailDiscussions.com 1998-2022. All Rights Reserved. Privacy Policy