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 12 Dec 2019, 11:28 PM   #1
JamesHenderson
Cornerstone of the Community
 
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
sieve if/elseif question

Hi,

Using Fastmail's rule maker, I get sieve that looks like the following....

Code:
### 7. Sieve generated for organise rules
if criteria-1{
  do_thing-1;
}
elsif 
criteria-2{
  do_thing-2;
}
When I get an email, containing both the criteria 1 & 2, shouldn't it get caught by the first stop (i.e. the last criteria doesn't get processed?
JamesHenderson is offline   Reply With Quote

Old 13 Dec 2019, 12:10 AM   #2
BritTim
The "e" in e-mail
 
Join Date: May 2003
Location: mostly in Thailand
Posts: 3,084
Yes. For that reason, it can be important to ensure the rules are in the desired order.
BritTim is offline   Reply With Quote
Old 13 Dec 2019, 12:16 AM   #3
JamesHenderson
Cornerstone of the Community
 
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
Quote:
Originally Posted by BritTim View Post
Yes. For that reason, it can be important to ensure the rules are in the desired order.
Huh. ...so I have an email that seems to do the opposite.

Criteria-1 is X-Resolved-to is exactly ...
Criteria-2 is List-Unsubscribe exists

Both exist in the email in question but it is ending up in the folder set by Criteria-2.
JamesHenderson is offline   Reply With Quote
Old 13 Dec 2019, 12:22 AM   #4
JamesHenderson
Cornerstone of the Community
 
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
when I try it in Fastmail's sieve tester, it works correctly...

perhaps I should raise a ticket..
JamesHenderson is offline   Reply With Quote
Old 15 Dec 2019, 12:42 AM   #5
JeremyNicoll
Essential Contributor
 
Join Date: Dec 2017
Location: Scotland
Posts: 483
Have you raised a ticket?

If not, it seems to me that you need to know categorically if your "criteria-1" test condition is really being matched for this email, because if it is not then having action-2 occur is not a surprise.

Other people have mentioned in other discussions that the sieve tester does not work properly. I don't know what it doesn't do, but perhaps your example has fallen down one of the tester's traps?

Perhaps you could edit the sieve rules directly (using the link at the foot of the rules page) and place code, just containing that condition, much higher up.

For example, I just added to my sieve code (in the optional user code section right at the top immediately after the "require" statement):

Code:
if header :contains "Subject" "this is just a sieve test" {
  addflag "\\Flagged";
  stop;
}
so any mail that satisifed that would have the flag (red pin) set, but because of the "stop" no other sieve processing would be done. Sieve's default action (which is to "keep" every mail, routeing them to the Inbox unless explicitly told to discard it or place it elsewhere) means such a mail also goes to the Inbox.

I sent myself a test email which didn't meet the condition and it ended up where I expected, then sent one which did.. and it was flagged. I don't set flags in any other rule so it must have been done by that rule.
JeremyNicoll is offline   Reply With Quote
Old 15 Dec 2019, 12:44 AM   #6
JamesHenderson
Cornerstone of the Community
 
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
Quote:
Originally Posted by JeremyNicoll View Post
Have you raised a ticket?

If not, it seems to me that you need to know categorically if your "criteria-1" test condition is really being matched for this email, because if it is not then having action-2 occur is not a surprise.

Other people have mentioned in other discussions that the sieve tester does not work properly. I don't know what it doesn't do, but perhaps your example has fallen down one of the tester's traps?

Perhaps you could edit the sieve rules directly (using the link at the foot of the rules page) and place code, just containing that condition, much higher up.

For example, I just added to my sieve code (in the optional user code section right at the top immediately after the "require" statement):

Code:
if header :contains "Subject" "this is just a sieve test" {
  addflag "\\Flagged";
  stop;
}
so any mail that satisifed that would have the flag (red pin) set, but because of the "stop" no other sieve processing would be done. Sieve's default action (which is to "keep" every mail, routeing them to the Inbox unless explicitly told to discard it or place it elsewhere) means such a mail also goes to the Inbox.

I sent myself a test email which didn't meet the condition and it ended up where I expected, then sent one which did.. and it was flagged. I don't set flags in any other rule so it must have been done by that rule.
I haven't yet, no. I'll try your suggestion first - thanks!
JamesHenderson is offline   Reply With Quote
Old 15 Dec 2019, 01:29 AM   #7
JeremyNicoll
Essential Contributor
 
Join Date: Dec 2017
Location: Scotland
Posts: 483
I've also experimented with the following actions:

Code:
addheader       "X-JN-Breadcrumb" "Inserted at start of headers by my sieve code";
addheader :last "X-JN-Breadcrumb" "Appended at   end of headers by sieve test 23";
Clearly one should only insert X- headers! Headers added like this either get appended at the foot of the block of headers in an email, or placed right at the start. There are notes on how not to use addheader in the RFC, see: https://tools.ietf.org/html/rfc5293

