public function __construct($params = array(), $scriptparams = array())
{
$this->_disable = !empty($params['disable']);
$this->_params = $scriptparams;
$this->_action[] = 'exception {';
switch ($params['action']) {
case 'Ingo_Rule_User_Keep':
$this->_action[] = ' to "${DEFAULT}"';
break;
case 'Ingo_Rule_User_Move':
$this->_action[] = ' to ' . $this->maildropPath($params['action-value']);
break;
case 'Ingo_Rule_User_Discard':
$this->_action[] = ' exit';
break;
case 'Ingo_Rule_User_Redirect':
$this->_action[] = ' to "! ' . $params['action-value'] . '"';
break;
case 'Ingo_Rule_User_RedirectKeep':
$this->_action[] = ' cc "! ' . $params['action-value'] . '"';
$this->_action[] = ' to "${DEFAULT}"';
break;
case 'Ingo_Rule_User_Reject':
// EX_NOPERM (permanent failure)
$this->_action[] = ' EXITCODE=77';
$this->_action[] = ' echo "5.7.1 ' . $params['action-value'] . '"';
$this->_action[] = ' exit';
break;
case 'Ingo_Rule_System_Vacation':
$from = reset($params['action-value']['addresses']);
/* Exclusion of addresses from vacation */
if ($params['action-value']['excludes']) {
$exclude = implode('|', $params['action-value']['excludes']);
// Disable wildcard until officially supported.
// $exclude = str_replace('*', '(.*)', $exclude);
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^From:.*(' . $exclude . ')/'));
}
$start = strftime($params['action-value']['start']);
if ($start === false) {
$start = 0;
}
$end = strftime($params['action-value']['end']);
if ($end === false) {
$end = 0;
}
$days = strftime($params['action-value']['days']);
if ($days === false) {
// Set to same value as $_days in ingo/lib/Storage.php
$days = 7;
}
// Rule : Do not send responses to bulk or list messages
if ($params['action-value']['ignorelist'] == 1) {
$params['combine'] = Ingo_Rule_User::COMBINE_ALL;
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Precedence: (bulk|list|junk)/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Return-Path:.*<#@\\[\\]>/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Return-Path:.*<>/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^From:.*MAILER-DAEMON/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^X-ClamAV-Notice-Flag: *YES/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Content-Type:.*message\\/delivery-status/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Subject:.*Delivery Status Notification/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Subject:.*Undelivered Mail Returned to Sender/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Subject:.*Delivery failure/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Subject:.*Message delay/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Subject:.*Mail Delivery Subsystem/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^Subject:.*Mail System Error.*Returned Mail/'));
$this->addCondition(array('match' => 'filter', 'field' => '', 'value' => '! /^X-Spam-Flag: YES/ '));
} else {
$this->addCondition(array('field' => 'From', 'value' => ''));
}
// Rule : Start/End of vacation
if ($start != 0 && $end !== 0) {
$this->_action[] = ' flock "$HOME/vacationprocess.lock" {';
$this->_action[] = ' current_time=time';
$this->_action[] = ' if ( \\ ';
$this->_action[] = ' ($current_time >= ' . $start . ') && \\ ';
$this->_action[] = ' ($current_time <= ' . $end . ')) ';
$this->_action[] = ' {';
}
$this->_action[] = ' cc "' . str_replace('"', '\\"', sprintf('| mailbot %s -D %d -c \'UTF-8\' -t $HOME/vacation.msg -d $HOME/vacation -A %s -s %s /usr/sbin/sendmail -t -f %s', $this->_params['mailbotargs'], $params['action-value']['days'], escapeshellarg('From: ' . $from), escapeshellarg(Horde_Mime::encode($params['action-value']['subject'])), escapeshellarg($from))) . '"';
if ($start != 0 && $end !== 0) {
$this->_action[] = ' }';
$this->_action[] = ' }';
}
break;
case 'Ingo_Rule_System_Forward':
case Ingo_Script_Maildrop::MAILDROP_STORAGE_ACTION_STOREANDFORWARD:
foreach ($params['action-value'] as $address) {
if (!empty($address)) {
$this->_action[] = ' cc "! ' . $address . '"';
}
}
/* The 'to' must be the last action, because maildrop
* stops processing after it. */
if ($params['action'] == Ingo_Script_Maildrop::MAILDROP_STORAGE_ACTION_STOREANDFORWARD) {
$this->_action[] = ' to "${DEFAULT}"';
} else {
$this->_action[] = ' exit';
}
break;
default:
$this->_valid = false;
break;
}
$this->_action[] = '}';
if (isset($params['combine']) && $params['combine'] == Ingo_Rule_User::COMBINE_ALL) {
$this->_combine = '&& ';
} else {
$this->_combine = '|| ';
}
}