Op 28-5-2018 om 14:18 schreef daniel_1983@protonmail.com:
Dear list, I want to define two concurrent rules :
- I want to flag an e-mail containing the word "cloud" in the body
- I want to move mail sent explicitly to me (as opposed to mail sent to an alias I am part of) going to "INOBX.I must answere this"
If I put rule (1) first, everything works as expected. If put rule (2) first, only that rule applies.
Here's a small test case you should be able to reproduce on your setup.
Let's work on this fake test e-mail :
$ cat testmail.eml
Date: Mon, 28 May 2018 12:41:53 +0100 From: friend@otherdomain.tld To: me@mydomain.tld Subject: dur dur la vie
mon frère, le cloud c'est le top du top
Here's the first, broken version of the script
$ cat test.sieve
require ["body","fileinto","imap4flags","vacation"];
# rule:[Mail about me] if anyof (header :contains "to" "me@mydomain.tld", body :text :contains "ahmed") { fileinto "INBOX.I must answere this"; }
# rule:[Mail about the Cloud] if body :text :contains "cloud" { addflag "\\Flagged"; }
Let's test it out, the two rules should be applied :
$ sieve-test test.sieve testmail.eml
Performed actions:
- store message in folder: INBOX.I must answere
Implicit keep:
(none)
sieve-test(root): Info: final result: success $
Notice that the last rule isn't applied although it matches. Now we invert the order of the rules and apply the script on the same test e-mail :
$ cat test.sieve
require ["body","fileinto","imap4flags","vacation"]; # rule:[Mail about the Cloud] if body :text :contains "cloud" { addflag "\\Flagged"; }
# rule:[Mail about me] if anyof (header :contains "to" "me@mydomain.tld", body :text :contains "ahmed") { fileinto "INBOX.I must answere this"; }
Running the test again :
$ sieve-test test.sieve testmail.eml
Performed actions:
- store message in folder: INBOX.I must answere + add IMAP flags: \flagged
Implicit keep:
(none)
sieve-test(root): Info: final result: success $
The IMAP flag was set !
Any ideas ?
You should read the specification: https://tools.ietf.org/html/rfc5232
Summary: the addflag command doesn't actually add the flag to the message immediately; instead, it adds it to an internal list of assigned flags. Only once fileinto is executed, the current list of flags is applied to the message stored for that particular fileinto action. Performing an addflag will not affect fileinto actions that were executed before; it will only affect fileinto (and keep) executed thereafter. That is why the order is so important in your script.
Regards,
Stephan.