Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Apr 2005
    Posts
    246

    Lightbulb Email filtering wisdom needed!

    Hi, two question:

    1. How do I bounce email from a specific sender? Not "fail" (which bounces email from an entire email address) and not "discard" (which doesn't bounce at all)...I remember long ago there used to be a command "::bounce::". It doesn't work anymore? Do I need to muck around with the EXIM filter file for this?

    2. Secondly, if I set up a filter to send all incoming email to a PHP program, how does that work? How does PHP get the values from email, with "$_GET" variables?

    Many thanks!!

  2. #2
    Member Stefaans's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, Canada
    Posts
    445

    Default

    1. How do I bounce email from a specific sender? Not "fail" (which bounces email from an entire email address) and not "discard" (which doesn't bounce at all)...I remember long ago there used to be a command "::bounce::". It doesn't work anymore? Do I need to muck around with the EXIM filter file for this?
    I stand to be corrected, but do not think the Exim Filter specification mentions a command to bounce emails. You could possibly achieve the effect with an autoresponse as follows:

    Edit your filter file at /etc/valiase/yourdomain.com
    Code:
    if $sender_address matches person@otherdomain.com then
    mail to $sender_address
    subject "Undeliverable email"
    expand file /home/username/bounce.msg
    file $home/vacation/messageendif
    In the above /home/username/bounce.msg is a file that contains the body of the bounce message. Be aware of the fact that the filter file will be overwritten when you use the cPanel Mail Filters command. I have not tested the above, so please use with caution


    Code:
    2. Secondly, if I set up a filter to send all incoming email to a PHP program, how does that work? How does PHP get the values from email, with "$_GET" variables?
    No, $_GET will not work. You have to decode the message and look at the MIME parts. Using the PEAR MAIL package (http://pear.php.net/packages.php?catpid=14&catname=Mail) is an easy way of doing this

  3. #3
    Member
    Join Date
    Apr 2005
    Posts
    246

    Default

    Thanks Stefaans.

    About bouncing. That file doesn't exist. Is the path correct "/etc/valiase/mydomain.com"? Or should I create a new one to put that code in it?

    Thanks also for info about grabbing text from incoming mail. Is there any specific part of that MAIL pear package that I need to look at? I find the PEAR library in general quite a bloated one (which serves the purpose it is meant for, I guess) so I wouldn't want to install the whole thing.

    Thanks!

  4. #4
    Member Stefaans's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, Canada
    Posts
    445

    Default

    That file doesn't exist. Is the path correct "/etc/valiase/mydomain.com"? Or should I create a new one to put that code in it?
    Typo alart! The file resides in /etc/valiases/ (I missed an "s"). If you do not have such a file, simply add a filter in cPanel. You will then have the file in /etc/valiases that you can overwrite as neeeded.

    Is there any specific part of that MAIL pear package that I need to look at? I find the PEAR library in general quite a bloated one (which serves the purpose it is meant for, I guess) so I wouldn't want to install the whole thing.
    Maybe it's bloated, maybe it's just very comprehensive. It's a matter of opinion The PEAR packages are generally small smiles; it will not really hurt of you install a few packages that you do not really need.

    Mail_mimeDecode is the package you want to use. Below is an example; it is an abstract from an actual script we use. I do not suggest that it is the best way of doing things or that the script is complete. Please test and use at your own risk

    PHP Code:
    // Mail_mimeDecode example by Stephen @ ANNO
    // Read the piped message
    $pipe fopen('php://stdin''r');
    while (!
    feof($pipe)) {
        
    $buffer fgets($pipe4096);
        
    $input.= $buffer;
    }
    fclose($pipe);

    // DeMIME with Pear packages
    $params['include_bodies'] = true;
    $params['decode_bodies'] = true;
    $params['decode_headers'] = true;
    $params['input'] = $input;
    $structure Mail_mimeDecode::decode($params);

    // Message headers
    $mail_from strip_address($structure->headers['from']);
    $mail_return strip_address($structure->headers['return-path']);
    $mail_to strip_address($structure->headers['to']);
    $mail_date $structure->headers['date'];
    $mail_delivered $structure->headers['delivery-date'];
    $mail_subject $structure->headers['subject'];

    // Check message format
    if ( ($structure->ctype_primary=='text') and ($structure->ctype_secondary=='plain') )
        
    $mail_body $structure->body;
    elseif (isset(
    $structure->parts)) { // HTML email; get plain text part
        
    foreach ($structure->parts as $part) {
            if ( (isset(
    $part->body)) and ($part->ctype_primary=="text") and ($part->ctype_secondary=="plain") )
            
    $mail_body $part->body;
        }  
    // end foreach
    }  // end elseif 
    To pipe the email into this script, set up forwarder for the relevant email address to
    Code:
    |/usr/bin/php -q /home/username/pipescript.php >/dev/null 2>&1

  5. #5
    Member
    Join Date
    Apr 2005
    Posts
    246

    Default

    Quote Originally Posted by Stefaans View Post
    Typo alart! The file resides in /etc/valiases/ (I missed an "s"). If you do not have such a file, simply add a filter in cPanel. You will then have the file in /etc/valiases that you can overwrite as neeeded.
    Thanks so much for this. But it isn't working. The code I have is this:

    Code:
    if $sender_address matches NAME.SURNAME@gmail.com then
    mail to $sender_address
    subject "Undeliverable email"
    expand file /home/MYDOMAIN/bounce.msg
    file $home/vacation/message
    endif
    
    abuse@MYDOMAIN.com: NAME.LASTNAME@gmail.com
    access@MYDOMAIN.com: NAME.LASTNAME@gmail.com
    ....long list of these....
    I've masked the names and such for this public forum, but is this the basic way to enter the information into that valiases file? Or should I place the code elsewhere?

    Thanks so much also for the mimedecode class, will look for it and pester you with questions when I do

  6. #6
    Member Stefaans's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, Canada
    Posts
    445

    Default

    I have dabbled with the Exim filters, but do not think I am an expert. Be cautious taking my advice

    It seems like I am guilty of yet another typo! The line "file $home/vacation/message" should not be there. Try:
    Code:
    if $sender_address matches NAME.SURNAME@gmail.com then
      mail to $sender_address
      subject "Undeliverable email"
      expand file /home/MYDOMAIN/bounce.msg
    endif
    I notice now (did not see it before) that the Exim Filter Spec mentions a fail command. The following may possible be a much simpler solution:
    Code:
    if $sender_address matches NAME.SURNAME@gmail.com then
      fail "Undeliverable emai"
    endif
    Something I should have mentioned before, is that errors in your filter file could mess up delivery of all email to your domain. So, perhaps a good idea to clear/delete /etc/vfilters/MYDOMAIN, and edit and test an "offline" filter file first.

    You can test your filter as follows:
    Code:
    exim -bf filterfile <email_message
    where filterfile is the Exim filter file you are editing, and email_message is a test email message stored somewhere on your server, e.g. /home/username/mail/MYDOMAIN/test/new/1233blah_blah

    And then, once you are happy with the results, copy the filter file to /etc/vfilters/MYDOMAIN.

Similar Threads & Tags
Similar threads

  1. Replies: 11
    Last Post: 05-11-2012, 12:38 PM
  2. Email Filtering
    By frankfer in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 08-27-2007, 09:37 AM
  3. Email filtering
    By oeriksen in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 10-31-2006, 03:53 PM
  4. Email filtering
    By h8r in forum E-mail Discussions
    Replies: 4
    Last Post: 04-16-2006, 03:18 PM
  5. Email Filtering
    By TBucketMan in forum E-mail Discussions
    Replies: 3
    Last Post: 12-30-2004, 02:06 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube