Postfix content filter how to block domain name?

Discussion in 'General' started by lonerunner, Oct 1, 2022.

  1. lonerunner

    lonerunner Member

    Lately I am getting lot of mails with a spam that links to specific phishing website, and I tried a few different regex patterns to block the mails that contains the link to that website but I am failing in blocking the mails.

    The email content is just some generic stuff like:

    So my guess is, this should fall into regex pattern for Body Filter to block any email that contain `domainname.tld` in the email weather it is in a link or just a text, as long as email content contain that domain name, block the email.

    The settings should be in ISPConfig control panel Email > Server settings > Content Filter And just add Regex pattern under Body Filter option I guess?
    But I am failing with the pattern i guess. Can someone help me out with the pattern example please ?
     
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    lonerunner and x-myrza like this.
  3. lonerunner

    lonerunner Member

    I did read exactly this tutorial and helped me block some spam emails but in this case I am failing to block when domain name is in content.
    I know I need to use body filter instead of header filter and regex should be something simple but in this case it's not working, the emails keep coming through.
     

    Attached Files:

  4. pyte

    pyte Well-Known Member HowtoForge Supporter

    You could try:
    Code:
    /^(?:https?:\/\/)?(?:[^.]+\.)?telegra\.ph(\/.*)?$/i
    This will match any of these case insensitive(see the 'i' at the end so "tElEgR.Ph" is valid to):
    Code:
    https://telegra.ph
    http://telegra.ph
    http://www.telegra.ph
    https://www.telegra.ph
    www.telegra.ph
    telegra.ph
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    And one thing that might affect the effectiveness of a regex on the email body is that the regex is run on the raw body content of the email by postfix (at least as far as I know), emails can be encoded in various ways that might cause a regex to not match. So using a mailbox filter instead (which is run by dovecot and not postfix) might be worthy a try, if the suggestions from @pyte about improving the regex do not help.
     
  6. pyte

    pyte Well-Known Member HowtoForge Supporter

    The statement of till is correct. If the mail is Base64 encoded for example your regex has to match that Base64 to match.
    I don't know your setup, but for filtering content i would use rspamd with a multimap content filter.

    You can test your regex with postfix with this:
    Code:
    cat badmail.eml | postmap -v -b -q - pcre:/path/to/contentfilter.pcre
    
    This will give you verbose output, if a line matches or not.
     
    till likes this.

Share This Page