Ejemplo n.º 1
0
 /**
  */
 protected function _retrieve($field, $readonly = false)
 {
     if (empty($this->_data[$field])) {
         switch ($field) {
             case self::ACTION_BLACKLIST:
                 return new Ingo_Storage_Blacklist();
             case self::ACTION_FILTERS:
                 $ob = new Ingo_Storage_Filters();
                 include INGO_BASE . '/config/prefs.php';
                 $ob->setFilterList(unserialize($_prefs['rules']['value']));
                 return $ob;
             case self::ACTION_FORWARD:
                 return new Ingo_Storage_Forward();
             case self::ACTION_VACATION:
                 return new Ingo_Storage_VacationTest();
             case self::ACTION_WHITELIST:
                 return new Ingo_Storage_Whitelist();
             case self::ACTION_SPAM:
                 return new Ingo_Storage_Spam();
             default:
                 return false;
         }
     }
     return $this->_data[$field];
 }
Ejemplo n.º 2
0
 /**
  * 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;
     }
 }
Ejemplo n.º 3
0
 /**
  * Stores the specified data.
  *
  * @param Ingo_Storage_Rule|Ingo_Storage_Filters $ob  The object to store.
  *
  * @throws Ingo_Exception
  */
 public function store($ob)
 {
     global $session;
     switch ($type = $ob->obType()) {
         case self::ACTION_BLACKLIST:
             $name = 'Blacklist';
             break;
         case self::ACTION_VACATION:
             $name = 'Vacation';
             break;
         case self::ACTION_WHITELIST:
             $name = 'Whitelist';
             break;
         case self::ACTION_FORWARD:
             $name = 'Forward';
             break;
         case self::ACTION_SPAM:
             $name = 'Spam Filter';
             break;
         default:
             $name = null;
             break;
     }
     if (!is_null($name) && ($filters = $this->retrieve(self::ACTION_FILTERS)) && $filters->findRuleId($type) === null) {
         $filters->addRule(array('action' => $type, 'name' => $name));
         $this->store($filters);
     }
     $this->_store($ob);
     $this->_cache[$type] = $ob;
     $session->set('ingo', 'change', time());
 }
Ejemplo n.º 4
0
 /**
  * @param mixed $max
  * @param Ingo_Storage_Filters $filters
  */
 protected function _assertMaxRules($max, $filters)
 {
     if ($max !== true && $max <= count($filters->getFilterList())) {
         Horde::permissionDeniedError('ingo', 'max_rules', sprintf(_("You are not allowed to create more than %d rules."), $max));
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  */
 public function sort($rules)
 {
     $old = $this->_filters;
     parent::sort($rules);
     $query = sprintf('UPDATE %s SET rule_order = ? WHERE rule_id = ?', $this->_params['table_rules']);
     $this->_db->beginDbTransaction();
     try {
         foreach ($this->_filters as $key => $val) {
             $this->_db->update($query, array($key, $val['id']));
         }
     } catch (Horde_Db_Exception $e) {
         $this->_db->rollbackDbTransaction();
         $this->_filters = $old;
         throw new Ingo_Exception($e);
     }
     $this->_db->commitDbTransaction();
 }
Ejemplo n.º 6
0
 /**
  * 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;
     }
 }