doujing5846 2010-09-09 04:45
浏览 67
已采纳

PHP邮件过滤脚本:.qmail文件中无法识别退出代码

Short story

I've got a PHP script filtering incoming mail using a .qmail file. The script works perfectly well and logs all activity but, as far as I know, the last .qmail line shouldn't be executed when my script returns a dot-qmail exit code 99 that should stop processing further .qmail lines.

Long story:

I'm using a Parallels Plesk Panel version 9.3.0 under Linux 2.6.18-4-686.

My PHP CLI version is 5.2.0-8+etch16 (cli) (built: Nov 24 2009 11:14:47).

Not satisfied with Spamassassin, Dr. Web and zen.spamhaus.org and their results, I decided to create my own PHP script for filtering all incoming mail.

(An aside to some of you who might think "this guy is reinventing the wheel": I know my customers personally and their specific needs so, after thousands of tests, this turned out to be the best option because it avoids black box models and lets me control the process in a comprehensive way, also freeing server resources and opening doors to other cool functionality).

However I'm having a hard time installing the script at the server.

qmailfilter is my script and you can see it at http://titanpad.com/1IFDj1jvB0

I edited an existing .qmail file in /var/qmail/mailnames/customerdomain.com/username/.qmail to be:

|/var/my/qmailfilter/qmailfilter
|/usr/bin/deliverquota ./Maildir

qmailfilter PHP script executes and logs perfectly when I send a message to this user account, returns the exit code (99 for discarding message and 0 for proceeding to next .qmail line delivering the message).

Turns out that it delivers the message irrespectively of the many exit codes I've already tried.

The script (see line 174) outputs a text exit code without any whitespace before or after. I tried exit($code), print $code, echo($code) and even file_put_contents("php://stdout", $code), and also exit(chr($code)).

dot-qmail codes are:

0 - Success (go to next .qmail line)

99 - Success and abort (do not execute next lines)

100 - permanent error (bounce)

111 - soft error (retry later)

Source: The Big Qmail Picture.

Other attempts/experiments:

  1. Removed the shebang line (#!/usr/bin/php) and changed the first .qmail line to |php -q /var/my/qmailfilter/qmailfilter

  2. Checked the last line of the script for whitespacing

  3. Read dot-qmail man file but nothing conclusive was found

  4. Joined .qmail lines:

    |/var/my/qmailfilter/qmailfilter |/usr/bin/deliverquota ./Maildir

In this case I got a message having only the proper return code without any header, subject or message body.

  1. Commented out (#) the second .qmail line, but stopped receiving any kind of messages.

  2. Edited /var/qmail/control/defaultdelivery to add a first line:

    |php /var/my/qmailfilter/qmailfilter |/usr/bin/deliverquota ./Maildir

and renamed user .qmail file to _qmail. Same results.

Should I deliver the message via PHP script and forget exit codes?

If so, is it enough to save the message to the user Maildir/new?

If so, is the message filename important?

Any idea will be appreciated. Thanks very much!

UPDATE: For those of you who need it, I published the final script at icebex.com slash qmailfilter

  • 写回答

1条回答 默认 最新

  • dotibrb048760 2010-09-09 04:51
    关注

    I only took a quick look at the code, but it looked like you were using string values. exit('99') and exit(99) are not the same. Make sure you use integers and not strings.

    • exit('99') will print 99 and return 0.

    • exit(99) will return 99.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题