Search code examples
sieve-language

Sieve randomly assigns mails to folders


I'm using sieve rules like the following to sort logs from normal mails:

require ["fileinto", "envelope", "subaddress", "variables", "mailbox"];
# rule:[asdf-logs]
if anyof (address "From" "[email protected]", address "From" "[email protected]", address "To" "[email protected]")
{
    fileinto "INBOX.asdf.logs";
}
# rule:[asdf]
if anyof (header :contains "Delivered-To" "[email protected]", header :contains "cc" "[email protected]", header :contains "to" "[email protected]")
{
    fileinto "INBOX.asdf";
}

Now, if some mail is sent from [email protected] to [email protected], the following two results are possible:

filing message into 'INBOX.asdf.logs'
filing message into 'INBOX.asdf'

My problem is that the mail will be sorted randomly into asdf or asdf.logs. How can I solve this?


Solution

  • You're looking for the "stop" command.

    if anyof (address "From" "[email protected]", address "From" "[email protected]", address "To" "[email protected]")
    {
        fileinto "INBOX.asdf.logs";
        stop;
    }
    

    Most commands, including "fileinto", don't inherently stop processing. Further rules will be processed and matched unless you explicitly execute a "stop" command. In general, once you're sure you have a message filed where you want it to go, you probably want to run stop; so that no further portions of the sieve script are run.