/** * Retrieves the specified data from the storage backend. * * @param integer $field The field name of the desired data. * See lib/Storage.php for the available fields. * @param boolean $readonly Whether to disable any write operations. * * @return Ingo_Storage_Rule|Ingo_Storage_Filters The specified data. */ protected function _retrieve($field, $readonly = false) { $prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('ingo', array('cache' => false, 'user' => Ingo::getUser())); switch ($field) { case self::ACTION_BLACKLIST: $ob = new Ingo_Storage_Blacklist(); if ($data = @unserialize($prefs->getValue('blacklist'))) { $ob->setBlacklist($data['a']); $ob->setBlacklistFolder($data['f']); } break; case self::ACTION_WHITELIST: $ob = new Ingo_Storage_Whitelist(); if ($data = @unserialize($prefs->getValue('whitelist'))) { $ob->setWhitelist($data); } break; case self::ACTION_FILTERS: $ob = new Ingo_Storage_Filters(); if ($data = @unserialize($prefs->getValue('rules'))) { $ob->setFilterlist($data); } break; case self::ACTION_FORWARD: $ob = new Ingo_Storage_Forward(); if ($data = @unserialize($prefs->getValue('forward'))) { $ob->setForwardAddresses($data['a']); $ob->setForwardKeep($data['k']); } break; case self::ACTION_VACATION: $ob = new Ingo_Storage_Vacation(); if ($data = @unserialize($prefs->getValue('vacation'))) { $ob->setVacationAddresses($data['addresses']); $ob->setVacationDays($data['days']); $ob->setVacationExcludes($data['excludes']); $ob->setVacationIgnorelist($data['ignorelist']); $ob->setVacationReason($data['reason']); $ob->setVacationSubject($data['subject']); if (isset($data['start'])) { $ob->setVacationStart($data['start']); } if (isset($data['end'])) { $ob->setVacationEnd($data['end']); } } break; case self::ACTION_SPAM: $ob = new Ingo_Storage_Spam(); if ($data = @unserialize($prefs->getValue('spam'))) { $ob->setSpamFolder($data['folder']); $ob->setSpamLevel($data['level']); } break; default: $ob = false; break; } return $ob; }
public function testWhitelist() { $wl = new Ingo_Storage_Whitelist(3); $wl->setWhitelist(array('*****@*****.**')); $this->storage->store($wl); $this->_assertScript('if address :all :comparator "i;ascii-casemap" :is ["From", "Sender", "Resent-From"] "*****@*****.**" { keep; stop; }'); }
function test_partial_whitelist_address_should_not_match() { $runner = ScriptTester::factory('all', $this); $bl = new Ingo_Storage_Blacklist(); $bl->setBlacklist(array('*****@*****.**')); $bl->setBlacklistFolder(''); $runner->addRule($bl); $wl = new Ingo_Storage_Whitelist(); $wl->setWhitelist(array('*****@*****.**')); $runner->addRule($wl); $runner->assertDeletesMessage('from_spammer'); }
/** * Retrieves the specified data from the storage backend. * * @param integer $field The field name of the desired data. * See lib/Storage.php for the available fields. * @param boolean $readonly Whether to disable any write operations. * * @return Ingo_Storage_Rule|Ingo_Storage_Filters The specified data. * @throws Ingo_Exception */ protected function _retrieve($field, $readonly = false) { switch ($field) { case self::ACTION_BLACKLIST: case self::ACTION_WHITELIST: if ($field == self::ACTION_BLACKLIST) { $ob = new Ingo_Storage_Blacklist(); $filters = $this->retrieve(self::ACTION_FILTERS); $rule = $filters->findRule($field); if (isset($rule['action-value'])) { $ob->setBlacklistFolder($rule['action-value']); } } else { $ob = new Ingo_Storage_Whitelist(); } $query = sprintf('SELECT list_address FROM %s WHERE list_owner = ? AND list_blacklist = ?', $this->_params['table_lists']); $values = array(Ingo::getUser(), (int) ($field == self::ACTION_BLACKLIST)); try { $addresses = $this->_params['db']->selectValues($query, $values); } catch (Horde_Db_Exception $e) { Horde::log($e->getMessage(), 'ERR'); throw new Ingo_Exception($e); } if ($field == self::ACTION_BLACKLIST) { $ob->setBlacklist($addresses); } else { $ob->setWhitelist($addresses); } break; case self::ACTION_FILTERS: $ob = new Ingo_Storage_Filters_Sql($this->_params['db'], $this->_params); $ob->init($readonly); break; case self::ACTION_FORWARD: $query = sprintf('SELECT * FROM %s WHERE forward_owner = ?', $this->_params['table_forwards']); try { $data = $this->_params['db']->selectOne($query, array(Ingo::getUser())); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } $ob = new Ingo_Storage_Forward(); if (!empty($data)) { $ob->setForwardAddresses(explode("\n", $data['forward_addresses'])); $ob->setForwardKeep((bool) $data['forward_keep']); $ob->setSaved(true); } elseif ($data = @unserialize($GLOBALS['prefs']->getDefault('forward'))) { $ob->setForwardAddresses($data['a']); $ob->setForwardKeep($data['k']); } break; case self::ACTION_VACATION: $query = sprintf('SELECT * FROM %s WHERE vacation_owner = ?', $this->_params['table_vacations']); try { $data = $this->_params['db']->selectOne($query, array(Ingo::getUser())); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } $ob = new Ingo_Storage_Vacation(); if (!empty($data)) { $ob->setVacationAddresses(explode("\n", $data['vacation_addresses'])); $ob->setVacationDays((int) $data['vacation_days']); $ob->setVacationStart((int) $data['vacation_start']); $ob->setVacationEnd((int) $data['vacation_end']); $ob->setVacationExcludes(explode("\n", $data['vacation_excludes'])); $ob->setVacationIgnorelist((bool) $data['vacation_ignorelists']); $ob->setVacationReason(Horde_String::convertCharset($data['vacation_reason'], $this->_params['charset'], 'UTF-8')); $ob->setVacationSubject(Horde_String::convertCharset($data['vacation_subject'], $this->_params['charset'], 'UTF-8')); $ob->setSaved(true); } elseif ($data = @unserialize($GLOBALS['prefs']->getDefault('vacation'))) { $ob->setVacationAddresses($data['addresses'], false); $ob->setVacationDays($data['days']); $ob->setVacationExcludes($data['excludes']); $ob->setVacationIgnorelist($data['ignorelist']); $ob->setVacationReason($data['reason']); $ob->setVacationSubject($data['subject']); if (isset($data['start'])) { $ob->setVacationStart($data['start']); } if (isset($data['end'])) { $ob->setVacationEnd($data['end']); } } break; case self::ACTION_SPAM: $query = sprintf('SELECT * FROM %s WHERE spam_owner = ?', $this->_params['table_spam']); try { $data = $this->_params['db']->selectOne($query, array(Ingo::getUser())); } catch (Horde_Db_Exception $e) { throw new Ingo_Exception($e); } $ob = new Ingo_Storage_Spam(); if (!empty($data)) { $ob->setSpamFolder($data['spam_folder']); $ob->setSpamLevel((int) $data['spam_level']); $ob->setSaved(true); } elseif ($data = @unserialize($GLOBALS['prefs']->getDefault('spam'))) { $ob->setSpamFolder($data['folder']); $ob->setSpamLevel($data['level']); } break; default: $ob = false; } return $ob; }
public function testWhitelist() { $wl = new Ingo_Storage_Whitelist(3); $wl->setWhitelist(array('*****@*****.**')); $this->storage->store($wl); $this->_assertScript(':0 * ^From:(.*\\<)?spammer@example\\.com $DEFAULT'); }
public function testWhitelist() { $wl = new Ingo_Storage_Whitelist(3); $wl->setWhitelist(array('*****@*****.**')); $this->storage->store($wl); $this->_assertScript('if( \\ /^From:\\s*.*spammer@example\\.com/:h \\ ) exception { to "${DEFAULT}" }'); }