Sieve-filter email with ambiguous message content

46 views Asked by At

From an external monitoring service I receive emails with message bodies containing random amounts of warnings:

foo
warning X
bar
warning X
...

Or:

warning X
warning Y
foo
warning X
bar
warning Z
...

Warning X is irrelevant, but all other warnings are important. X is a known type - all others can be anything.

If an email contains only warning X lines, I can safely trash it. The sieve script would be straightforward:

if body :contains "warning X" {
      fileinto :create "INBOX.Trash";
}

However, when a message contains warning X and other warnings, the script would trash the message and I would miss all other warnings in it, which is unacceptable.

How can I discard all messages that exclusively contain warnings of type X?


If I had regex I could check for something like "warning [^X]", but so far I am unable to find any way to express this in sieve.

The next thing that came to mind was comparing the amount of occurrences of "warning X" against just "warning ". If they were equal, it would mean that every warning was in fact of type X. However, the :count expression doesn't seem to work on message bodies and also seems to only compare against hard-coded integers.

1

There are 1 answers

0
user569825 On

Shortly after posting the question I realized that I do have regex:

require ["body", "fileinto", "mailbox", "regex"];

if not body :regex "warning [^X]" {
    fileinto :create "INBOX.Trash";
}

This script appears to have the desired effect.