Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top