Judicious use of this Sieve command allows one to see which parts of one's code have been executed.
JeremyNicoll is offline   Reply With Quote
Old 15 Dec 2019, 01:59 AM   #8
JamesHenderson
Cornerstone of the Community
 
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
Quote:
Originally Posted by JeremyNicoll View Post
I've also experimented with the following actions:

Code:
addheader       "X-JN-Breadcrumb" "Inserted at start of headers by my sieve code";
addheader :last "X-JN-Breadcrumb" "Appended at   end of headers by sieve test 23";
Clearly one should only insert X- headers! Headers added like this either get appended at the foot of the block of headers in an email, or placed right at the start. There are notes on how not to use addheader in the RFC, see: https://tools.ietf.org/html/rfc5293

Judicious use of this Sieve command allows one to see which parts of one's code have been executed.
cheers - I'll have a crack at that! :-)
JamesHenderson is offline   Reply With Quote
Old 15 Dec 2019, 07:36 PM   #9
JamesHenderson
Cornerstone of the Community
 
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
OK, took a look this morning and have added the code (flagging and breadcrumbs) - thanks both those great ideas!

...why is it clear that we should only add "X-" headers though?

cheers,
J.
JamesHenderson is offline   Reply With Quote
Old 15 Dec 2019, 07:52 PM   #10
JamesHenderson
Cornerstone of the Community
 
Join Date: Jan 2003
Location: Oxfordshire, UK
Posts: 603
Quote:
Originally Posted by JeremyNicoll View Post
I've also experimented with the following actions:
Code:
addheader       "X-JN-Breadcrumb" "Inserted at start of headers by my sieve code";
well that worked wonderfully and I now know that it is working for the emails that just came through.

I did find a piece of code that that I must have half written and forgotten about (it was an if with no then (if you know what I mean) and may have been throwing the whole thing off.

thanks so much - I know I'll be using breadcrumbs again in future
JamesHenderson is offline   Reply With Quote
Old 16 Dec 2019, 05:46 AM   #11
xyzzy
Essential Contributor
 
Join Date: May 2018
Posts: 474
Quote:
Originally Posted by JeremyNicoll View Post
Clearly one should only insert X- headers
I don't believe there are any restrictions on what you name the header (ignoring possible digital signature implications should you redirect the message).

Last edited by xyzzy : 16 Dec 2019 at 05:59 AM.
xyzzy is offline   Reply With Quote
Old 16 Dec 2019, 09:03 AM   #12
JeremyNicoll
Essential Contributor
 
Join Date: Dec 2017
Location: Scotland
Posts: 483
Quote:
Originally Posted by xyzzy View Post
I don't believe there are any restrictions on what you name the header (ignoring possible digital signature implications should you redirect the message).
I was under the impression that there is a convention that headers which are arbitrary extensions to the 'standard' ones should have "X-" prefixes.

That appears to have been suggested in RFC822 - see: https://tools.ietf.org/html/rfc822 though in reverse where it is stated that no future email standard will define a 'standard' header whose name starts "X-". That means that in theory adding an "X-" header won't cause a problem if the email is then forwarded or whatever.

However, there are now lots of "X-" headers added, mainly by anti-spam measures and those designed to detect email looping round and round between various servers and never being delivered, and one drawback of there being no standard naming convention for them is that you cannot be sure that a header you add won't cause a problem if it has a name conflict with someone-else's non-standard header. So, the idea of adding one's own X-headers is not perfect, but what else would you suggest?

The fact that there's a myriad of X- headers in use, without any official agreement on what they all mean - so it's a mess - is discussed in other RFCs eg https://tools.ietf.org/html/rfc6648

The Sieve 'editheader' extension, which supports the 'addheader' command will prevent some specific standard headers from being added.

Last edited by JeremyNicoll : 16 Dec 2019 at 09:10 AM.
JeremyNicoll is offline   Reply With Quote
Old 16 Dec 2019, 09:05 AM   #13
JeremyNicoll
Essential Contributor
 
Join Date: Dec 2017
Location: Scotland
Posts: 483
Quote:
Originally Posted by JamesHenderson View Post
well that worked wonderfully and I now know that it is working for the emails that just came through.

I did find a piece of code that that I must have half written and forgotten about (it was an if with no then (if you know what I mean) and may have been throwing the whole thing off.

thanks so much - I know I'll be using breadcrumbs again in future
Note that the header name I chose started X- (for reasons discussed in another reply), then "JN" because those are my initials, then "Breadcrumb" because it seemed sensible to me. You can use anything you like.
JeremyNicoll 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 04:55 PM.

 

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