* @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 .= '

'.$val.''; $out .= '
'. ''; foreach($this->settings['spamrule_tests'][$module]['values'] as $res=>$res_desc) { $out .= '
'. ''; } } return $out; } /** * Main function that outputs a form for editing a whole rule. * * @param int $edit Number of rule that editing is based on. * @return string */ function edit_rule($edit = false) { global $PHP_SELF, $color, $avelsieve_maintypes, $spamrule_actions, $data_dir, $username, $plugins, $junkfolder_days; $out = '

'; $out .= ''. ""; if($this->mode == 'edit') { /* 'edit' */ $out .= ''. $this->table_header( sprintf( _("Editing %s"), (sprintf(_("(Rule #%s)"), ($edit+1))) )); } else { /* 'duplicate' or 'addnew' */ $out .= $this->table_header( sprintf(_("Add a new %s "), $avelsieve_maintypes[$this->rule['type']]['desc']) ); } $out .= $this->all_sections_start(). $this->section_start( _("Configure Anti-SPAM Protection") ). '

' . _("All incoming mail is checked for unsolicited commercial content (SPAM) and marked accordingly. This special rule allows you to configure what to do with such messages once they arrive to your Inbox.") . '

'; /* ---------- Error (or other) Message, if it exists -------- */ $out .= $this->print_errmsg(); if(!$this->spamrule_advanced) { // FIXME string $out .= '

'. sprintf( _("Select %s to add the predefined rule, or select the advanced SPAM filter to customize the rule."), '' . _("Add Spam Rule") . '' ) . '

'. '

'; } else { /* include_once(SM_PATH . 'plugins/filters/filters.php'); $spamfilters = load_spam_filters(); */ $out .= ''. ''; } if(isset($junkprune_saveme)) { $out .= ''; } /* STOP */ $out .= '
useimages) { $out .= ''. _( '; } else { $out .= ""._("STOP").": "; } $out .= _("If this rule matches, do not check any rules after it."). ''. $this->section_end(); /* --------------------- buttons ----------------------- */ $out .= $this->submit_buttons(). '
'. $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; } } }