[Dovecot] sieve rules processing
Hello list,
My question: is sieve support some kind of "continue" action, to explicit tell server processing rules below current one(if current has triged)?
Situation: I have few rules, which fileinto's to different directories. All is working fine, but if I want redirect all my mail for some period of time to another mailbox, I'm adding rule like this, to be processing first.
if anyof (true) { redirect "koshikov@gmail.com"; keep; }
Mail redirecting, but keep state store messages to INBOX. All I want - to process other rules, which will move message to the right imap directory. This situation also happens with vacation sieve-action. In sieve rfc I didn't find any workaround to that actions.
Maybe someone know how to make sieve working in described way?
Nikita Koshikov schreef:
Hello list,
My question: is sieve support some kind of "continue" action, to explicit tell server processing rules below current one(if current has triged)?
Situation: I have few rules, which fileinto's to different directories. All is working fine, but if I want redirect all my mail for some period of time to another mailbox, I'm adding rule like this, to be processing first.
if anyof (true) { redirect "koshikov@gmail.com"; keep; }
Mail redirecting, but keep state store messages to INBOX. All I want - to process other rules, which will move message to the right imap directory. This situation also happens with vacation sieve-action. In sieve rfc I didn't find any workaround to that actions.
I am not exactly sure what you mean. Why are you providing an explicit keep command when you want to sort the message further? I would think the following example script does what you need:
== require "fileinto"; require "copy";
# Temporary rule if true { # Forward a copy of all messages to gmail account redirect :copy "koshikov@gmail.com"; }
# File spam into spam folder and stop further processing if header :contains "X-spam" "yes" { fileinto "Spam"; stop; }
# Mailing list if header :contains "list-id" "ietf-mta-filters.imc.org" { fileinto "Lists.Sieve"; }
# Implicit keep will store message in INBOX if it was not # stored already by the fileinto commands above. The :copy # argument to the redirect command prevents that command # from cancelling the implicit keep action.
I hope this helps you along.
Regards,
-- Stephan Bosch stephan@rename-it.nl
On Thu, 30 Jul 2009 01:29:26 +0200 Stephan Bosch <stephan@rename-it.nl> wrote:
Thanks for your reply, Stephan.
I am not exactly sure what you mean. Why are you providing an explicit keep command when you want to sort the message further? I would think the following example script does what you need:
Without keep action - mail just redirected to specified mailbox, but it doesn't stores into my inbox.
== require "fileinto"; require "copy";
# Temporary rule if true { # Forward a copy of all messages to gmail account redirect :copy "koshikov@gmail.com"; }
# File spam into spam folder and stop further processing if header :contains "X-spam" "yes" { fileinto "Spam"; stop; }
# Mailing list if header :contains "list-id" "ietf-mta-filters.imc.org" { fileinto "Lists.Sieve"; }
# Implicit keep will store message in INBOX if it was not # stored already by the fileinto commands above. The :copy # argument to the redirect command prevents that command # from cancelling the implicit keep action.
I hope this helps you along.
This is my current rule list:
require ["fileinto","envelope","copy"]; # rule:[redirect] if anyof (true) { redirect :copy "alice@domain.com"; } # rule:[Cron] elsif anyof (header :contains "Subject" "Cron") { fileinto "INBOX/Cron"; }
Here is the message's headers: Return-path: <bob@domain.com> Envelope-to: koshikov.n@domain.com Delivery-date: Thu, 30 Jul 2009 10:29:04 +0300 Received: from [192.168.1.160] by mail.domain.com with ESMTPSA (TLSv1:AES256-SHA:256) id 1MWQ4W-0007bH-38 (envelope-from <bob@domain.com>) for koshikov.n@domain.com; Thu, 30 Jul 2009 10:29:04 +0300 Message-ID: <4A714B09.9030704@domain.com> Date: Thu, 30 Jul 2009 10:26:01 +0300 From: "bob@domain.com" <bob@domain.com> User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 To: =?UTF-8?B?0JrQvtGI0LjQutC+0LIg0J3QuNC60LjRgtCw?= <koshikov.n@domain.com> Subject: Cron Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit
test
But this mail save into INBOX, for user koshikov.n@domain.com, (the second rule is not working), in logs I have: Jul 30 10:29:04 deliver(koshikov.n@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: forwarded to <alice@domain.com> Jul 30 10:29:04 deliver(koshikov.n@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: stored mail into mailbox 'INBOX' Jul 30 10:29:04 deliver(alice@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: stored mail into mailbox 'INBOX'
So :copy acting for me like "keep". Do you have any ideas, why this might happen ?
Regards,
-- Stephan Bosch stephan@rename-it.nl
Nikita Koshikov schreef:
This is my current rule list:
require ["fileinto","envelope","copy"]; # rule:[redirect] if anyof (true) { redirect :copy "alice@domain.com"; } # rule:[Cron] elsif anyof (header :contains "Subject" "Cron") { fileinto "INBOX/Cron"; }
You are using a if/elseif/else statement. When the if clause (which is always true) is matched, the stuff in the elsif/else clauses is discarded.
You'll need to use 2 separate if statements to make this work.
-- Regards, Tom
On Thu, 30 Jul 2009 10:32:20 +0200 Tom Hendrikx <tom@whyscream.net> wrote:
You are using a if/elseif/else statement. When the if clause (which is always true) is matched, the stuff in the elsif/else clauses is discarded.
You'll need to use 2 separate if statements to make this work.
Thank you for explanation, Tom. Dividing rule list to two separate statements helped.
-- Regards, Tom
Nikita Koshikov schreef:
On Thu, 30 Jul 2009 01:29:26 +0200 Stephan Bosch <stephan@rename-it.nl> wrote:
I am not exactly sure what you mean. Why are you providing an explicit keep command when you want to sort the message further? Without keep action - mail just redirected to specified mailbox, but it doesn't stores into my inbox. [..] This is my current rule list:
require ["fileinto","envelope","copy"]; # rule:[redirect] if anyof (true) { redirect :copy "alice@domain.com"; } # rule:[Cron] elsif anyof (header :contains "Subject" "Cron") { fileinto "INBOX/Cron"; }
[..]
But this mail save into INBOX, for user koshikov.n@domain.com, (the second rule is not working), in logs I have: Jul 30 10:29:04 deliver(koshikov.n@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: forwarded to <alice@domain.com> Jul 30 10:29:04 deliver(koshikov.n@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: stored mail into mailbox 'INBOX' Jul 30 10:29:04 deliver(alice@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: stored mail into mailbox 'INBOX'
So :copy acting for me like "keep". Do you have any ideas, why this might happen ?
Yes, your second rule is an elsif, meaning that it is only executed when the first if-condition is not 'true'. Since that first rule has a forced 'true' result, the second rule is absolutely never executed. You script should be:
require ["fileinto","copy"];
# rule:[redirect] if true { redirect :copy "alice@domain.com"; }
# rule:[Cron] if header :contains "Subject" "Cron" { fileinto "INBOX/Cron"; }
Note that the anyof() commands are only necessary when you have multiple tests per if command. Also, I removed the envelope require, since it is not used.
Regards,
-- Stephan Bosch stephan@rename-it.nl
On Thu, 30 Jul 2009 10:38:51 +0200 Stephan Bosch <stephan@rename-it.nl> wrote:
Nikita Koshikov schreef:
On Thu, 30 Jul 2009 01:29:26 +0200 Stephan Bosch <stephan@rename-it.nl> wrote:
I am not exactly sure what you mean. Why are you providing an explicit keep command when you want to sort the message further? Without keep action - mail just redirected to specified mailbox, but it doesn't stores into my inbox. [..] This is my current rule list:
require ["fileinto","envelope","copy"]; # rule:[redirect] if anyof (true) { redirect :copy "alice@domain.com"; } # rule:[Cron] elsif anyof (header :contains "Subject" "Cron") { fileinto "INBOX/Cron"; }
[..]
But this mail save into INBOX, for user koshikov.n@domain.com, (the second rule is not working), in logs I have: Jul 30 10:29:04 deliver(koshikov.n@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: forwarded to <alice@domain.com> Jul 30 10:29:04 deliver(koshikov.n@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: stored mail into mailbox 'INBOX' Jul 30 10:29:04 deliver(alice@domain.com): Info: sieve: msgid=<4A714B09.9030704@domain.com>: stored mail into mailbox 'INBOX'
So :copy acting for me like "keep". Do you have any ideas, why this might happen ?
Yes, your second rule is an elsif, meaning that it is only executed when the first if-condition is not 'true'. Since that first rule has a forced 'true' result, the second rule is absolutely never executed. You script should be:
require ["fileinto","copy"];
# rule:[redirect] if true { redirect :copy "alice@domain.com"; }
# rule:[Cron] if header :contains "Subject" "Cron" { fileinto "INBOX/Cron"; }
Note that the anyof() commands are only necessary when you have multiple tests per if command. Also, I removed the envelope require, since it is not used.
Thank you, Stephan. Your example rules works like a charm.
Regards,
-- Stephan Bosch stephan@rename-it.nl
Stephan Bosch <stephan@rename-it.nl> writes:
Yes, your second rule is an elsif, meaning that it is only executed when the first if-condition is not 'true'. Since that first rule has a forced true' result, the second rule is absolutely never executed. You script should be:
require ["fileinto","copy"];
# rule:[redirect] if true { redirect :copy "alice@domain.com"; }
# rule:[Cron] if header :contains "Subject" "Cron" { fileinto "INBOX/Cron"; }
Note that the anyof() commands are only necessary when you have multiple tests per if command. Also, I removed the envelope require, since it is not used.
Out of interest is the conditional around
if true
{
redirect :copy "alice@domain.com";
}
necessary? Does a plain inline
redirect :copy "alice@domain.com";
not behave in exactly the same manner?
I'm afraid it's a while since I read RFC 5228 (Sieve) and I was unfamiliar with RFC 3894 (:copy) but on scanning through them I can't see anything to indicate that behaviour should differ inside and outside an "if".
So I suppose my question is does "redirect :copy" have different behaviour based on whether it is inline or inside an "if"?
pod wrote:
Note that the anyof() commands are only necessary when you have multiple tests per if command. Also, I removed the envelope require, since it is not used.
Out of interest is the conditional around
if true { redirect :copy "alice@domain.com"; }
necessary? Does a plain inline
redirect :copy "alice@domain.com";
not behave in exactly the same manner? These are identical. Some people (or rather their GUI-based editors) use unconditional if-statements to temporarily disable/enable certain sections of a script.
By the looks of it, this was generated by the sieverules plugin for the RoundCube webmail client. In this case it looks more like a limitation of the script generator, meaning that it doesn't omit the if statement when the rule is unconditional.
Other than that, the if true {...} statement is completely useless and adds nothing to the semantics of the script.
I'm afraid it's a while since I read RFC 5228 (Sieve) and I was unfamiliar with RFC 3894 (:copy) but on scanning through them I can't see anything to indicate that behaviour should differ inside and outside an "if".
So I suppose my question is does "redirect :copy" have different behaviour based on whether it is inline or inside an "if"? Conclusion: no.
Regards,
Stephan.
participants (4)
-
Nikita Koshikov
-
pod
-
Stephan Bosch
-
Tom Hendrikx