PHP mail filtering script: exit codes not recognized in .qmail file

safaksaracoglu

New Member
Short storyI'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/1IFDj1jvB0I edited an existing .qmail file in \[code\]/var/qmail/mailnames/customerdomain.com/username/.qmail\[/code\] to be:\[code\]|/var/my/qmailfilter/qmailfilter|/usr/bin/deliverquota ./Maildir\[/code\]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 \[code\]exit($code)\[/code\], \[code\]print $code\[/code\], \[code\]echo($code)\[/code\] and even \[code\]file_put_contents("php://stdout", $code)\[/code\], and also \[code\]exit(chr($code))\[/code\].\[code\]dot-qmail\[/code\] 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:[*]Removed the shebang line (\[code\]#!/usr/bin/php\[/code\]) and changed the first \[code\].qmail\[/code\] line to \[code\]|php -q /var/my/qmailfilter/qmailfilter\[/code\][*]Checked the last line of the script for whitespacing[*]Read dot-qmail man file but nothing conclusive was found[*]Joined .qmail lines:|/var/my/qmailfilter/qmailfilter |/usr/bin/deliverquota ./MaildirIn this case I got a message having only the proper return code without any header, subject or message body.[*]Commented out (#) the second \[code\].qmail\[/code\] line, but stopped receiving any kind of messages.[*]Edited \[code\]/var/qmail/control/defaultdelivery\[/code\] to add a first line:|php /var/my/qmailfilter/qmailfilter|/usr/bin/deliverquota ./Maildirand renamed user \[code\].qmail\[/code\] file to \[code\]_qmail\[/code\]. 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
 
Back
Top