Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 function testPartialBlacklistAddressShouldNotMatch()
 {
     $runner = ScriptTester::factory('all', $this);
     $bl = new Ingo_Storage_Blacklist();
     $bl->addAddresses('*****@*****.**');
     $runner->addRule($bl);
     $runner->assertKeepsMessage('from_spammer');
 }
Пример #3
0
 function test_partial_blacklist_address_should_not_match()
 {
     $runner = ScriptTester::factory('all', $this);
     $bl = new Ingo_Storage_Blacklist();
     $bl->setBlacklist(array('*****@*****.**'));
     $bl->setBlacklistFolder('');
     $runner->addRule($bl);
     $runner->assertKeepsMessage('from_spammer');
 }
Пример #4
0
    public function testBlacklistMarker()
    {
        $bl = new Ingo_Storage_Blacklist(3);
        $bl->setBlacklist(array('*****@*****.**'));
        $bl->setBlacklistFolder(Ingo::BLACKLIST_MARKER);
        $this->storage->store($bl);
        $this->_assertScript('require "imap4flags";
if address :all :comparator "i;ascii-casemap" :is ["From", "Sender", "Resent-From"] "*****@*****.**"  {
addflag ["\\\\Deleted"];
keep;
removeflag ["\\\\Deleted"];
stop;
}');
    }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 /**
  */
 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');
 }
Пример #7
0
    public function testBlacklistDiscard()
    {
        $bl = new Ingo_Storage_Blacklist(3);
        $bl->setBlacklist(array('*****@*****.**'));
        $bl->setBlacklistFolder(null);
        $this->storage->store($bl);
        $this->_assertScript(':0
* ^From:(.*\\<)?spammer@example\\.com
/dev/null');
    }
Пример #8
0
    public function testBlacklistDiscard()
    {
        $bl = new Ingo_Storage_Blacklist(3);
        $bl->setBlacklist(array('*****@*****.**'));
        $bl->setBlacklistFolder(null);
        $this->storage->store($bl);
        $this->_assertScript('if( \\
/^From:\\s*.*spammer@example\\.com/:h \\
)
exception {
exit
}');
    }