最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Continue processing more email filter rules after "Pipe to Program" completes? - Stack Overflow

programmeradmin0浏览0评论

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);.

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);.

Share Improve this question edited Feb 2 at 18:55 DarkBee 15.6k8 gold badges72 silver badges117 bronze badges asked Feb 2 at 16:42 HippoManHippoMan 2,3282 gold badges26 silver badges56 bronze badges 2
  • Please re-read my message. I made it clear in what I wrote that the problem still occurs even when there is no analyzer and when the filter is a no-op which only does an exit(0);. – HippoMan Commented Feb 2 at 18:10
  • Sure, but an exit(0); would have eaten up all input as well (good test btw.). But I was under the wrong impression anyway that it could forward via stdout, but it's more a sink and you have to forward each message from within your script then. I'll update the answer. Sorry for the confusion. – hakre Commented Feb 2 at 18:22
Add a comment  | 

2 Answers 2

Reset to default 0

How can my "Pipe to Program" filter specify that email filtering and processing must continue normally after the "Pipe to Program" filter completes successfully?

You can't. The moment you forward to the program (pipe to program), the program has the responsibility to handle the processing of the message.

As corrected, standard output is getting bounced, so forwarding via standard output is not an option.


No idea if your cPanel allows you to configure this, but from Exim's own documentation, it may be possible by prefixing the pipe command with unseen.

From Exim Filter Specification - Significant deliveries (exim.):

The delivery commands "deliver", "save", and "pipe" are by default significant.

However, if such a command is preceded by the word "unseen", then its delivery is not considered to be significant.

You have to check though if controlling this by Significant Deliveries is an option for your overall setup.

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.

发布评论

评论列表(0)

  1. 暂无评论