/** */ 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'); }
/** * Returns a Ingo_Transport instance. * * @param array $transport A transport driver name and parameter hash. * * @return Ingo_Transport The Ingo_Transport instance. * @throws Ingo_Exception */ public function create(array $transport) { global $registry; /* Get authentication parameters. */ try { $auth = $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook('transport_auth', 'ingo', array($transport['driver'])); } catch (Horde_Exception_HookNotSet $e) { $auth = null; } if (!is_array($auth)) { $auth = array(); } if (!isset($auth['password'])) { $auth['password'] = $registry->getAuthCredential('password'); } if (!isset($auth['username'])) { $auth['username'] = $registry->getAuth('bare'); } if (!isset($auth['euser'])) { $auth['euser'] = Ingo::getUser(false); } $class = 'Ingo_Transport_' . ucfirst($transport['driver']); if (class_exists($class)) { return new $class(array_merge($auth, $transport['params'])); } throw new Ingo_Exception(sprintf(_("Unable to load the transport driver \"%s\"."), $class)); }
/** * @see Horde_Registry_Application#perms() */ public function perms() { $perms = array('backends' => array('title' => _("Backends"))); foreach (array_keys(Ingo::loadBackends()) as $key) { $bkey = 'backends:' . $key; $perms[$bkey] = array('title' => $key); foreach ($this->_perms as $key2 => $val2) { $perms[$bkey . ':' . $key2] = array('title' => $val2['title'], 'type' => $val2['type']); } } return $perms; }
/** * Replaces place holders in a query. * * @param string $query A SQL query with place holders. * @param integer $rule A Ingo::RULE_* constant. * * @return string A valid query. */ protected function _placeHolders($query, $rule) { $transport = $GLOBALS['injector']->getInstance('Ingo_Factory_Transport')->create(isset($this->_params['transport'][$rule]) ? $this->_params['transport'][$rule] : $this->_params['transport'][Ingo::RULE_ALL]); $search = array('%u', '%d'); $replace = array($transport->quote(Ingo::getUser()), $transport->quote(Ingo::getDomain())); switch ($rule) { case Ingo::RULE_VACATION: $vacation = $this->_params['storage']->retrieve(Ingo_Storage::ACTION_VACATION); $search[] = '%m'; $search[] = '%s'; $replace[] = $transport->quote($vacation->getVacationReason()); $replace[] = $transport->quote($vacation->getVacationSubject()); break; } return str_replace($search, $replace, $query); }
/** */ protected function _storeBackend($action, $rule) { $user = Ingo::getUser(); switch ($action) { case self::STORE_ADD: try { $res = $this->_params['db']->aggregate(array(array('$match' => array(self::WHO => $user)), array('$group' => array(self::MONGO_ID => '', 'max' => array('$max' => '$' . self::ORDER))))); if (isset($res['result'])) { $res = current($res['result']); $max = ++$res['max']; } else { $max = 0; } $this->_params['db']->insert(array(self::DATA => serialize($rule), self::ORDER => $max, self::WHO => $user)); } catch (MongoException $e) { throw new Ingo_Exception($e); } break; case self::STORE_DELETE: try { $this->_params['db']->remove(array(self::MONGO_ID => new MongoId($rule->uid), self::WHO => $user)); } catch (MongoException $e) { } break; case self::STORE_SORT: try { foreach ($this->_rules as $key => $val) { $this->_params['db']->update(array(self::MONGO_ID => new MongoId($val->uid), self::WHO => $user), array('$set' => array(self::ORDER => $key))); } } catch (MongoException $e) { } break; case self::STORE_UPDATE: try { $this->_params['db']->update(array(self::MONGO_ID => new MongoId($rule->uid), self::WHO => $user), array('$set' => array(self::DATA => serialize($rule)))); } catch (MongoException $e) { } break; } }
/** * AJAX action: Re-sort the filters list. * * Variables used: * - sort: (string) JSON serialized sort list of rule UIDs. * * @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(); try { $storage->sort(json_decode($this->vars->sort)); $notification->push(_("Rule sort saved successfully."), 'horde.success'); } catch (Ingo_Exception $e) { $notification->push(_("Rule sort not saved."), 'horde.error'); return false; } try { $injector->getInstance('Ingo_Factory_Script')->activateAll(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.warning'); } return true; }
/** */ public function getVacationAddresses() { try { return $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook('vacation_addresses', 'ingo', array(Ingo::getUser(), $this->_addr)); } catch (Horde_Exception_HookNotSet $e) { return $this->_addr; } }
/** */ protected function _storeBackend($action, $rule) { switch ($action) { case self::STORE_ADD: try { $query = sprintf('SELECT MAX(rule_order) FROM %s WHERE rule_owner = ?', $this->_params['table_rules']); $values = array(Ingo::getUser()); $max = $this->_params['db']->selectValue($query, $values); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } $query = sprintf('INSERT INTO %s (rule_owner, rule_name, rule_action, ' . 'rule_value, rule_flags, rule_conditions, rule_combine, ' . 'rule_stop, rule_active, rule_order) ' . 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table_rules']); $d = $this->_ruleToBackend($rule); $values = array(Ingo::getUser(), $d['name'], $d['action'], $d['value'], $d['flags'], $d['conditions'], $d['combine'], $d['stop'], $d['active'], $max + 1); try { $rule->uid = $this->_params['db']->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } break; case self::STORE_DELETE: $query = sprintf('DELETE FROM %s WHERE rule_id = ? AND rule_owner = ?', $this->_params['table_rules']); $values = array($rule->uid, Ingo::getUser()); try { /* No need to alter rule order; it is no longer contiguous, * but that doesn't affect sort order. */ $this->_params['db']->delete($query, $values); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } break; case self::STORE_UPDATE: $query = sprintf('UPDATE %s SET rule_name = ?, rule_action = ?, ' . 'rule_value = ?, rule_flags = ?, rule_conditions = ?, ' . 'rule_combine = ?, rule_stop = ?, rule_active = ? ' . 'WHERE rule_id = ? AND rule_owner = ?', $this->_params['table_rules']); $d = $this->_ruleToBackend($rule); $values = array($d['name'], $d['action'], $d['value'], $d['flags'], $d['conditions'], $d['combine'], $d['stop'], $d['active'], $rule->uid, Ingo::getUser()); try { $this->_params['db']->update($query, $values); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } break; case self::STORE_SORT: /* This won't update "invisible" rules based on current script * setup, but that is fine; sorting will still work if rules have * duplicate order IDs, and these invisible rules have no * guarantee of order if they are ever displayed again. */ $query = sprintf('UPDATE %s SET rule_order = ? WHERE rule_id = ?', $this->_params['table_rules']); $this->_params['db']->beginDbTransaction(); try { foreach ($this->_rules as $key => $val) { $this->_params['db']->update($query, array($key, $val->uid)); } } catch (Horde_Db_Exception $e) { $this->_params['db']->rollbackDbTransaction(); throw new Ingo_Exception($e); } $this->_params['db']->commitDbTransaction(); break; } switch ($action) { case self::STORE_ADD: case self::STORE_UPDATE: switch ($class = get_class($rule)) { case 'Ingo_Rule_System_Blacklist': case 'Ingo_Rule_System_Whitelist': $query = sprintf('DELETE FROM %s WHERE list_owner = ? AND ' . 'list_blacklist = ?', $this->_params['table_lists']); $values = array(Ingo::getUser(), intval($class === 'Ingo_Rule_System_Blacklist')); try { $this->_params['db']->delete($query, $values); } catch (Horde_Db_Exception $e) { Horde::log($e, 'ERR'); throw new Ingo_Exception($e); } $query = sprintf('INSERT INTO %s (list_owner, list_blacklist, ' . 'list_address) VALUES (?, ?, ?)', $this->_params['table_lists']); $this->_params['db']->beginDbTransaction(); try { foreach ($rule->addresses as $address) { $this->_params['db']->insert($query, array_merge($values, array($address))); } } catch (Horde_Db_Exception $e) { Horde::log($e, 'ERR'); throw new Ingo_Exception($e); } break; case 'Ingo_Rule_System_Forward': $values = array(implode("\n", $rule->addresses), intval($rule->keep), Ingo::getUser()); try { if ($action === self::STORE_ADD) { $query = sprintf('INSERT INTO %s (forward_addresses, ' . 'forward_keep, forward_owner) VALUES (?, ?, ?)', $this->_params['table_forwards']); $this->_params['db']->insert($query, $values); } else { $query = sprintf('UPDATE %s SET forward_addresses = ?, ' . 'forward_keep = ? WHERE forward_owner = ?', $this->_params['table_forwards']); $this->_params['db']->update($query, $values); } } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } break; case 'Ingo_Rule_System_Spam': $values = array($rule->level, $rule->mailbox, Ingo::getUser()); try { if ($action === self::STORE_ADD) { $query = sprintf('UPDATE %s SET spam_level = ?, ' . 'spam_folder = ? WHERE spam_owner = ?', $this->_params['table_spam']); $this->_params['db']->update($query, $values); } else { $query = sprintf('INSERT INTO %s (spam_level, spam_folder, ' . 'spam_owner) VALUES (?, ?, ?)', $this->_params['table_spam']); $this->_params['db']->insert($query, $values); } } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } break; case 'Ingo_Rule_System_Vacation': $values = array(implode("\n", $rule->addresses), Horde_String::convertCharset($rule->subject, 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($rule->reason, 'UTF-8', $this->_params['charset']), $rule->days, $rule->start, $rule->end, implode("\n", $rule->exclude), intval($rule->ignore_list), Ingo::getUser()); try { if ($action === self::STORE_ADD) { $query = sprintf('INSERT INTO %s (vacation_addresses, ' . 'vacation_subject, vacation_reason, ' . 'vacation_days, vacation_start, vacation_end, ' . 'vacation_excludes, vacation_ignorelists, ' . 'vacation_owner) VALUES ' . '(?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table_vacations']); $this->_params['db']->insert($query, $values); } else { $query = sprintf('UPDATE %s SET vacation_addresses = ?, ' . 'vacation_subject = ?, vacation_reason = ?, ' . 'vacation_days = ?, vacation_start = ?, ' . 'vacation_end = ?, vacation_excludes = ?, ' . 'vacation_ignorelists = ? WHERE ' . 'vacation_owner = ?', $this->_params['table_vacations']); $this->_params['db']->update($query, $values); } } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } break; } } }
/** * Returns all rulesets a user has access to. * * @return array The ruleset list. */ protected function _listRulesets() { global $injector, $registry; if (isset($this->_rulesets)) { return $this->_rulesets; } $this->_rulesets = array(); try { if (!($share = $injector->getInstance('Ingo_Shares'))) { return $this->_rulesets; } $tmp = $share->listShares($registry->getAuth(), array('perm' => Horde_Perms::SHOW)); } catch (Horde_Share_Exception $e) { Horde::log($e, 'ERR'); return $this->_rulesets; } /* Check if filter backend of the share still exists. */ $backends = Ingo::loadBackends(); foreach ($tmp as $id => $ruleset) { list($backend) = explode(':', $id); if (isset($backends[$backend])) { $this->_rulesets[$id] = $ruleset; } } return $this->_rulesets; }
/** * Determine the backend to use. * * This decision is based on the global 'SERVER_NAME' and 'HTTP_HOST' * server variables and the contents of the 'preferred' either field * in the backend's definition. The 'preferred' field may take a * single value or an array of multiple values. * * @return array The backend entry. * @throws Ingo_Exception */ protected static function _getBackend() { $backend = null; foreach (Ingo::loadBackends() as $name => $val) { $val['id'] = $name; if (!isset($backend)) { $backend = $val; } elseif (!empty($val['preferred'])) { if (is_array($val['preferred'])) { foreach ($val['preferred'] as $v) { if ($v == $_SERVER['SERVER_NAME'] || $v == $_SERVER['HTTP_HOST']) { $backend = $val; } } } elseif ($val['preferred'] == $_SERVER['SERVER_NAME'] || $val['preferred'] == $_SERVER['HTTP_HOST']) { $backend = $val; } } } /* Check for valid backend configuration. */ if (is_null($backend)) { throw new Ingo_Exception(_("No backend configured for this host")); } foreach (array('script', 'transport') as $val) { if (empty($backend[$val])) { throw new Ingo_Exception(sprintf(_("No \"%s\" element found in backend configuration."), $val)); } } return $backend; }
/** * Deletes a rule from the filters list. * * @param integer $id Number of the rule to delete. * * @return boolean True if the rule has been found and deleted. */ public function deleteRule($id) { if (!isset($this->_filters[$id])) { return false; } $query = sprintf('DELETE FROM %s WHERE rule_id = ? AND rule_owner = ?', $this->_params['table_rules']); $values = array($this->_filters[$id]['id'], Ingo::getUser()); try { $this->_db->delete($query, $values); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } /* Remove the rule from the filter list. */ unset($this->_filters[$id]); $this->_filters = array_combine(range(1, count($this->_filters)), array_values($this->_filters)); $query = sprintf('UPDATE %s SET rule_order = rule_order - 1 WHERE rule_owner = ? AND rule_order > ?', $this->_params['table_rules']); $values = array(Ingo::getUser(), $id); try { $this->_db->update($query, $values); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } return true; }
/** * Returns the vacation reason with all placeholder replaced. * * @param string $reason The vacation reason including placeholders. * @param integer $start The vacation start timestamp. * @param integer $end The vacation end timestamp. * * @return string The vacation reason suitable for usage in the filter * scripts. */ public static function vacationReason($reason, $start, $end) { global $injector, $prefs; $format = $prefs->getValue('date_format'); $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create(Ingo::getUser()); $replace = array('%NAME%' => $identity->getName(), '%EMAIL%' => $identity->getDefaultFromAddress(), '%SIGNATURE%' => $identity->getValue('signature'), '%STARTDATE%' => $start ? strftime($format, $start) : '', '%ENDDATE%' => $end ? strftime($format, $end) : ''); return str_replace(array_keys($replace), array_values($replace), $reason); }
<?php /** * Index script. * * Copyright 2002-2014 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (ASL). If you * did not receive this file, see http://www.horde.org/licenses/apache. * * @author Mike Cochrane <*****@*****.**> * @category Horde * @license http://www.horde.org/licenses/apache ASL * @package Ingo */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('ingo'); Ingo::getInitialPage()->redirect();
/** */ 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'); }
/** * Get prefs object to use for storage. * * @param string $user Username to use (if not default). * * @return Horde_Prefs Prefs object. */ protected function _prefs($user = null) { global $injector; return $injector->getInstance('Horde_Core_Factory_Prefs')->create('ingo', array('cache' => false, 'user' => is_null($user) ? Ingo::getUser() : $user)); }
/** */ 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'); }
/** * Connect to the VFS server. * * @throws Ingo_Exception */ protected function _connect() { /* Do variable substitution. */ if (!empty($this->_params['vfs_path'])) { $this->_params['vfs_path'] = str_replace(array('%u', '%d', '%U'), array(Ingo::getUser(), Ingo::getDomain(), $this->_params['username']), $this->_params['vfs_path']); } if (!empty($this->_vfs)) { return; } try { $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('ingo', array('type' => $this->_params['vfstype'], 'params' => $this->_params)); } catch (Horde_Exception $e) { throw new Ingo_Exception($e); } }
/** * Add addresses to the whitelist. * * @param string $addresses The addresses to add to the whitelist. */ public function whitelistFrom($addresses) { global $injector, $notification; try { $wl = $injector->getInstance('Ingo_Factory_Storage')->create()->retrieve(Ingo_Storage::ACTION_WHITELIST)->getWhitelist(); Ingo::updateListFilter(array_merge($wl, $addresses), Ingo_Storage::ACTION_WHITELIST); Ingo_Script_Util::update(false); foreach ($addresses as $from) { $notification->push(sprintf(_("The address \"%s\" has been added to your whitelist."), $from)); } } catch (Ingo_Exception $e) { $notification->push($e); } }
/** * Stores the specified data in the storage backend. * * @access private * * @param Ingo_Storage_Rule|Ingo_Storage_Filters $ob The object to store. */ protected function _store($ob) { switch ($ob->obType()) { case self::ACTION_BLACKLIST: case self::ACTION_WHITELIST: $is_blacklist = (int) ($ob->obType() == self::ACTION_BLACKLIST); if ($is_blacklist) { $filters = $this->retrieve(self::ACTION_FILTERS); $id = $filters->findRuleId(self::ACTION_BLACKLIST); if ($id !== null) { $rule = $filters->getRule($id); if (!isset($rule['action-value']) || $rule['action-value'] != $ob->getBlacklistFolder()) { $rule['action-value'] = $ob->getBlacklistFolder(); $filters->updateRule($rule, $id); } } } $query = sprintf('DELETE FROM %s WHERE list_owner = ? AND list_blacklist = ?', $this->_params['table_lists']); $values = array(Ingo::getUser(), $is_blacklist); try { $this->_params['db']->delete($query, $values); } catch (Horde_Db_Exception $e) { Horde::log($e, 'ERR'); throw new Ingo_Exception($e); } $query = sprintf('INSERT INTO %s (list_owner, list_blacklist, list_address) VALUES (?, ?, ?)', $this->_params['table_lists']); $addresses = $is_blacklist ? $ob->getBlacklist() : $ob->getWhitelist(); foreach ($addresses as $address) { try { $result = $this->_params['db']->insert($query, array(Ingo::getUser(), $is_blacklist, $address)); } catch (Horde_Db_Exception $e) { Horde::log($result, 'ERR'); throw new Ingo_Exception($e); } } $ob->setSaved(true); break; case self::ACTION_FORWARD: $values = array(implode("\n", $ob->getForwardAddresses()), (int) (bool) $ob->getForwardKeep(), Ingo::getUser()); try { if ($ob->isSaved()) { $query = sprintf('UPDATE %s SET forward_addresses = ?, forward_keep = ? WHERE forward_owner = ?', $this->_params['table_forwards']); $this->_params['db']->update($query, $values); } else { $query = sprintf('INSERT INTO %s (forward_addresses, forward_keep, forward_owner) VALUES (?, ?, ?)', $this->_params['table_forwards']); $this->_params['db']->insert($query, $values); } } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } $ob->setSaved(true); break; case self::ACTION_VACATION: $values = array(implode("\n", $ob->getVacationAddresses()), Horde_String::convertCharset($ob->getVacationSubject(), 'UTF-8', $this->_params['charset']), Horde_String::convertCharset($ob->getVacationReason(), 'UTF-8', $this->_params['charset']), (int) $ob->getVacationDays(), (int) $ob->getVacationStart(), (int) $ob->getVacationEnd(), implode("\n", $ob->getVacationExcludes()), (int) (bool) $ob->getVacationIgnorelist(), Ingo::getUser()); try { if ($ob->isSaved()) { $query = sprintf('UPDATE %s SET vacation_addresses = ?, vacation_subject = ?, vacation_reason = ?, vacation_days = ?, vacation_start = ?, vacation_end = ?, vacation_excludes = ?, vacation_ignorelists = ? WHERE vacation_owner = ?', $this->_params['table_vacations']); $this->_params['db']->update($query, $values); } else { $query = sprintf('INSERT INTO %s (vacation_addresses, vacation_subject, vacation_reason, vacation_days, vacation_start, vacation_end, vacation_excludes, vacation_ignorelists, vacation_owner) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table_vacations']); $this->_params['db']->insert($query, $values); } } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } $ob->setSaved(true); break; case self::ACTION_SPAM: $values = array((int) $ob->getSpamLevel(), $ob->getSpamFolder(), Ingo::getUser()); try { if ($ob->isSaved()) { $query = sprintf('UPDATE %s SET spam_level = ?, spam_folder = ? WHERE spam_owner = ?', $this->_params['table_spam']); $this->_params['db']->update($query, $values); } else { $query = sprintf('INSERT INTO %s (spam_level, spam_folder, spam_owner) VALUES (?, ?, ?)', $this->_params['table_spam']); $this->_params['db']->insert($query, $values); } } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } $ob->setSaved(true); break; } }
/** */ protected function _init() { global $injector, $notification, $page_output, $prefs, $session; /* Get the list of filter rules. */ $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); /* 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); /* 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(); } $success = false; switch ($actionID) { case 'rule_delete': if (!$delete_allowed) { $notification->push(_("You do not have permission to delete filter rules."), 'horde.error'); self::url()->redirect(); } if (($tmp = $ingo_storage->getRuleByUid($this->vars->uid)) && $ingo_storage->deleteRule($tmp)) { $notification->push(sprintf(_("Rule \"%s\" deleted."), $tmp->name), 'horde.success'); $success = true; } break; case 'rule_copy': switch ($ingo_storage->maxRules()) { case Ingo_Storage::MAX_NONE: Horde::permissionDeniedError('ingo', 'max_rules', _("You are not allowed to create or edit custom rules.")); break 2; case Ingo_Storage::MAX_OVER: Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $ingo_storage->max_rules)); break 2; } if (($tmp = $ingo_storage->getRuleByUid($this->vars->uid)) && $ingo_storage->copyRule($tmp)) { $notification->push(sprintf(_("Rule \"%s\" copied."), $tmp->name), 'horde.success'); $success = true; } break; case 'rule_disable': case 'rule_enable': if ($tmp = $ingo_storage->getRuleByUid($this->vars->uid)) { $tmp->disable = $actionID === 'rule_disable'; $ingo_storage->updateRule($tmp); $notification->push(sprintf($actionID === 'rule_disable' ? _("Rule \"%s\" disabled.") : _("Rule \"%s\" enabled."), $tmp->name), 'horde.success'); $success = true; } break; } /* Save changes */ if ($success) { try { $factory->activateAll(); } 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; } /* 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; $view->can_copy = $edit_allowed && !$ingo_storage->maxRules(); $display = array(); $filters = Ingo_Storage_FilterIterator_Match::create($ingo_storage, $session->get('ingo', 'script_categories')); foreach ($filters as $rule) { $copyurl = $delurl = $editurl = null; $entry = array(); $url = $filters_url->copy()->add('uid', $rule->uid); switch (get_class($rule)) { case 'Ingo_Rule_System_Blacklist': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Blacklist::url(); $entry['filterimg'] = 'blacklist.png'; break; case 'Ingo_Rule_System_Whitelist': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Whitelist::url(); $entry['filterimg'] = 'whitelist.png'; break; case 'Ingo_Rule_System_Vacation': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Vacation::url(); $entry['filterimg'] = 'vacation.png'; break; case 'Ingo_Rule_System_Forward': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Forward::url(); $entry['filterimg'] = 'forward.png'; break; case 'Ingo_Rule_System_Spam': if (!is_null($mbox_search)) { continue 2; } $editurl = Ingo_Basic_Spam::url(); $entry['filterimg'] = 'spam.png'; 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->uid)); $delurl = $url->copy()->add('actionID', 'rule_delete'); $copyurl = $url->copy()->add('actionID', 'rule_copy'); break; } /* Create description. */ if (!$edit_allowed) { $entry['descriplink'] = htmlspecialchars($rule->name); } elseif (!empty($rule->conditions)) { $entry['descriplink'] = Horde::linkTooltip($editurl, sprintf(_("Edit %s"), $rule->name), null, null, null, $rule->description()) . htmlspecialchars($rule->name) . '</a>'; } else { $entry['descriplink'] = Horde::link($editurl, sprintf(_("Edit %s"), $rule->name)) . htmlspecialchars($rule->name) . '</a>'; } /* Create delete link. */ if ($delete_allowed && !is_null($delurl)) { $entry['dellink'] = Horde::link($delurl, sprintf(_("Delete %s"), $rule->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"), $rule->name)); } /* Create disable/enable link. */ if (!$rule->disable) { $entry['disabled'] = true; if ($edit_allowed) { $entry['disablelink'] = Horde::link($url->copy()->add('actionID', 'rule_disable'), sprintf(_("Disable %s"), $rule->name)); } } elseif ($edit_allowed) { $entry['enablelink'] = Horde::link($url->copy()->add('actionID', 'rule_enable'), sprintf(_("Enable %s"), $rule->name)); } $display[$rule->uid] = $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'); $page_output->ajax = true; $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'); }
/** */ protected function _init() { global $conf, $injector, $notification, $page_output; $ingo_storage = $injector->getInstance('Ingo_Factory_Storage')->create(); switch ($ingo_storage->maxRules()) { case Ingo_Storage::MAX_NONE: Horde::permissionDeniedError('ingo', 'allow_rules', _("You are not allowed to create or edit custom rules.")); Ingo_Basic_Filters::url()->redirect(); case Ingo_Storage::MAX_OVER: Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $ingo_storage->max_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_factory = $injector->getInstance('Ingo_Factory_Script'); $ingo_script = $ingo_script_factory->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']; /* Token checking. */ $actionID = $this->_checkToken(array('rule_save', 'rule_delete')); /* Update the current rules before performing any action. */ switch ($this->vars->action) { case 'Ingo_Rule_User_Discard': case 'Ingo_Rule_User_FlagOnly': case 'Ingo_Rule_User_Keep': case 'Ingo_Rule_User_Move': case 'Ingo_Rule_User_MoveKeep': case 'Ingo_Rule_User_Notify': case 'Ingo_Rule_User_Redirect': case 'Ingo_Rule_User_RedirectKeep': case 'Ingo_Rule_User_Reject': $rule = new $this->vars->action(); $rule->combine = $this->vars->combine; $rule->name = $this->vars->name; $rule->stop = $this->vars->stop; $rule->uid = $this->vars->edit; break; default: $rule = isset($this->vars->edit) ? $ingo_storage->getRuleByUid($this->vars->edit) : new Ingo_Rule_User(); break; } 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_Rule_User::TEST_HEADER; } elseif (!isset($ingo_fields[$val])) { $condition['field'] = $val; $condition['type'] = Ingo_Rule_User::TEST_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] : ''; } $tmp = $rule->conditions; $tmp[] = $condition; $rule->conditions = $tmp; } if ($this->vars->action) { switch ($rule->type) { case Ingo_Rule_User::TYPE_MAILBOX: switch ($actionID) { case 'rule_save': try { $rule->value = $this->validateMbox('actionvalue'); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); $actionID = null; } break; default: $rule->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; } break; default: $rule->value = $this->vars->actionvalue; break; } } $flags = empty($this->vars->flags) ? array() : $this->vars->flags; $tmp = $rule->flags; foreach ($flags as $val) { $tmp |= $val; } $rule->flags = $tmp; /* 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; } $ingo_storage->updateRule($rule); $notification->push(_("Changes saved."), 'horde.success'); try { $ingo_script_factory->activateAll(); } catch (Ingo_Exception $e) { $notification->push($e, 'horde.error'); } Ingo_Basic_Filters::url()->redirect(); case 'rule_delete': if (isset($this->vars->conditionnumber)) { $tmp = $rule->conditions; unset($tmp[intval($this->vars->conditionnumber)]); $rule->conditions = array_values($tmp); } 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_Rule_User::TEST_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' => $rule->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 = $rule->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(); foreach ($availActions as $val) { $ob = new $val(); $actions[] = array('label' => $ob->label, 'selected' => $ob instanceof $rule, 'value' => $val); } $view->actions = $actions; /* Get the action value output. */ switch ($rule->type) { case Ingo_Rule_User::TYPE_MAILBOX: $view->actionvaluelabel = _("Select target folder"); $view->actionvalue = Ingo_Flist::select($rule->value); break; case Ingo_Rule_User::TYPE_TEXT: $view->actionvaluelabel = _("Value"); $view->actionvalue = '<input id="actionvalue" name="actionvalue" size="40" value="' . htmlspecialchars($rule->value) . '" />'; break; } $view->flags = $rule->flags && Ingo_Rule_User::FLAG_AVAILABLE && $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'); }
/** * Stores the specified data in the storage backend. * * @param Ingo_Storage_Rule|Ingo_Storage_Filters $ob The object to store. */ protected function _store($ob) { $prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('ingo', array('cache' => false, 'user' => Ingo::getUser())); switch ($ob->obType()) { case self::ACTION_BLACKLIST: $data = array('a' => $ob->getBlacklist(), 'f' => $ob->getBlacklistFolder()); $prefs->setValue('blacklist', serialize($data)); break; case self::ACTION_FILTERS: $prefs->setValue('rules', serialize($ob->getFilterList())); break; case self::ACTION_FORWARD: $data = array('a' => $ob->getForwardAddresses(), 'k' => $ob->getForwardKeep()); $prefs->setValue('forward', serialize($data)); break; case self::ACTION_VACATION: $data = array('addresses' => $ob->getVacationAddresses(), 'days' => $ob->getVacationDays(), 'excludes' => $ob->getVacationExcludes(), 'ignorelist' => $ob->getVacationIgnorelist(), 'reason' => $ob->getVacationReason(), 'subject' => $ob->getVacationSubject(), 'start' => $ob->getVacationStart(), 'end' => $ob->getVacationEnd()); $prefs->setValue('vacation', serialize($data)); break; case self::ACTION_WHITELIST: $prefs->setValue('whitelist', serialize($ob->getWhitelist())); break; case self::ACTION_SPAM: $data = array('folder' => $ob->getSpamFolder(), 'level' => $ob->getSpamLevel()); $prefs->setValue('spam', serialize($data)); break; } }