There is a :count
match type (like :is
and :contains
, etc.) in the "relational" extension you can use with the :comparator
comparator to do this, and in fact your use-case is the standard example for it!
If you're using Dovecot Pigeonhole (used by many package solutions and providers like RoundCube, FastMail, and others), the "relational" extension comes with it, you just have to require it (and its comparator; see below) at the top of your sieve file with your others. The sieve filter should look the same no matter what implementation you're using, as long as the extensions are supported.
IANA maintains the master list of official extensions. If you use Dovecot Pigeonhole Sieve, scroll down to "Implementation Status" on its Github to see which ones are supported there (all are, most completely). This means you don't have to search to find the "relational" extension.
Note that while :comparator
is supported by the base install (of Dovecot's implementation), it doesn't include numerical comparison by default and the collation itself is an extension that must be required specificially.
require [..., "relational","comparator-i;ascii-numeric"]
# ...
# reject if the number of recipient addresses is greater than 1
if allof(
address :domain ["to","cc"] "example.com",
address :count "gt" :comparator "i;ascii-numeric" ["to","cc"] "1"){
# if you really want it destroyed
# discard;
fileinto :create "Trash"; stop;
}
I did some tests and the filter will combine the counts of TO & CC (but not BCC) for the comparison, so it applies to the total number of (visible) recipient addresses.
RFC 5228: Sieve
RFC 5231: Relational Extension