';
$out .= '';
// FIXME What does the type have to do in here?
$out .= '';
if(true || $items > 1) {
$out .= '';
}
if(true || $items < $maxitems) {
$out .= '';
}
return $out;
}
/**
* Output HTML code for header match rule.
*
* @param int $n Number of current condition (index of 'cond' array)
* @return string
*/
function condition_header($n) {
$header = $matchtype = $headermatch = $index = $index_last = '';
if(isset($this->rule['cond'][$n]['header'])) {
$header = $this->rule['cond'][$n]['header'];
}
if(isset($this->rule['cond'][$n]['matchtype'])) {
$matchtype = $this->rule['cond'][$n]['matchtype'];
}
if(isset($this->rule['cond'][$n]['headermatch'])) {
$headermatch = $this->rule['cond'][$n]['headermatch'];
}
if($this->s->capability_exists('index')) {
if(isset($this->rule['cond'][$n]['index'])) {
$index = $this->rule['cond'][$n]['index'];
}
if(isset($this->rule['cond'][$n]['index_last'])) {
$index_last = $this->rule['cond'][$n]['index_last'];
}
}
$out = $this->header_listbox($header, $n) .
($this->s->capability_exists('index') ? $this->index_option($n, $index, $index_last) : '') .
$this->matchtype_listbox($matchtype, $n) .
'';
return $out;
}
/**
* Output HTML code for address match rule.
*
* @param int $n Number of current condition (index of 'cond' array)
* @return string
*/
function condition_address($n) {
if(isset($this->rule['cond'][$n]['address'])) {
$address = $this->rule['cond'][$n]['address'];
} else {
$address = '';
}
if(isset($this->rule['cond'][$n]['matchtype'])) {
$matchtype = $this->rule['cond'][$n]['matchtype'];
} else {
$matchtype = '';
}
if(isset($this->rule['cond'][$n]['addressmatch'])) {
$addressmatch = $this->rule['cond'][$n]['addressmatch'];
} else {
$addressmatch = '';
}
$out = $this->address_listbox($address, $n) .
$this->matchtype_listbox($matchtype, $n) .
'';
return $out;
}
/**
* Output HTML code for envelope match rule.
*
* @param int $n Number of current condition (index of 'cond' array)
* @return string
*/
function condition_envelope($n) {
if(isset($this->rule['cond'][$n]['envelope'])) {
$envelope = $this->rule['cond'][$n]['envelope'];
} else {
$envelope = '';
}
if(isset($this->rule['cond'][$n]['matchtype'])) {
$matchtype = $this->rule['cond'][$n]['matchtype'];
} else {
$matchtype = '';
}
if(isset($this->rule['cond'][$n]['envelopematch'])) {
$envelopematch = $this->rule['cond'][$n]['envelopematch'];
} else {
$envelopematch = '';
}
$out = $this->envelope_listbox($envelope, $n) .
$this->matchtype_listbox($matchtype, $n) .
'';
return $out;
}
/**
* Size match
*
* @param int $n Number of current condition (index of 'cond' array)
* @return string
*/
function condition_size($n) {
if(isset($this->rule['cond'][$n]['sizerel'])) {
$sizerel = $this->rule['cond'][$n]['sizerel'];
} else {
$sizerel = 'bigger';
}
if(isset($this->rule['cond'][$n]['sizeamount'])) {
$sizeamount = $this->rule['cond'][$n]['sizeamount'];
} else {
$sizeamount = '';
}
if(isset($this->rule['cond'][$n]['sizeunit'])) {
$sizeunit = $this->rule['cond'][$n]['sizeunit'];
} else {
$sizeunit = 'kb';
}
// $out = '
'._("This rule will trigger if message is").
$out = '' .
_("than") .
' '.
'';
return $out;
}
/**
* Output HTML code for body match rule.
*
* @param int $n Number of current condition (index of 'cond' array)
* @return string
*/
function condition_body($n) {
if(isset($this->rule['cond'][$n]['matchtype'])) {
$matchtype = $this->rule['cond'][$n]['matchtype'];
} else {
$matchtype = '';
}
if(isset($this->rule['cond'][$n]['bodymatch'])) {
$bodymatch = $this->rule['cond'][$n]['bodymatch'];
} else {
$bodymatch = '';
}
$out = $this->matchtype_listbox($matchtype, $n) .
'';
return $out;
}
function condition_datetime($n) {
$myCondition = new avelsieve_condition_datetime($this->s, $this->rule, $n, 'date');
$out = $myCondition->datetime_header_ui();
$out .= $myCondition->datetime_common_ui();
return $out;
}
/**
* All messages
* @return string
* @obsolete
*/
function condition_all() {
$out = _("All Messages");
$dum = _("The following action will be applied to all incoming messages that do not match any of the previous rules.");
return $out;
}
/**
* Index
*
* @param string $selected
* @param string $last
* @return string
*/
function index_option($n, $selected, $last) {
$index_options = array(
'' => '',
'1' => _("1st"),
'2' => _("2nd"),
'3' => _("3rd"),
'4' => _("4th"),
'5' => _("5th"),
'6' => _("6th"),
'7' => _("7th"),
'8' => _("8th"),
'9' => _("9th"),
);
$index_last_options = array(
'' => '',
'1' => _("from the end"),
);
$out =
$this->generic_listbox('cond['.$n.'][index]', $index_options, $selected) .
$this->generic_listbox('cond['.$n.'][index_last]', $index_last_options, $last)
;
return $out;
}
/**
* Return the HTML markup of the options of Sieve action $action.
* This is a wrap around the relevant class of the Avelsieve action.
*
* If no such action exists, the function simply returns an empty
* string.
*
* @return string
*/
function action_html($action) {
$out = '';
$classname = 'avelsieve_action_'.$action;
if(class_exists($classname)) {
$$classname = new $classname($this->s, $this->rule);
if($$classname != null) {
if(AVELSIEVE_DEBUG >= 3 || $$classname->is_action_valid()) {
$out .= $$classname->action_html();
}
}
}
return $out;
}
/**
* Output available actions in a radio-button style.
* @return string
*/
function rule_3_action() {
/* Preferences from config.php */
global $translate_return_msgs;
/* Data taken from addrule.php */
global $boxes, $emailaddresses;
/* Other */
global $avelsieve_actions;
$out = '
'. _("Choose what to do when this rule triggers, from one of the following:"). '
';
foreach($avelsieve_actions as $action) {
$out .= $this->action_html($action);
}
return $out;
}
/**
* Output available *additional* actions (notify, stop etc.) in a
* checkbox-button style.
*
* @return string
*/
function rule_3_additional_actions() {
/* Preferences from config.php */
global $translate_return_msgs;
/* Data taken from addrule.php */
global $boxes, $emailaddresses;
/* Other */
global $additional_actions;
$out = '';
foreach($additional_actions as $action) {
$out .= $this->action_html($action);
}
return $out;
}
/**
* Submit buttons for edit form -- not applicable for wizard
* @return string
*/
function submit_buttons() {
$out = '
';
switch ($this->mode) {
case 'addnew':
$out .= '';
break;
case 'addnewspam':
$out .= '';
break;
case 'duplicate':
$out .= '';
$out .= '';
break;
case 'duplicatespam':
$out .= '';
$out .= '';
break;
case 'edit':
$out .= '';
break;
}
if($this->popup) {
$out .= ' ';
} else {
$out .= ' ';
}
return $out;
}
/**
* Output the HTML with the hidden input fields, for the referrer function.
* (After saving a rule or pressing "Cancel", the user is supposed to go
* back to where he was before).
*
* @return string
*/
function referrer_html() {
$out = '';
if(isset($this->referrerUrl)) {
$out .= '';
if(isset($this->referrerArgs) & !empty($this->referrerArgs)) {
$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.
*/
function edit_rule($edit = false) {
global $PHP_SELF, $color;
if($this->mode == 'edit') {
/* 'edit' */
$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.
*
* If any error happens, put a human-readable error message in
* $this->errmsg array, and return false. Otherwise, return true.
*
* @param array $ns
* @param boolean $truncate_empty_conditions
* @return boolean
*
* @todo Provide a better interface for $created_mailbox_name (creation
* of a folder on-the-spot, for various operations), instead of the
* current hack.
*/
function process_input(&$ns, $truncate_empty_conditions = false, $validate = true) {
/* Reset current rule, as it will be overwritten from input */
$this->rule = array();
/* Type is needed for later */
//if(isset($ns['type'])) $type = $ns['type'];
/* If Part */
$vars = array('type', 'condition');
if($truncate_empty_conditions && isset($ns['cond'])) {
/* Decide how much of the items to use for the condition of the
* rule, based on the first zero / null /undefined variable to be
* found. Also, reorder the conditions. */
$match_vars = array('headermatch', 'addressmatch', 'envelopematch', 'sizeamount', 'bodymatch', 'datetype');
$new_cond_indexes = array();
foreach($ns['cond'] as $n => $c) {
if(isset($c['kind'])) {
$kind = $c['kind'];
} else {
$kind = 'message';
}
switch($kind) {
case 'message':
foreach($match_vars as $m) {
if(!empty($c[$m]) || $c['type'] == 'all') {
$new_cond_indexes[] = $n;
}
}
$new_cond_indexes = array_unique($new_cond_indexes);
$new_cond_indexes = array_values($new_cond_indexes);
break;
case 'datetime':
default:
// TODO - for datetime, perform truncating / checking
$new_cond_indexes = array_keys($ns['cond']);
}
}
$this->rule['cond'] = array();
foreach($new_cond_indexes as $n => $index) {
$this->rule['cond'][] = $ns['cond'][$index];
}
/* If it is completely empty, we must return an error. */
if(empty($this->rule['cond'])) {
$this->errmsg[] = _("You have to define at least one condition.");
}
} else {
$vars[] = 'cond';
}
if(isset($ns['action'])) {
array_push($vars, 'action');
switch ($ns['action']) {
case "1": /* keep */
break;
case "2": /* discard */
break;
case "3": /* reject w/ excuse */
array_push($vars, 'excuse');
break;
case "4": /* redirect */
avelsieve_action_redirect::validate($ns, $this->errmsg);
array_push($vars, 'redirectemail', 'keep');
break;
case "5": /* fileinto */
array_push($vars, 'folder');
break;
case "6": /* vacation */
avelsieve_action_vacation::validate($ns, $this->errmsg);
array_push($vars, 'vac_addresses', 'vac_subject', 'vac_days', 'vac_message');
break;
default:
break;
}
} else {
/* User did not select anything from the radio buttons; default to
* 'keep' */
$this->rule['action'] = '1';
}
if(isset($ns['keepdeleted'])) {
$vars[] = 'keepdeleted';
}
if(isset($ns['stop'])) {
$vars[] = 'stop';
}
if(isset($ns['notify']['on']) && isset($ns['notify']['options']) &&
!empty($ns['notify']['options'])) {
$vars[] = 'notify';
}
if(isset($ns['imapflags']['on'])) {
$flagsOptions = array('setflag', 'addflag', 'removeflag', 'flags');
$flagsGroups = array('standard', 'labels');
foreach($flagsOptions as $O) {
if(!empty($ns['imapflags'][$O])) {
$this->rule['imapflags'][$O] = array();
// For the two groups ('standard', 'labels') that have checkboxes
foreach($ns['imapflags'][$O] as $k => $v) {
$this->rule['imapflags'][$O][base64_decode($k)] = 1;
}
}
}
// For the final group ('custom') that is free-form
if(!empty($ns['imapflags']['custom']) && !empty($ns['imapflags']['custom'][$O])) {
$input = trim($ns['imapflags']['custom'][$O]);
$flagsParsed = preg_split("/[\s,]+/", $input);
foreach($flagsParsed as $newflag) {
$this->rule['imapflags'][$O][$newflag] = 1;
}
}
}
if(isset($ns['disabled'])) {
$this->rule['disabled'] = 1;
}
/* Put all variables from the defined namespace (e.g. $_POST) in the rule
* array. */
foreach($vars as $myvar) {
if(isset($ns[$myvar])) {
$this->rule[$myvar]= $ns[$myvar];
}
}
/* Special hack for newly-created folder */
if(isset($this->rule['folder'])) {
global $created_mailbox_name;
if(!empty($created_mailbox_name)) {
$this->rule['folder'] = $created_mailbox_name;
}
}
/* For standard avelsieve rules > #10 */
/*
if(is_numeric($type) && $type >= 10) {
$class_name = 'avelsieve_html_edit_'.$type;
if(class_exists($class_name)) {
call_user_func(array($class_name, 'process_user_input'), array(&$ns, &$rule, &$this->errmsg));
}
}
*/
}
/**
* Return a customized "Rule has been successfully changed"-type message.
*
* Child classes may change this as they see fit.
*
* @return string
*/
function getSuccessMessage() {
return '';
}
}