Sieve: Filter Rules

I want to implement a rule as follows:

  • If "To" comprises only addresses having "*@example.com" -> discard
  • Otherwise -> keep

In other words:

  • If "To" comprises at least one address different to "*@example.com" -> keep
  • Otherwise -> discard

The problem with the statement if not header :contains "To" "@example.com" { keep; } else { discard;} is that a mail is not kept if there is a "*@example.com" address among other non-"*@example.com" addresses.

What I would need is an option to negate the search pattern rather than the complete statement, e.g.: if header :contains "To" NOT "@example.com" { keep; } else { discard;}

Any ideas how to solve this?


This works:

require "regex";
if header :regex "to" "@[^(example.com)]+" { keep; } else { discard; }