public addCondition ( array $condition = [] ) | ||
$condition | array | Array of parameters. Required keys are 'field' and 'value'. 'case' is an optional key. |
public function addCondition($condition = array())
{
$flag = !empty($condition['case']) ? 'D' : '';
$match = isset($condition['match']) ? $condition['match'] : null;
$string = '';
$prefix = '';
switch ($condition['field']) {
case 'Destination':
$string = '^TO_';
break;
case 'Body':
$flag .= 'B';
break;
default:
// convert 'field' to PCRE pattern matching
if (!strpos($condition['field'], ',')) {
$string = '^' . $condition['field'] . ':';
} else {
$string .= '^(' . str_replace(',', '|', $condition['field']) . '):';
}
$prefix = ' ';
}
$reverseCondition = false;
switch ($match) {
case 'regex':
$string .= $prefix . $condition['value'];
break;
case 'address':
$string .= '(.*\\<)?' . preg_quote($condition['value']);
break;
case 'not begins with':
$reverseCondition = true;
// fall through
// fall through
case 'begins with':
$string .= $prefix . preg_quote($condition['value']);
break;
case 'not ends with':
$reverseCondition = true;
// fall through
// fall through
case 'ends with':
$string .= '.*' . preg_quote($condition['value']) . '$';
break;
case 'not contain':
$reverseCondition = true;
// fall through
// fall through
case 'contains':
default:
$string .= '.*' . preg_quote($condition['value']);
break;
}
$this->_conditions[] = array('condition' => ($reverseCondition ? '* !' : '* ') . $string, 'flags' => $flag);
}
/** * Generates the procmail script to handle the whitelist specified in * the rules. * * @param Ingo_Rule $rule Rule object. */ protected function _generateWhitelist(Ingo_Rule $rule) { if (!count($rule)) { return; } $this->_addItem(Ingo::RULE_WHITELIST, new Ingo_Script_Procmail_Comment(_("Whitelisted Addresses"), $rule->disable, true)); foreach ($rule->addresses as $address) { $recipe = new Ingo_Script_Procmail_Recipe(array('action' => 'Ingo_Rule_User_Keep', 'disable' => $rule->disable), $this->_params); $recipe->addCondition(array('field' => 'From', 'value' => $address, 'match' => 'address')); $this->_addItem(Ingo::RULE_WHITELIST, $recipe); } }