* @copyright 2004-2007 Alexandros Vellis
* @package plugins
* @subpackage avelsieve
*/
/** Includes */
include_once(SM_PATH . 'plugins/avelsieve/include/html_main.inc.php');
include_once(SM_PATH . 'plugins/avelsieve/include/html_ruleedit.inc.php');
include_once(SM_PATH . 'plugins/avelsieve/include/sieve_rule_spam.inc.php');
/**
* Rule #10: Customized Anti-SPAM rule (original version)
*
* @package plugins
* @subpackage avelsieve
*/
class avelsieve_html_edit_10 extends avelsieve_html_edit_spamrule {
/**
* Constructor, that just calls the parent one.
*/
function avelsieve_html_edit_10(&$s, $mode = 'edit', $rule = array(), $popup = false, $errmsg = '') {
global $avelsieve_rules_settings;
$this->settings = $avelsieve_rules_settings[10];
$this->avelsieve_html_edit($s, $mode, $rule, $popup, $errmsg);
}
/**
* Spamrule module settings
*
* @return string
*/
function module_settings($module) {
$out = '';
foreach($this->settings['spamrule_tests'][$module]['available'] as $key=>$val) {
$out .= '
'.
$this->all_sections_end().
$this->table_footer() . '';
return $out;
}
/**
* Process HTML submission from namespace $ns (usually $_POST),
* and put the resulting rule structure in $this->rule class variable.
*
* @param array $ns
* @param array $rule
* @return void
*/
function process_input(&$ns, $unused = false, $validate = true) {
global $startitems;
if(isset($ns['intermediate_action']['spamrule_switch_to_advanced'])) {
// Just switched to advanced.
$this->spamrule_advanced = true;
$this->rule['advanced'] = 1;
} elseif(isset($ns['spamrule_advanced'])) {
$this->spamrule_advanced = true;
$this->rule['advanced'] = 1;
} elseif (isset($edit) && isset($this->rule['advanced'])) {
$this->spamrule_advanced = true; // FIXME
$this->rule['advanced'] = 1;
} else {
$this->spamrule_advanced = false;
$this->rule['advanced'] = 0;
}
/* Spam Rule variables */
/* If we need to get spamrule RBLs from LDAP, then do so now. */
if(isset($_SESSION['spamrule_rbls'])) {
$spamrule_rbls = $_SESSION['spamrule_rbls'];
} elseif(isset($this->settings['spamrule_tests_ldap']) && $this->settings['spamrule_tests_ldap'] == true &&
!isset($_SESSION['spamrule_rbls'])) {
include_once(SM_PATH . 'plugins/avelsieve/include/spamrule.inc.php');
$spamrule_rbls = avelsieve_askldapforrbls();
$_SESSION['spamrule_rbls'] = $spamrule_rbls;
}
if(isset($ns['tests'])) {
$tests = $ns['tests'];
} elseif (isset($edit) && isset($this->rule['tests'])) {
$tests = $this->rule['tests'];
} else {
$tests = array_keys($this->settings['spamrule_tests']);
}
if(isset($ns['score'])) {
$score = $ns['score'];
} elseif (isset($edit) && isset($this->rule['score'])) {
$score = $this->rule['score'];
} else {
$score = $this->settings['spamrule_score_default'];
}
/* Whitelist number of items to display */
if(isset($ns['whitelistitems'])) {
$this->whitelistitems = $ns['whitelistitems'];
} elseif (isset($edit) && isset($this->rule['whitelist'])) {
$this->whitelistitems = sizeof($this->rule['whitelist']) + 1;
} else {
$this->whitelistitems = $startitems;
}
if(isset($ns['whitelist_add'])) {
$this->whitelistitems++;
}
/* The actual whitelist */
if(isset($ns['whitelist_add']) || isset($ns['apply'])) {
$j=0;
for($i=0; $i< $this->whitelistitems; $i++) {
if(!empty($ns['cond'][$i]['headermatch'])) {
$whitelist[$j]['header'] = $ns['cond'][$i]['header'];
$whitelist[$j]['matchtype'] = $ns['cond'][$i]['matchtype'];
$whitelist[$j]['headermatch'] = $ns['cond'][$i]['headermatch'];
$j++;
}
}
} elseif (isset($edit) && isset($this->rule['whitelist'])) {
$whitelist = $this->rule['whitelist'];
}
if(isset($ns['action'])) {
$action = $ns['action'];
} elseif (isset($edit) && isset($this->rule['action'])) {
$action = $this->rule['action'];
} else {
$action = $this->settings['spamrule_action_default'];
}
if(isset($ns['stop'])) {
$stop = 1;
} elseif (isset($edit) && isset($this->rule['stop']) && !isset($ns['apply'])) {
$stop = $this->rule['stop'];
} else {
$stop = 1;
}
/* After all that story, now overwrite the variables of the rule. */
$this->rule['type'] = 10;
$this->rule['tests'] = $tests;
$this->rule['score'] = $score;
$this->rule['action'] = $action;
if(isset($whitelist)) {
$this->rule['whitelist'] = $whitelist;
}
if($this->spamrule_advanced) {
$this->rule['advanced'] = 1;
}
if(isset($stop) && $stop) {
$this->rule['stop'] = $stop;
}
}
}