Search code examples
phpemailfiltercpanel

Continue processing more email filter rules after "Pipe to Program" completes?


I'm using cPanel's Global Filters to manage my email delivery at my hosting site.

Additionally, I want to use "Pipe to Program" to analyze the contents of incoming messages, log information about each email to a file ... and then (and this is the part I'm having problems with!) to continue passing all the incoming mails to the other Global Filters.

I wrote a "Pipe to Program" filter and installed it as my first Global Filter.

It correctly runs for each incoming email, and it correctly analyzes each message and correctly logs the results to a file.

However, after this "Pipe to Program" filter runs, no other Global Filters are applied to the incoming message, and the message does not get delivered to its designated recipient. And no bounce back to the sender is generated.

Here is the structure of the "Pipe to Program" filter:

#!/usr/bin/php -q
<?php

/*** PHP code exists here, instead of this comment,
     to analyze incoming mail from STDIN, and then
     to write analysis results to the log file. ***/

exit(0);
?>

This is in a file with 755 permissions, and it runs with no problems: i.e., the email analysis is always properly calculated and logged. But no futher Global Filters are run, and the email does not get delivered to the recipient, and the email is not bounced back to the sender.

Instead of the above, I even tried the following "Pipe to Program" executable as the first Global Email filter:

#!/usr/bin/php -q
<?php
exit(0);
?>

This also results in the same problem: no message is bounced back to the sender, and further Global Filters do not get run, and the messages do not get delivered to the recipient.

If I delete this one initial Global Filter, then all emails are processed normally, which means that all my other Global Filters are correct.

How can my "Pipe to Program" filter specify that email filtering and processing must continue normally after the "Pipe to Program" filter completes successfully? Keep in mind (as you can see above) that I always make sure to terminate the "Pipe to Program" code with exit(0);.


Solution

  • Based on the feedback here (and thank you!) and based on some other approaches that I have also tested, I now understand that "Pipe to Program" and "Forward email" cPanel email filters are unable to pass their input on to further filters. The cPanel "Pipe to Program" and "Forward email" filters eat up the message, and no other subsequent email filtering or processing takes place.

    Re-emailing the incoming message from the "Pipe to Program" filter is not an option for my particular use case.

    So, I see now that I'm totally out of luck with this approach.

    UPDATE: I think I might be able to get the message-analysis-and-logging functionality as follows:

    Use the cPanel "Deliver to folder" filter as my first filter, and have it deliver a copy of the message to a special folder. I believe that this filter rule does indeed allow the email to be passed on to subsequent filters.

    Then, outside of the hosting and cPanel environment, run a cron job from my home computer to periodically query that special folder via IMAP, to perform the message analysis and logging, and then to delete all those message copies from the special folder.

    I'm relatively certain that this would work.

    FURTHER UPDATE: Nope, I'm wrong. The "Deliver to folder" filter also will not pass the message to further filters. So, I am now defintely certain that I am totally out of luck with this.