Skip to content

Commit

Permalink
Merge branch 'ingo-x-spam-header' of https://github.com/atj/horde
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Oct 2, 2017
2 parents ce39da0 + 5b60b1c commit 0a6d0d2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
6 changes: 6 additions & 0 deletions ingo/config/conf.xml
Expand Up @@ -39,6 +39,12 @@
"*", then "****" in the header indicates a spam level
of four.">*</configstring>
</case>
<case name="boolean" desc="Boolean">
<configstring name="header" desc="The spam header to
check">X-Spam</configstring>
<configstring name="value" desc="The value of the spam header when a mail
is identified as spam.">Yes</configstring>
</case>
</configswitch>
</configsection>
</configuration>
4 changes: 4 additions & 0 deletions ingo/lib/Factory/Script.php
Expand Up @@ -86,6 +86,10 @@ public function create($rule)
($params['spam_compare'] == 'string')) {
$params['spam_char'] = $conf['spam']['char'];
}
if (!isset($params['spam_value']) &&
($params['spam_compare'] == 'boolean')) {
$params['spam_value'] = $conf['spam']['value'];
}

switch ($driver) {
case 'Imap':
Expand Down
22 changes: 13 additions & 9 deletions ingo/lib/Form/Spam.php
Expand Up @@ -30,17 +30,21 @@ class Ingo_Form_Spam extends Ingo_Form_Base

public function __construct($vars, $title = '', $name = null)
{
global $conf;

parent::__construct($vars, $title, $name);

$v = $this->addVariable(
_("Spam Level:"),
'level',
'int',
true,
false,
_("Messages with a likely spam score greater than or equal to this number will be treated as spam.")
);
$v->setHelp('spam-level');
if ($conf['spam']['compare'] != 'boolean') {
$v = $this->addVariable(
_("Spam Level:"),
'level',
'int',
true,
false,
_("Messages with a likely spam score greater than or equal to this number will be treated as spam.")
);
$v->setHelp('spam-level');
}

$this->folder_var = $this->addVariable(
_("Folder to receive spam:"),
Expand Down
6 changes: 6 additions & 0 deletions ingo/lib/Script/Maildrop.php
Expand Up @@ -358,6 +358,12 @@ protected function _generateSpam(Ingo_Rule $rule)
$rule->level
)
));
} elseif ($this->_params['spam_compare'] == 'boolean') {
$recipe->addCondition(array(
'match' => 'is',
'field' => $this->_params['spam_header'],
'value' => $this->_params['spam_value']
));
}

$this->_addItem(Ingo::RULE_SPAM, $recipe);
Expand Down
8 changes: 8 additions & 0 deletions ingo/lib/Script/Sieve.php
Expand Up @@ -467,6 +467,14 @@ protected function _addSpamBlocks(Ingo_Rule $rule)
'comparator' => 'i;ascii-casemap',
);
$test = new Ingo_Script_Sieve_Test_Header($vals);
} elseif ($this->_params['spam_compare'] == 'boolean') {
$vals = array(
'headers' => $this->_params['spam_header'],
'match-type' => ':is',
'strings' => $this->_params['spam_value'],
'comparator' => 'i;ascii-casemap',
);
$test = new Ingo_Script_Sieve_Test_Header($vals);
}

$actions[] = new Ingo_Script_Sieve_Action_Stop();
Expand Down

0 comments on commit 0a6d0d2

Please sign in to comment.