/** */ protected function _init() { global $injector, $notification, $page_output; $this->_assertCategory(Ingo_Storage::ACTION_WHITELIST, _("Whitelist")); $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $whitelist = $ingo_storage->retrieve(Ingo_Storage::ACTION_WHITELIST); /* Token checking & perform requested actions. */ switch ($this->_checkToken(array('rule_update'))) { case 'rule_update': try { Ingo::updateListFilter($this->vars->whitelist, Ingo_Storage::ACTION_WHITELIST); $notification->push(_("Changes saved."), 'horde.success'); Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } break; } /* Get the whitelist rule. */ $wl_rule = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS)->findRule(Ingo_Storage::ACTION_WHITELIST); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/whitelist')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('Text'); $view->disabled = !empty($wl_rule['disable']); $view->formurl = $this->_addToken(self::url()); $view->whitelist = implode("\n", $whitelist->getWhitelist()); $page_output->addScriptFile('whitelist.js'); $page_output->addInlineJsVars(array('IngoWhitelist.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->title = _("Whitelist Edit"); $this->output = $view->render('whitelist'); }
/** */ protected function _init() { global $injector, $notification; /* Redirect if forward is not available. */ $this->_assertCategory(Ingo_Storage::ACTION_FORWARD, _("Forward")); if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Get the forward object and rule. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $forward = $ingo_storage->retrieve(Ingo_Storage::ACTION_FORWARD); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $fwd_id = $filters->findRuleId(Ingo_Storage::ACTION_FORWARD); $fwd_rule = $filters->getRule($fwd_id); /* Build form. */ $form = new Ingo_Form_Forward($this->vars); /* Perform requested actions. Ingo_Form_Forward does token checking * for us. */ if ($form->validate($this->vars)) { $forward->setForwardAddresses($this->vars->addresses); $forward->setForwardKeep($this->vars->keep_copy == 'on'); try { $ingo_storage->store($forward); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($fwd_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $fwd_rule['disable'] = false; } elseif ($this->vars->submitbutton == _("Save and Disable")) { $filters->ruleDisable($fwd_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $fwd_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($fwd_rule['disable']); /* Set default values. */ if (!$form->isSubmitted()) { $this->vars->keep_copy = $forward->getForwardKeep(); $this->vars->addresses = implode("\n", $forward->getForwardAddresses()); } /* Set form title. */ $form_title = _("Forward"); if (!empty($fwd_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'forward'); $form->setTitle($form_title); $this->header = _("Forwards Edit"); Horde::startBuffer(); $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))), $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** * AJAX action: Re-sort the filters list. * * Variables used: * - sort: (string) JSON serialized sort list of rule IDs. * * @return boolean True on success. */ public function reSortFilters() { global $injector, $notification; if (!Ingo::hasSharePermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); return false; } $storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $filters = $storage->retrieve(Ingo_Storage::ACTION_FILTERS); try { $filters->sort(json_decode($this->vars->sort)); $storage->store($filters); $notification->push(_("Rule sort saved successfully."), 'horde.success'); } catch (Ingo_Exception $e) { $notification->push(_("Rule sort not saved."), 'horde.error'); return false; } try { Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.warning'); } return true; }
/** */ protected function _init() { global $injector, $notification; $this->_assertCategory(Ingo_Storage::ACTION_SPAM, _("Spam filtering")); /* Get the spam object and rule. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $spam = $ingo_storage->retrieve(Ingo_Storage::ACTION_SPAM); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $spam_id = $filters->findRuleId(Ingo_Storage::ACTION_SPAM); $spam_rule = $filters->getRule($spam_id); if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Build form. */ $form = new Ingo_Form_Spam($this->vars); $renderer = new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))); /* Perform requested actions. Ingo_Form_Spam does token checking for * us .*/ if ($form->validate($this->vars)) { $success = false; try { $spam->setSpamFolder($this->validateMbox('folder')); $success = true; } catch (Horde_Exception $e) { $notification->push($e); } $spam->setSpamLevel($this->vars->level); try { $ingo_storage->store($spam); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($spam_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $spam_rule['disable'] = false; } elseif ($this->vars->submitbutton == _("Save and Disable")) { $filters->ruleDisable($spam_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $spam_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($spam_rule['disable']); /* Set default values. */ $form->folder_var->type->setFolder($spam->getSpamFolder()); if (!$form->isSubmitted()) { $this->vars->level = $spam->getSpamLevel(); $this->vars->folder = $spam->getSpamFolder(); $this->vars->actionID = ''; } /* Set form title. */ $form_title = _("Spam Filtering"); if (!empty($spam_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'spam'); $form->setTitle($form_title); $this->header = _("Spam Filtering"); Horde::startBuffer(); $form->renderActive($renderer, $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** */ protected function _init() { global $injector, $notification; $this->_assertCategory(Ingo_Storage::ACTION_VACATION, _("Vacation")); /* Get vacation object and rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $vacation = $ingo_storage->retrieve(Ingo_Storage::ACTION_VACATION); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $vac_id = $filters->findRuleId(Ingo_Storage::ACTION_VACATION); $vac_rule = $filters->getRule($vac_id); /* Load libraries. */ if ($this->vars->submitbutton == _("Return to Rules List")) { Ingo_Basic_Filters::url()->redirect(); } /* Build form. */ $form = new Ingo_Form_Vacation($this->vars, '', null, $injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_VACATION)->availableCategoryFeatures(Ingo_Storage::ACTION_VACATION)); /* Perform requested actions. Ingo_Form_Vacation does token checking * for us. */ if ($form->validate($this->vars)) { $form->getInfo($this->vars, $info); $vacation->setVacationAddresses(isset($info['addresses']) ? $info['addresses'] : ''); $vacation->setVacationDays($info['days']); $vacation->setVacationExcludes($info['excludes']); $vacation->setVacationIgnorelist($info['ignorelist'] == 'on'); $vacation->setVacationReason($info['reason']); $vacation->setVacationSubject($info['subject']); $vacation->setVacationStart($info['start']); $vacation->setVacationEnd($info['end']); try { $ingo_storage->store($vacation); $notification->push(_("Changes saved."), 'horde.success'); if ($this->vars->submitbutton == _("Save and Enable")) { $filters->ruleEnable($vac_id); $ingo_storage->store($filters); $notification->push(_("Rule Enabled"), 'horde.success'); $vac_rule['disable'] = false; } elseif ($this->vars->get('submitbutton') == _("Save and Disable")) { $filters->ruleDisable($vac_id); $ingo_storage->store($filters); $notification->push(_("Rule Disabled"), 'horde.success'); $vac_rule['disable'] = true; } Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e); } } /* Add buttons depending on the above actions. */ $form->setCustomButtons($vac_rule['disable']); /* Make sure we have at least one address. */ if (!$vacation->getVacationAddresses()) { $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create(); $addresses = implode("\n", $identity->getAll('from_addr')); /* Remove empty lines. */ $addresses = trim(preg_replace('/\\n+/', "\n", $addresses)); if (empty($addresses)) { $addresses = $GLOBALS['registry']->getAuth(); } $vacation->setVacationAddresses($addresses); } /* Set default values. */ if (!$form->isSubmitted()) { $this->vars->set('addresses', implode("\n", $vacation->getVacationAddresses())); $this->vars->set('excludes', implode("\n", $vacation->getVacationExcludes())); $this->vars->set('ignorelist', $vacation->getVacationIgnorelist()); $this->vars->set('days', $vacation->getVacationDays()); $this->vars->set('subject', $vacation->getVacationSubject()); $this->vars->set('reason', $vacation->getVacationReason()); $this->vars->set('start', $vacation->getVacationStart()); $this->vars->set('end', $vacation->getVacationEnd()); $this->vars->set('start_year', $vacation->getVacationStartYear()); $this->vars->set('start_month', $vacation->getVacationStartMonth() - 1); $this->vars->set('start_day', $vacation->getVacationStartDay() - 1); $this->vars->set('end_year', $vacation->getVacationEndYear()); $this->vars->set('end_month', $vacation->getVacationEndMonth() - 1); $this->vars->set('end_day', $vacation->getVacationEndDay() - 1); } /* Set form title. */ $form_title = _("Vacation"); if (!empty($vac_rule['disable'])) { $form_title .= ' [<span class="horde-form-error">' . _("Disabled") . '</span>]'; } $form_title .= ' ' . Horde_Help::link('ingo', 'vacation'); $form->setTitle($form_title); $this->header = _("Vacation Edit"); Horde::startBuffer(); $form->renderActive(new Horde_Form_Renderer(array('encode_title' => false, 'varrenderer_driver' => array('ingo', 'ingo'))), $this->vars, self::url(), 'post'); $this->output = Horde::endBuffer(); }
/** */ protected function _init() { global $injector, $notification, $page_output; $this->_assertCategory(Ingo_Storage::ACTION_BLACKLIST, _("Blacklist")); $ingo_script = $injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_BLACKLIST); $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $flagonly = $ingo_script && in_array(Ingo_Storage::ACTION_FLAGONLY, $ingo_script->availableActions()); /* Token checking & perform requested actions. */ switch ($this->_checkToken(array('rule_update'))) { case 'rule_update': switch ($this->vars->action) { case 'delete': $folder = ''; break; case 'mark': $folder = Ingo::BLACKLIST_MARKER; break; case 'folder': $folder = $this->validateMbox('actionvalue'); break; default: $folder = null; break; } if (!$flagonly && $folder == Ingo::BLACKLIST_MARKER) { $notification->push("Not supported by this script generator.", 'horde.error'); } else { try { $blacklist = Ingo::updateListFilter($this->vars->blacklist, Ingo_Storage::ACTION_BLACKLIST); $blacklist->setBlacklistFolder($folder); $ingo_storage->store($blacklist); $notification->push(_("Changes saved."), 'horde.success'); Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e->getMessage(), $e->getCode()); } } break; } /* Get the blacklist object. */ if (!isset($blacklist)) { try { $blacklist = $ingo_storage->retrieve(Ingo_Storage::ACTION_BLACKLIST); } catch (Ingo_Exception $e) { $notification->push($e); $blacklist = new Ingo_Storage_Blacklist(); } } /* Create the folder listing. */ $blacklist_folder = $blacklist->getBlacklistFolder(); $folder_list = Ingo_Flist::select($blacklist_folder, 'actionvalue'); /* Get the blacklist rule. */ $bl_rule = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS)->findRule(Ingo_Storage::ACTION_BLACKLIST); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/blacklist')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->addHelper('Text'); $view->blacklist = implode("\n", $blacklist->getBlacklist()); $view->disabled = !empty($bl_rule['disable']); $view->flagonly = $flagonly; $view->folder = $blacklist_folder; $view->folderlist = $folder_list; $view->formurl = $this->_addToken(self::url()); $page_output->addScriptFile('blacklist.js'); $page_output->addInlineJsVars(array('IngoBlacklist.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->header = _("Blacklist Edit"); $this->output = $view->render('blacklist'); }
/** */ protected function _vacationCode() { $code = 'vacation :days ' . $this->_vars['days'] . ' '; $addresses = $this->_vars['addresses']; $stringlist = ''; if (count($addresses) > 1) { foreach ($addresses as $address) { $address = trim($address); if (!empty($address)) { $stringlist .= empty($stringlist) ? '"' : ', "'; $stringlist .= Ingo_Script_Sieve::escapeString($address) . '"'; } } $stringlist = "[" . $stringlist . "] "; } elseif (count($addresses) == 1) { $stringlist = '"' . Ingo_Script_Sieve::escapeString($addresses[0]) . '" '; } if (!empty($stringlist)) { $code .= ':addresses ' . $stringlist; } if (!empty($this->_vars['subject'])) { $code .= ':subject "' . Horde_Mime::encode(Ingo_Script_Sieve::escapeString($this->_vars['subject'])) . '" '; } return $code . '"' . Ingo_Script_Sieve::escapeString(Ingo_Script_Util::vacationReason($this->_vars['reason'], $this->_vars['start'], $this->_vars['end'])) . '";'; }
/** */ protected function _init() { global $conf, $injector, $notification, $page_output; /* Check rule permissions. */ $max = $injector->getInstance('Horde_Core_Perms')->hasAppPermission(Ingo_Perms::getPerm('max_rules')); if ($max === 0) { Horde::permissionDeniedError('ingo', 'allow_rules', _("You are not allowed to create or edit custom rules.")); Ingo_Basic_Filters::url()->redirect(); } if (!Ingo::hasSharePermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } /* Load the Ingo_Script:: driver. */ $ingo_script = $injector->getInstance('Ingo_Factory_Script')->create(Ingo::RULE_FILTER); /* Redirect if no rules are available. */ $availActions = $ingo_script->availableActions(); if (empty($availActions)) { $notification->push(_("Individual rules are not supported in the current filtering driver."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } /* This provides the $ingo_fields array. */ $config = new Horde_Registry_LoadConfig('ingo', 'fields.php', 'ingo_fields'); $ingo_fields = $config->config['ingo_fields']; /* Get the current rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); if ($this->_assertMaxRules($max, $filters)) { Ingo_Basic_Filters::url()->redirect(); } /* Token checking. */ $actionID = $this->_checkToken(array('rule_save', 'rule_delete')); /* Update the current rules before performing any action. */ if (isset($this->vars->action)) { $rule = array('action' => $this->vars->action, 'combine' => $this->vars->combine, 'conditions' => array(), 'flags' => 0, 'id' => $this->vars->id, 'name' => $this->vars->name, 'stop' => $this->vars->stop); } else { $rule = isset($this->vars->edit) ? $filters->getRule($this->vars->edit) : $filters->getDefaultRule(); } if (!$rule) { $notification->push(_("Filter not found."), 'horde.error'); Ingo_Basic_Filters::url()->redirect(); } if ($ingo_script->hasFeature('case_sensitive')) { $casesensitive = $this->vars->case; } foreach (array_filter(isset($this->vars->field) ? $this->vars->field : array()) as $key => $val) { $condition = array(); $f_label = null; if ($val == Ingo::USER_HEADER) { $condition['field'] = empty($this->vars->userheader[$key]) ? '' : $this->vars->userheader[$key]; $condition['type'] = Ingo_Storage::TYPE_HEADER; } elseif (!isset($ingo_fields[$val])) { $condition['field'] = $val; $condition['type'] = Ingo_Storage::TYPE_HEADER; } else { $condition['field'] = $val; $f_label = $ingo_fields[$val]['label']; $condition['type'] = $ingo_fields[$val]['type']; } $condition['match'] = isset($this->vars->match[$key]) ? $this->vars->match[$key] : ''; if ($actionID == 'rule_save' && empty($this->vars->value[$key]) && !in_array($condition['match'], array('exists', 'not exist'))) { $notification->push(sprintf(_("You cannot create empty conditions. Please fill in a value for \"%s\"."), is_null($f_label) ? $condition['field'] : $f_label), 'horde.error'); $actionID = null; } $condition['value'] = isset($this->vars->value[$key]) ? $this->vars->value[$key] : ''; if (isset($casesensitive)) { $condition['case'] = isset($casesensitive[$key]) ? $casesensitive[$key] : ''; } $rule['conditions'][] = $condition; } if ($this->vars->action) { switch ($ingo_storage->getActionInfo($this->vars->action)->type) { case 'folder': if ($actionID == 'rule_save') { try { $rule['action-value'] = $this->validateMbox('actionvalue'); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); $actionID = null; } } else { $rule['action-value'] = $this->vars->actionvalue; if (!$this->vars->actionvalue && isset($this->vars->actionvalue_new)) { $page_output->addInlineScript(array('IngoNewFolder.setNewFolder("actionvalue", ' . Horde_Serialize::serialize($this->vars->actionvalue_new, Horde_Serialize::JSON) . ')'), true); } } break; default: $rule['action-value'] = $this->vars->actionvalue; break; } } $flags = empty($this->vars->flags) ? array() : $this->vars->flags; foreach ($flags as $val) { $rule['flags'] |= $val; } /* Run through action handlers. */ switch ($actionID) { case 'rule_save': if (empty($rule['conditions'])) { $notification->push(_("You need to select at least one field to match."), 'horde.error'); break; } if (!isset($this->vars->edit)) { if ($this->_assertMaxRules($max, $filters)) { break; } $filters->addRule($rule); } else { $filters->updateRule($rule, $this->vars->edit); } $ingo_storage->store($filters); $notification->push(_("Changes saved."), 'horde.success'); try { Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); } Ingo_Basic_Filters::url()->redirect(); case 'rule_delete': if (isset($this->vars->conditionnumber)) { unset($rule['conditions'][intval($this->vars->conditionnumber)]); $rule['conditions'] = array_values($rule['conditions']); } break; } /* Add new, blank condition. */ $rule['conditions'][] = array(); /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/rule')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->addHelper('Text'); $view->avail_types = $ingo_script->availableTypes(); $view->edit = $this->vars->edit; $view->fields = $ingo_fields; $view->formurl = $this->_addToken(self::url()); $view->rule = $rule; $view->special = $ingo_script->specialTypes(); $view->userheader = !empty($conf['rules']['userheader']); $filter = array(); $lastcond = count($rule['conditions']) - 1; /* Display the conditions. */ foreach ($rule['conditions'] as $cond_num => $condition) { $tmp = array('cond_num' => intval($cond_num), 'field' => isset($condition['field']) ? $condition['field'] : '', 'lastfield' => $lastcond == $cond_num); if ($view->userheader && isset($condition['type']) && $condition['type'] == Ingo_Storage::TYPE_HEADER && !isset($ingo_fields[$tmp['field']])) { $tmp['userheader'] = $tmp['field']; } if ($tmp['lastfield']) { $filter[] = $tmp; continue; } /* Create the match listing. */ if (!isset($condition['field']) || $condition['field'] == Ingo::USER_HEADER || !isset($ingo_fields[$condition['field']]['tests'])) { $avail_tests = $ingo_script->availableTests(); } else { $avail_tests = $ingo_fields[$condition['field']]['tests']; } $tmp['matchtest'] = array(); $selected_test = empty($condition['match']) ? null : $condition['match']; foreach ($avail_tests as $test) { if (is_null($selected_test)) { $selected_test = $test; } $tmp['matchtest'][] = array('label' => $ingo_storage->getTestInfo($test)->label, 'selected' => isset($condition['match']) && $test == $condition['match'], 'value' => $test); } if (!in_array($selected_test, array('exists', 'not exist'))) { $tmp['match_value'] = isset($condition['value']) ? $condition['value'] : ''; } $testOb = $ingo_storage->getTestInfo(!empty($condition['match']) ? $condition['match'] : 'contains'); switch ($testOb->type) { case 'text': if ($ingo_script->hasFeature('case_sensitive')) { $tmp['case_sensitive'] = !empty($condition['case']); } break; } $filter[] = $tmp; } $view->filter = $filter; /* Get the action select output. */ $actions = array(); $current_action = false; foreach ($availActions as $val) { $action = $ingo_storage->getActionInfo($val); $actions[] = array('label' => $action->label, 'selected' => $val == $rule['action'], 'value' => $val); if ($val == $rule['action']) { $current_action = $action; } } $view->actions = $actions; /* Get the action value output. */ if ($current_action) { switch ($current_action->type) { case 'folder': $view->actionvaluelabel = _("Select target folder"); $view->actionvalue = Ingo_Flist::select($rule['action-value']); break; case 'text': case 'int': $view->actionvaluelabel = _("Value"); $view->actionvalue = '<input id="actionvalue" name="actionvalue" size="40" value="' . htmlspecialchars($rule['action-value']) . '" />'; break; } $view->flags = $current_action->flags && $ingo_script->hasFeature('imap_flags'); } $view->stop = $ingo_script->hasFeature('stop_script'); $page_output->addScriptFile('rule.js'); $page_output->addInlineJsVars(array('IngoRule.filtersurl' => strval(Ingo_Basic_Filters::url()->setRaw(true)))); $this->header = $rule['name']; $this->output = $view->render('rule'); }
/** * Disable vacation * * @throws Ingo_Exception */ public function disableVacation() { /* Get vacation filter. */ $ingo_storage = $GLOBALS['injector']->getInstance('Ingo_Factory_Storage')->create(); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); $vacation_id = $filters->findRuleId(Ingo_Storage::ACTION_VACATION); $filters->ruleDisable($vacation_id); $ingo_storage->store($filters); Ingo_Script_Util::update(); }
/** * Constructs a new procmail recipe. * * @param array $params Array of parameters. * REQUIRED FIELDS: * 'action' * OPTIONAL FIELDS: * 'action-value' (only used if the * 'action' requires it) * @param array $scriptparams Array of parameters passed to * Ingo_Script_Procmail::. */ public function __construct($params = array(), $scriptparams = array()) { $this->_disable = !empty($params['disable']); $this->_params = array_merge($this->_params, $scriptparams); switch ($params['action']) { case Ingo_Storage::ACTION_KEEP: // Note: you may have to set the DEFAULT variable in your // backend configuration. if (isset($this->_params['delivery_agent']) && isset($this->_params['delivery_mailbox_prefix'])) { $this->_action[] = '| ' . $this->_params['delivery_agent'] . ' ' . $this->_params['delivery_mailbox_prefix'] . '$DEFAULT'; } elseif (isset($this->_params['delivery_agent'])) { $this->_action[] = '| ' . $this->_params['delivery_agent'] . ' $DEFAULT'; } else { $this->_action[] = '$DEFAULT'; } break; case Ingo_Storage::ACTION_MOVE: if (isset($this->_params['delivery_agent']) && isset($this->_params['delivery_mailbox_prefix'])) { $this->_action[] = '| ' . $this->_params['delivery_agent'] . ' ' . $this->_params['delivery_mailbox_prefix'] . $this->procmailPath($params['action-value']); } elseif (isset($this->_params['delivery_agent'])) { $this->_action[] = '| ' . $this->_params['delivery_agent'] . ' ' . $this->procmailPath($params['action-value']); } else { $this->_action[] = $this->procmailPath($params['action-value']); } break; case Ingo_Storage::ACTION_DISCARD: $this->_action[] = '/dev/null'; break; case Ingo_Storage::ACTION_REDIRECT: $this->_action[] = '! ' . $params['action-value']; break; case Ingo_Storage::ACTION_REDIRECTKEEP: $this->_action[] = '{'; $this->_action[] = ' :0 c'; $this->_action[] = ' ! ' . $params['action-value']; $this->_action[] = ''; $this->_action[] = ' :0' . (isset($this->_params['delivery_agent']) ? ' w' : ''); if (isset($this->_params['delivery_agent']) && isset($this->_params['delivery_mailbox_prefix'])) { $this->_action[] = ' | ' . $this->_params['delivery_agent'] . ' ' . $this->_params['delivery_mailbox_prefix'] . '$DEFAULT'; } elseif (isset($this->_params['delivery_agent'])) { $this->_action[] = ' | ' . $this->_params['delivery_agent'] . ' $DEFAULT'; } else { $this->_action[] = ' $DEFAULT'; } $this->_action[] = '}'; break; case Ingo_Storage::ACTION_REJECT: $this->_action[] = '{'; $this->_action[] = ' :0 h'; $this->_action[] = ' SUBJECT=| formail -xSubject:'; $this->_action[] = ''; $this->_action[] = ' :0 h'; $this->_action[] = ' SENDER=| formail -zxFrom:'; $this->_action[] = ''; $this->_action[] = ' :0 Wh'; $this->_action[] = ' * !^FROM_DAEMON'; $this->_action[] = ' * !^X-Loop: $SENDER'; $this->_action[] = ' | (formail -rA"X-Loop: $SENDER" \\'; $reason = $params['action-value']; if (Horde_Mime::is8bit($reason)) { $this->_action[] = ' -i"Subject: Re: $SUBJECT" \\'; $this->_action[] = ' -i"Content-Transfer-Encoding: quoted-printable" \\'; $this->_action[] = ' -i"Content-Type: text/plain; charset=UTF-8" ; \\'; $reason = Horde_Mime::quotedPrintableEncode($reason, "\n"); } else { $this->_action[] = ' -i"Subject: Re: $SUBJECT" ; \\'; } $reason = addcslashes($reason, "\\\n\r\t\"`"); $this->_action[] = ' ' . $this->_params['echo'] . ' -e "' . $reason . '" \\'; $this->_action[] = ' ) | $SENDMAIL -oi -t'; $this->_action[] = '}'; break; case Ingo_Storage::ACTION_VACATION: $days = $params['action-value']['days']; $timed = !empty($params['action-value']['start']) && !empty($params['action-value']['end']); $this->_action[] = '{'; foreach ($params['action-value']['addresses'] as $address) { if (!empty($address)) { $this->_action[] = ' :0'; $this->_action[] = ' * ^TO_' . $address; $this->_action[] = ' {'; $this->_action[] = ' FILEDATE=`test -f ${VACATION_DIR:-.}/\'.vacation.' . $address . '\' && ' . $this->_params['ls'] . ' -lcn --time-style=+%s ${VACATION_DIR:-.}/\'.vacation.' . $address . '\' | ' . 'awk \'{ print $6 + (' . $days * 86400 . ') }\'`'; $this->_action[] = ' DATE=`' . $this->_params['date'] . ' +%s`'; $this->_action[] = ' DUMMY=`test -f ${VACATION_DIR:-.}/\'.vacation.' . $address . '\' && ' . 'test $FILEDATE -le $DATE && ' . 'rm ${VACATION_DIR:-.}/\'.vacation.' . $address . '\'`'; if ($timed) { $this->_action[] = ' START=' . $params['action-value']['start']; $this->_action[] = ' END=' . $params['action-value']['end']; } $this->_action[] = ''; $this->_action[] = ' :0 h'; $this->_action[] = ' SUBJECT=| formail -xSubject:'; $this->_action[] = ''; $this->_action[] = ' :0 Whc: ${VACATION_DIR:-.}/vacation.lock'; if ($timed) { $this->_action[] = ' * ? test $DATE -gt $START && test $END -gt $DATE'; } $this->_action[] = ' {'; $this->_action[] = ' :0 Wh'; $this->_action[] = ' * ^TO_' . $address; $this->_action[] = ' * !^X-Loop: ' . $address; $this->_action[] = ' * !^X-Spam-Flag: YES'; if (count($params['action-value']['excludes']) > 0) { foreach ($params['action-value']['excludes'] as $exclude) { if (!empty($exclude)) { $this->_action[] = ' * !^From.*' . $exclude; } } } if ($params['action-value']['ignorelist']) { $this->_action[] = ' * !^FROM_DAEMON'; } $this->_action[] = ' | formail -rD 8192 ${VACATION_DIR:-.}/.vacation.' . $address; $this->_action[] = ' :0 eh'; $this->_action[] = ' | (formail -rI"Precedence: junk" \\'; $this->_action[] = ' -a"From: <' . $address . '>" \\'; $this->_action[] = ' -A"X-Loop: ' . $address . '" \\'; $reason = Ingo_Script_Util::vacationReason($params['action-value']['reason'], $params['action-value']['start'], $params['action-value']['end']); if (Horde_Mime::is8bit($reason)) { $this->_action[] = ' -i"Subject: ' . Horde_Mime::encode($params['action-value']['subject'] . ' (Re: $SUBJECT)') . '" \\'; $this->_action[] = ' -i"Content-Transfer-Encoding: quoted-printable" \\'; $this->_action[] = ' -i"Content-Type: text/plain; charset=UTF-8" ; \\'; $reason = Horde_Mime::quotedPrintableEncode($reason, "\n"); } else { $this->_action[] = ' -i"Subject: ' . Horde_Mime::encode($params['action-value']['subject'] . ' (Re: $SUBJECT)') . '" ; \\'; } $reason = addcslashes($reason, "\\\n\r\t\"`"); $this->_action[] = ' ' . $this->_params['echo'] . ' -e "' . $reason . '" \\'; $this->_action[] = ' ) | $SENDMAIL -f' . $address . ' -oi -t'; $this->_action[] = ' }'; $this->_action[] = ' }'; } } $this->_action[] = '}'; break; case Ingo_Storage::ACTION_FORWARD: /* Make sure that we prevent mail loops using 3 methods. * * First, we call sendmail -f to set the envelope sender to be the * same as the original sender, so bounces will go to the original * sender rather than to us. This unfortunately triggers lots of * Authentication-Warning: messages in sendmail's logs. * * Second, add an X-Loop header, to handle the case where the * address we forward to forwards back to us. * * Third, don't forward mailer daemon messages (i.e., bounces). * Method 1 above should make this redundant, unless we're sending * mail from this account and have a bad forward-to account. * * Get the from address, saving a call to formail if possible. * The procmail code for doing this is borrowed from the * Procmail Library Project, http://pm-lib.sourceforge.net/. * The Ingo project has the permission to use Procmail Library code * under Apache licence v 1.x or any later version. * Permission obtained 2006-04-04 from Author Jari Aalto. */ $this->_action[] = '{'; $this->_action[] = ' :0 '; $this->_action[] = ' *$ ! ^From *\\/[^ ]+'; $this->_action[] = ' *$ ! ^Sender: *\\/[^ ]+'; $this->_action[] = ' *$ ! ^From: *\\/[^ ]+'; $this->_action[] = ' *$ ! ^Reply-to: *\\/[^ ]+'; $this->_action[] = ' {'; $this->_action[] = ' OUTPUT = `formail -zxFrom:`'; $this->_action[] = ' }'; $this->_action[] = ' :0 E'; $this->_action[] = ' {'; $this->_action[] = ' OUTPUT = $MATCH'; $this->_action[] = ' }'; $this->_action[] = ''; /* Forward to each address on our list. */ foreach ($params['action-value'] as $address) { if (!empty($address)) { $this->_action[] = ' :0 c'; $this->_action[] = ' * !^FROM_MAILER'; $this->_action[] = ' * !^X-Loop: to-' . $address; $this->_action[] = ' | formail -A"X-Loop: to-' . $address . '" | $SENDMAIL -oi -f $OUTPUT ' . $address; } } /* In case of mail loop or bounce, store a copy locally. Note * that if we forward to more than one address, only a mail loop * on the last address will cause a local copy to be saved. TODO: * The next two lines are redundant (and create an extra copy of * the message) if "Keep a copy of messages in this account" is * checked. */ $this->_action[] = ' :0 E' . (isset($this->_params['delivery_agent']) ? 'w' : ''); if (isset($this->_params['delivery_agent'])) { $this->_action[] = isset($this->_params['delivery_mailbox_prefix']) ? ' | ' . $this->_params['delivery_agent'] . ' ' . $this->_params['delivery_mailbox_prefix'] . '$DEFAULT' : ' | ' . $this->_params['delivery_agent'] . ' $DEFAULT'; } else { $this->_action[] = ' $DEFAULT'; } $this->_action[] = ' :0 '; $this->_action[] = ' /dev/null'; $this->_action[] = '}'; break; default: $this->_valid = false; break; } }
/** * Generates the maildrop script to handle vacation messages. * * @param boolean $disable Disable forwarding? */ public function generateVacation($disable = false) { $vacation = $this->_params['storage']->retrieve(Ingo_Storage::ACTION_VACATION); $addresses = $vacation->getVacationAddresses(); $actionval = array('addresses' => $addresses, 'subject' => $vacation->getVacationSubject(), 'days' => $vacation->getVacationDays(), 'ignorelist' => $vacation->getVacationIgnorelist(), 'excludes' => $vacation->getVacationExcludes(), 'start' => $vacation->getVacationStart(), 'end' => $vacation->getVacationEnd()); if (!empty($addresses)) { $this->_addItem(Ingo::RULE_VACATION, new Ingo_Script_Maildrop_Comment(_("Vacation"), $disable, true)); $params = array('action' => Ingo_Storage::ACTION_VACATION, 'action-value' => $actionval, 'disable' => $disable); $recipe = new Ingo_Script_Maildrop_Recipe($params, $this->_params); $this->_addItem(Ingo::RULE_VACATION, $recipe); $this->_addItem(Ingo::RULE_VACATION, new Ingo_Script_String(Ingo_Script_Util::vacationReason($vacation->getVacationReason(), $vacation->getVacationStart(), $vacation->getVacationEnd())), 'vacation.msg'); } }
/** */ protected function _init() { global $injector, $notification, $session; /* Redirect if script updating is not available. */ $script = $injector->getInstance('Ingo_Factory_Script'); if (!$script->hasFeature('script_file')) { Ingo_Basic_Filters::url()->redirect(); } /* Generate the script. */ $scripts = array(); foreach ($script->createAll() as $script) { $scripts = array_merge($scripts, $script->generate()); } /* Token checking. */ $actionID = $this->_checkToken(array('action_activate', 'action_deactivate')); /* Activate/deactivate script if requested. */ switch ($actionID) { case 'action_activate': case 'action_deactivate': if (!empty($scripts)) { try { Ingo_Script_Util::activate($scripts, $actionID == 'action_deactivate'); } catch (Ingo_Exception $e) { $notification->push($e); } } break; case 'show_active': $scripts = array(); foreach ($session->get('ingo', 'backend/transport', Horde_Session::TYPE_ARRAY) as $transport) { try { $backend = $injector->getInstance('Ingo_Factory_Transport')->create($transport); if (method_exists($backend, 'getScript')) { $scripts[] = $backend->getScript(); } } catch (Horde_Exception_NotFound $e) { } catch (Ingo_Exception $e) { $notification->push($e); } } break; } /* Prepare the view. */ $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/script')); $view->addHelper('Text'); if (empty($scripts)) { $view->scriptexists = false; } else { $view->scriptexists = true; foreach ($scripts as &$script) { $script['lines'] = preg_split('(\\r\\n|\\n|\\r)', trim($script['script'])); $script['width'] = strlen(count($script['lines'])); } } $view->scripturl = $this->_addToken(self::url()); $view->showactivate = $actionID != 'show_active'; if ($view->scriptexists) { $view->scripts = $scripts; } $this->header = _("Filter Script Display"); $this->output = $view->render('script'); }
/** */ protected function _init() { global $injector, $notification, $page_output, $prefs, $session; /* Get the list of filter rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); $filters = $ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS); /* Load the Ingo_Script factory. */ $factory = $injector->getInstance('Ingo_Factory_Script'); /* Get permissions. */ $edit_allowed = Ingo::hasSharePermission(Horde_Perms::EDIT); $delete_allowed = Ingo::hasSharePermission(Horde_Perms::DELETE); /* Permissions. */ $perms = $injector->getInstance('Horde_Core_Perms'); /* Token checking. */ $actionID = $this->_checkToken(array('rule_copy', 'rule_delete', 'rule_disable', 'rule_enable')); /* Default to no mailbox filtering. */ $mbox_search = null; /* Perform requested actions. */ switch ($actionID) { case 'mbox_search': if (isset($this->vars->searchfield)) { $mbox_search = array('exact' => $this->vars->get('searchexact', 1), 'query' => $this->vars->searchfield); } break; case 'rule_copy': case 'rule_delete': case 'rule_disable': case 'rule_enable': if (!$edit_allowed) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); self::url()->redirect(); } switch ($actionID) { case 'rule_delete': if (!$delete_allowed) { $notification->push(_("You do not have permission to delete filter rules."), 'horde.error'); self::url()->redirect(); } $tmp = $filters->getFilter($this->vars->rulenumber); if ($filters->deleteRule($this->vars->rulenumber)) { $notification->push(sprintf(_("Rule \"%s\" deleted."), $tmp['name']), 'horde.success'); } break; case 'rule_copy': $max = $perms->hasAppPermission(Ingo_Perms::getPerm('max_rules')); if ($max === 0) { Horde::permissionDeniedError('ingo', 'max_rules', _("You are not allowed to create or edit custom rules.")); break 2; } elseif ($max !== true && $max <= count($filters->getFilterList())) { Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $max)); break 2; } $tmp = $filters->getFilter($this->vars->rulenumber); if ($filters->copyRule($this->vars->rulenumber)) { $notification->push(sprintf(_("Rule \"%s\" copied."), $tmp['name']), 'horde.success'); } break; case 'rule_disable': $tmp = $filters->getFilter($this->vars->rulenumber); $filters->ruleDisable($this->vars->rulenumber); $notification->push(sprintf(_("Rule \"%s\" disabled."), $tmp['name']), 'horde.success'); break; case 'rule_enable': $tmp = $filters->getFilter($this->vars->rulenumber); $filters->ruleEnable($this->vars->rulenumber); $notification->push(sprintf(_("Rule \"%s\" enabled."), $tmp['name']), 'horde.success'); break; } /* Save changes */ $ingo_storage->store($filters); try { Ingo_Script_Util::update(); } catch (Ingo_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); } break; case 'settings_save': if (!$edit_allowed) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); self::url()->redirect(); } $prefs->setValue('show_filter_msg', $this->vars->show_filter_msg); $prefs->setValue('filter_seen', $this->vars->filter_seen); $notification->push(_("Settings successfully updated."), 'horde.success'); break; case 'apply_filters': $factory->perform(); break; } /* Get the list of rules now. */ $filter_list = $filters->getFilterList(); /* Common URLs. */ $filters_url = $this->_addToken(self::url()); $rule_url = Ingo_Basic_Rule::url(); $view = new Horde_View(array('templatePath' => INGO_TEMPLATES . '/basic/filters')); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Image'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->canapply = $factory->canPerform(); $view->deleteallowed = $delete_allowed; $view->editallowed = $edit_allowed; $view->formurl = $filters_url; if (count($filter_list)) { $display = array(); $s_categories = $session->get('ingo', 'script_categories'); $view->can_copy = $edit_allowed && (($max_rules = $perms->hasAppPermission(Ingo_Perms::getPerm('max_rules'))) === true || $max_rules > count($filter_list)); foreach ($filter_list as $rule_number => $filter) { /* Non-display categories. */ if (!in_array($filter['action'], $s_categories)) { $display[$rule_number] = false; continue; } $copyurl = $delurl = $editurl = $name = null; $entry = array(); $url = $filters_url->copy()->add('rulenumber', $rule_number); switch ($filter['action']) { case Ingo_Storage::ACTION_BLACKLIST: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Blacklist::url(); $entry['filterimg'] = 'blacklist.png'; $name = _("Blacklist"); break; case Ingo_Storage::ACTION_WHITELIST: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Whitelist::url(); $entry['filterimg'] = 'whitelist.png'; $name = _("Whitelist"); break; case Ingo_Storage::ACTION_VACATION: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Vacation::url(); $entry['filterimg'] = 'vacation.png'; $name = _("Vacation"); break; case Ingo_Storage::ACTION_FORWARD: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Forward::url(); $entry['filterimg'] = 'forward.png'; $name = _("Forward"); break; case Ingo_Storage::ACTION_SPAM: if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Spam::url(); $entry['filterimg'] = 'spam.png'; $name = _("Spam Filter"); break; default: if (!is_null($mbox_search)) { if ($mbox_search['exact']) { if (strcasecmp($filter['action-value'], $mbox_search['query']) !== 0) { continue 2; } } elseif (stripos($filter['action-value'], $mbox_search['query']) === false) { continue 2; } } $editurl = $rule_url->copy()->add(array('edit' => $rule_number)); $delurl = $url->copy()->add('actionID', 'rule_delete'); $copyurl = $url->copy()->add('actionID', 'rule_copy'); $name = $filter['name']; break; } /* Create description. */ if (!$edit_allowed) { $entry['descriplink'] = htmlspecialchars($name); } elseif (!empty($filter['conditions'])) { $entry['descriplink'] = Horde::linkTooltip($editurl, sprintf(_("Edit %s"), $name), null, null, null, $ingo_storage->ruleDescription($filter)) . htmlspecialchars($name) . '</a>'; } else { $entry['descriplink'] = Horde::link($editurl, sprintf(_("Edit %s"), $name)) . htmlspecialchars($name) . '</a>'; } /* Create delete link. */ if ($delete_allowed && !is_null($delurl)) { $entry['dellink'] = Horde::link($delurl, sprintf(_("Delete %s"), $name), null, null, "return window.confirm('" . addslashes(_("Are you sure you want to delete this rule?")) . "');"); } /* Create copy link. */ if ($view->can_copy && !is_null($copyurl)) { $entry['copylink'] = Horde::link($copyurl, sprintf(_("Copy %s"), $name)); } /* Create disable/enable link. */ if (empty($filter['disable'])) { $entry['disabled'] = true; if ($edit_allowed) { $entry['disablelink'] = Horde::link($url->copy()->add('actionID', 'rule_disable'), sprintf(_("Disable %s"), $name)); } } elseif ($edit_allowed) { $entry['enablelink'] = Horde::link($url->copy()->add('actionID', 'rule_enable'), sprintf(_("Enable %s"), $name)); } $display[$rule_number] = $entry; } $view->filter = $display; $view->mbox_search = $mbox_search; } if ($edit_allowed && is_null($mbox_search)) { if ($factory->hasFeature('on_demand')) { $view->settings = true; $view->flags = $prefs->getValue('filter_seen'); $view->show_filter_msg = $prefs->getValue('show_filter_msg'); } $page_output->addScriptFile('hordecore.js', 'horde'); $page_output->addScriptPackage('Horde_Core_Script_Package_Sortable'); } $page_output->addScriptFile('stripe.js', 'horde'); $page_output->addScriptFile('filters.js'); $topbar = $injector->getInstance('Horde_View_Topbar'); $topbar->search = true; $topbar->searchAction = self::url(); $topbar->searchLabel = _("Mailbox Search"); $topbar->searchParameters = array('actionID' => 'mbox_search', 'searchexact' => 0, 'page' => 'filters'); $this->header = _("Filter Rules"); $this->output = $view->render('filters'); }