简体   繁体   中英

Filter email by containing my name in “To” using procmail

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM