2

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!

tripleee
  • 175,061
  • 34
  • 275
  • 318
Donald T
  • 10,234
  • 17
  • 63
  • 91
  • 1
    Directory deliveries do not require or support locking; you should lose the second colon from `:0:`. It's not clear why you would want to prevent concurrent access to SpamAssassin, either, but perhaps you have a particular reason. – tripleee Jul 27 '12 at 14:47
  • Those particular settings were recommended in a template from my host, WebFaction. I don't know what they mean myself. – Donald T Jul 27 '12 at 17:51
  • Well, if your Procmail log file contains "lock file ignored" warnings, that's why. If SpamAssassin is used by a large number of users with Bayes etc data in a shared database, *maybe* locking might help avoid congestion, but this lock file is per-user so I doubt it's genuinely useful (and if they have scalability problems, why aren't they using the spamd/spamc wrappers). – tripleee Jul 28 '12 at 06:31

1 Answers1

3

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318