The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Email filters - filter on CC and BCC?

Discussion in 'E-mail Discussions' started by webignition, Feb 7, 2005.

  1. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    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. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    Ok, silly me for having my brain turned off this morning.

    Email filters using regular expression matching do the trick.
     
  3. GeoffJarvis

    GeoffJarvis Registered

    Joined:
    Mar 15, 2005
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    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. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    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. GeoffJarvis

    GeoffJarvis Registered

    Joined:
    Mar 15, 2005
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    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
     
    #5 GeoffJarvis, Mar 16, 2005
    Last edited: Mar 17, 2005
  6. uksteve

    uksteve Registered

    Joined:
    Oct 22, 2003
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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. uksteve

    uksteve Registered

    Joined:
    Oct 22, 2003
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    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 ... :)
     
Loading...

Share This Page