EmailDiscussions.com  

Go Back   EmailDiscussions.com > Email Service Provider-specific Forums > FastMail Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Stay in touch wirelessly

FastMail Forum All posts relating to FastMail.FM should go here: suggestions, comments, requests for help, complaints, technical issues etc.

Reply
 
Thread Tools
Old 7 Jan 2019, 02:40 PM   #1
xyzzy
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;
}
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.

Last edited by xyzzy : 8 Jan 2019 at 11:30 AM.
xyzzy is offline   Reply With Quote

Old 7 Jan 2019, 05:02 PM   #2
Terry
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.
Terry is offline   Reply With Quote
Old 7 Jan 2019, 05:54 PM   #3
xyzzy
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.
xyzzy is offline   Reply With Quote
Old 16 Jan 2019, 01:01 PM   #4
xyzzy
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:]]*<"
and ${2} contains the name.
xyzzy is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +9. The time now is 07:00 PM.

 

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