Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Jan 2005
    Posts
    1,880

    Default Email filters - filter on CC and BCC?

    I'd like to know if the email filters in Cpanel can be set to filter on more headers.

    I'm setting up a PHP script to deal with emails sent to support@domain. The script works fine but I need to be able to set up further filters.

    I began by setting up a filter to pipe mail to the PHP script where the "To" field contained "support@domain". This works wonderfully.

    I also need to set up filters so that mail with "support@domain" gets piped if it is in the CC or BCC fields.

    I know that I can choose to set up a filter with the option "Any header" but this is not proving too useful, as an email addressed to "support@domain" is likely to have the string "support@domain" present more than once in the entire headers, meaning that with such a filter mail addressed to support@domain normally gets passed on to the PHP script twice.

    I tried manually editing the .filter file in /home/accountusername/ from:

    Code:
    $header_to: contains "support@domain"+++++++|/home/accountusername/path/to/script.php
    to

    Code:
    $header_cc: contains "support@domain"+++++++|/home/accountusername/path/to/script.php
    and even

    Code:
    $header_cc: contains "support@domain"+++++++|/home/accountusername/path/to/script.php
    $header_to: contains "support@domain"+++++++|/home/accountusername/path/to/script.php
    But this fails to filter mail on the CC header and obviously isn't the right thing to do.

    Any idea how I can filter mail specifically on the CC and BCC fields?

  2. #2
    Member
    Join Date
    Jan 2005
    Posts
    1,880

    Default

    Ok, silly me for having my brain turned off this morning.

    Email filters using regular expression matching do the trick.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    2

    Default So how do you get CC to be filtered

    Bump how do you do this?

    any bcc and cc filters seemed to be ignored.

  4. #4
    Member
    Join Date
    Jan 2005
    Posts
    1,880

    Default

    To filter on headers that are not specifically listed in the relevant drop-down menu, you will need to perform a regular expression match on all headers.

    When adding a new filter:

    Filter [Any Header] that [matches regex] [your regular expression]
    Destination [your destination]

    So to filter on Cc: or Bcc: fields, your regular expression would have to contain a reference to the Cc: or Bcc: field.

    To get this to work correctly, you will need a good understanding or both the structure of email headers and how to form regular expressions.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    2

    Default Seems ok

    Hi

    Thanks for the reply after much head scratching and trying a few things this seems to work well
    in the .filter file

    $h_cc:,$h_to:,$h_bcc: matches ".*\myname@mailbox.com"+++++++me@home.com
    Last edited by GeoffJarvis; 03-17-2005 at 02:05 AM.

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    Default

    Quote Originally Posted by webignition
    To filter on headers that are not specifically listed in the relevant drop-down menu, you will need to perform a regular expression match on all headers.

    When adding a new filter:

    Filter [Any Header] that [matches regex] [your regular expression]
    Destination [your destination]

    So to filter on Cc: or Bcc: fields, your regular expression would have to contain a reference to the Cc: or Bcc: field.

    To get this to work correctly, you will need a good understanding or both the structure of email headers and how to form regular expressions.
    I'm trying to setup a filter that works on Envelope-to:, but this method doesn't work. I think that the match regex only uses the regex to match the content of the header, and not the header itself.

    This is so fundamental! You must be able to filter on Envelope-to: otherwise mailing list, spam, etc will not be filtered.

    The regex I have used is of the form :-

    ^Envelope-to: .user.*\@domain

    The intention is to redirect all mail with the Envelope-to: user part beginning with "user"

    If I use $ to denote the end of string, I get an error when I test it (I think it is trying to expand it to a variable).

    Incidently guys, there is no such thing as a bcc: header! in RFC822. The whole point of Bcc is that it is blind. Your mail transport will strip it out of the outgoing mail and add the recipient in the Bcc field to the list of recipients.

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    3

    Default

    Quote Originally Posted by uksteve
    I'm trying to setup a filter that works on Envelope-to:
    Replying to my own post! After digging around in some Exim mans, now realize that you can edit the .filter file via cPanel FileManager (don't have shell access).

    I think that Envelope-to: isn't present when the filter runs... So have used the Received: header instead :-

    Code:
    $h_Received matches "for user.*@domain\.com"+++++++user@domain.com
    seems to do the trick! Exim writes a Received header, so this filter finds the for user@domain in that. The regexp could be tweaked for whitespace around the "for", but it's always a space, isn't it ...

Similar Threads & Tags
Similar threads

  1. Email filters to take effect before the email forwarders
    By jpratt in forum Feature Requests for cPanel/WHM
    Replies: 0
    Last Post: 01-21-2011, 10:41 AM
  2. Replies: 3
    Last Post: 03-17-2009, 07:01 AM
  3. Adding Bcc headers into specific email accounts on server side.
    By ramprage in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 08-11-2006, 10:40 PM
  4. email to large bcc list get rejected
    By fweikeong in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 04-18-2006, 10:00 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube