Using cPanel Email Filter Wildcards

You can use wildcards in Spam Filters by using Regex. Providing a full breakdown of how Regex works is beyond the scope of this tutorial.

However, I will provide you with some basic examples to get you started:

Anchors - ^ and $

  • ^The - matches any string that starts with “The”
  • end$ - matches a string that ends with “end”
  • ^The end$ - exact string match
  • filtering - matches any string that has the text “filtering” in it

Quantifiers - *, +, ?, and {}

  • abc* - matches a string containing “ab” followed by “zero” or more “c”
  • abc+ - matches a string that has “ab” followed by one or more “c”
  • abc? - matches a string that has “ab” followed by zero or one “c”
  • abc{2} - matches a string that has “ab” followed by 2 “c”
  • abc{2,} - matches a string that has “ab” followed by 2 or more “c”
  • abc{2,5} - matches a string that has “ab” followed by 2 up to 5 “c”
  • a(bc)* - matches a string that has “a” followed by “zero” or more copies of the sequence “bc”
  • a(bc){2,5} - matches a string that has “a” followed by 2 up to 5 copies of the sequence “bc”

OR operator - | or []

  • a(b|c) - matches a string that has “a” followed by “b” or “c”
  • a[bc] - matches a string that has “a” followed by “b” or “c”

Grouping - ()

  • a(bc) - parentheses create a group with the value “bc”

For more detailed examples see this cheat sheet.

Example Email Filter using a Wildcard

Let’s take the example I used previously configuring a SpamAssassin filter that contained several rules. I can simplify the rules match field as follows:

Step 1: Go to the Filters menu

  • Click on the “Email Filters” or “Global Email Filters” icon on the cPanel dashboard.
    01

 

Step 2: Create new Email Filter

On this page, you will see a list of your current email filters. You will also be able to create a new filter for that email address.

  • Click the “Create a New Filter” button to create the new filter.
    02

 

Step 3: Enter the following filter settings

Enter the following settings:

  • Filter Name: Delete Spam with score 4 or below that does not contain SEO in body
  • Rule 1: “Spam Bar” “contains” “++++” AND
  • Rule 2: “Body” “does not contain” “SEO|seo”
  • Actions: Discard Message

You can use the “OR” operator in this instance because the rule is set to delete the message if the body does not contain “SEO” or “seo”. If any of those variations match then the message is NOT deleted.

03