Question

Using procmail, I want to move any incoming mail that does not contain my name ("John Doe") in the "To" field to the "Junk" folder.

However, the following rule does not seem to have any effect, even though I have tested the regular expression thoroughly in online testing apps to ensure it matches what it should:

# Filter spam if the name "John Doe" is not in "To"
:0:
* ^(?!To:.*John\sDoe).*
.Junk/

In case it is of interest, my entire procmail rule file is:

# Filter mail using SpamAssassin
:0fw: spamassassin.lock
* < 256000
| /usr/bin/spamassassin

# Filter spam based on "Spam-Level"
:0:
* ^X-Spam-Level: \*\*
.Junk/

# Filter spam if the name "John Doe" is not in "To"
:0:
* ^(?!To:.*John\sDoe).*
.Junk/

Why doesn't my rule work?

Thank you for any assistance!

Was it helpful?

Solution

Because Perl lookaheads are not part of Procmail's regex repertoire.

Try this instead.

:0
* ! ^To:.*John[  ]+Doe
.Junk/

The whitespace inside [ ] should be a space and a tab; the \s Perlism isn't supported, either.

You might be better off using your email address as the filtering criterion, and perhaps using the ^TO_ special macro to cover Cc: etc. You still cannot handle Bcc: to your account, of course.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top