Beispiel #1
0
 /**
  * get sieve rule object
  * 
  * @return Felamimail_Sieve_Rule
  */
 public function getFSR()
 {
     $fsr = new Felamimail_Sieve_Rule();
     $fsr->setEnabled($this->enabled)->setId($this->id);
     $fsra = new Felamimail_Sieve_Rule_Action();
     $fsra->setType($this->action_type)->setArgument($this->action_argument);
     $fsr->setAction($fsra);
     foreach ($this->conditions as $condition) {
         $fsrc = new Felamimail_Sieve_Rule_Condition();
         $fsrc->setTest($condition['test'])->setComperator($condition['comperator'])->setHeader($condition['header'])->setKey($condition['key']);
         $fsr->addCondition($fsrc);
     }
     return $fsr;
 }
 /**
  * parse rule generated by SmartSieve
  * 
  * @param   array   $parts
  */
 protected function _parseSmartSieveRule(array $parts)
 {
     $rule = new Felamimail_Sieve_Rule();
     $rule->setId($parts[1])->setEnabled($parts[2] == 'ENABLED' ? true : false);
     // conditions
     // from test
     if (!empty($parts[3])) {
         $condition = new Felamimail_Sieve_Rule_Condition();
         $condition->setTest(Felamimail_Sieve_Rule_Condition::TEST_ADDRESS)->setComperator(Felamimail_Sieve_Rule_Condition::COMPERATOR_CONTAINS)->setHeader('from')->setKey($this->_unescapeChars($parts[3]));
         $rule->addCondition($condition);
     }
     // to test
     if (!empty($parts[4])) {
         $condition = new Felamimail_Sieve_Rule_Condition();
         $condition->setTest(Felamimail_Sieve_Rule_Condition::TEST_ADDRESS)->setComperator(Felamimail_Sieve_Rule_Condition::COMPERATOR_CONTAINS)->setHeader(array('to', 'cc'))->setKey($this->_unescapeChars($parts[4]));
         $rule->addCondition($condition);
     }
     // subject test
     if (!empty($parts[5])) {
         $condition = new Felamimail_Sieve_Rule_Condition();
         $condition->setTest(Felamimail_Sieve_Rule_Condition::TEST_HEADER)->setComperator(Felamimail_Sieve_Rule_Condition::COMPERATOR_CONTAINS)->setHeader('subject')->setKey($this->_unescapeChars($parts[5]));
         $rule->addCondition($condition);
     }
     // header test
     if (!empty($parts[9])) {
         $condition = new Felamimail_Sieve_Rule_Condition();
         $condition->setTest(Felamimail_Sieve_Rule_Condition::TEST_HEADER)->setComperator(Felamimail_Sieve_Rule_Condition::COMPERATOR_CONTAINS)->setHeader($this->_unescapeChars($parts[9]))->setKey($this->_unescapeChars($parts[10]));
         $rule->addCondition($condition);
     }
     // size
     if (!empty($parts[11])) {
         $condition = new Felamimail_Sieve_Rule_Condition();
         $condition->setTest(Felamimail_Sieve_Rule_Condition::TEST_SIZE)->setComperator(Felamimail_Sieve_Rule_Condition::COMPERATOR_OVER)->setKey($this->_unescapeChars($parts[11]));
         $rule->addCondition($condition);
     }
     // action
     $action = new Felamimail_Sieve_Rule_Action();
     switch ($this->_unescapeChars($parts[6])) {
         case 'folder':
             $action->setType(Felamimail_Sieve_Rule_Action::FILEINTO)->setArgument($this->_unescapeChars($parts[7]));
             break;
         case 'address':
             $action->setType(Felamimail_Sieve_Rule_Action::REDIRECT)->setArgument($this->_unescapeChars($parts[7]));
             break;
         case 'reject':
             $action->setType(Felamimail_Sieve_Rule_Action::REJECT)->setArgument($this->_unescapeChars($parts[7]));
             break;
         case 'discard':
             $action->setType(Felamimail_Sieve_Rule_Action::DISCARD);
             break;
     }
     $rule->setAction($action);
     //parts[8] == regex bit
     $this->addRule($rule);
 }