> Its a PHP simple script:
>
> #!/usr/bin/php
> <?php
> print_r("action=PERMIT\n\n");
> ?>
As Wietse stated, the policy server is designed to be recycled to avoid a
script start up expense for each email. I created this in PHP before deciding
to use a milter instead. Here is an example of how i was able to get PHP to
process multiple emails before exiting the script.
#!/usr/bin/php
<?php
#
# Install Script At
# /usr/libexec/postfix/<POLICY_SCRIPT_NAME>
#
# Postfix Creates Socket At
# /var/spool/postfix/private/<POLICY_SERVICE_NAME>
#
# master.cf:
# <POLICY_SERVICE_NAME> unix - n n - 0 spawn user=<LINUX_USER>
argv=/usr/libexec/postfix/<POLICY_SCRIPT_NAME>
#
# main.cf:
# <POLICY_SERVICE_NAME>_time_limit = 3600
# smtpd_recipient_restrictions =
# check_policy_service unix:private/<POLICY_SERVICE_NAME>
#
set_time_limit(0);
ignore_user_abort(true);
stream_set_timeout(STDIN, 30);
while (true) {
$buffer = array();
while (true) {
$line = trim(fgets(STDIN));
if (connection_status() == 1) exit(0);
if ($line == "") break;
$key = "";
$value = "";
if (strpos($line, "=")) list($key, $value) = explode("=",
$line, 2);
if ($key) $buffer[$key] = $value;
}
processInput($buffer);
unset($buffer);
}
function allow () {
echo "action=dunno" . PHP_EOL;
echo PHP_EOL;
return null;
}
function reject ($reason = "Policy Violation") {
echo "action=550 $reason" . PHP_EOL;
echo PHP_EOL;
return null;
}
function noreply () {
echo PHP_EOL;
return null;
}
function processInput (&$buffer) {
if (count($buffer) < 1) return noreply();
# Example To Reject
if (isset($buffer['recipient']) && $buffer['recipient'] ==
"[email protected]") return reject("User not accepting email.");
# Accept Email
return allow();
}
?>