Exemple #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;
 }
 /**
  * return values as array
  * 
  * @return array
  */
 public function toArray()
 {
     $conditions = array();
     foreach ($this->_conditions as $condition) {
         $conditions[] = $condition->toArray();
     }
     $action = $this->_action->toArray();
     return array('conditions' => $conditions, 'action_type' => $action['type'], 'action_argument' => $action['argument'], 'conjunction' => $this->_conjunction, 'enabled' => (int) $this->_enabled, 'id' => $this->_id);
 }
 /**
  * test enabled rule
  */
 public function testEnabledRule()
 {
     $script = new Felamimail_Sieve_Backend_Script();
     $rule = new Felamimail_Sieve_Rule();
     $condition = new Felamimail_Sieve_Rule_Condition();
     $action = new Felamimail_Sieve_Rule_Action();
     $condition->setComperator(Felamimail_Sieve_Rule_Condition::COMPERATOR_CONTAINS)->setTest(Felamimail_Sieve_Rule_Condition::TEST_ADDRESS)->setHeader('From')->setKey('info@example.com');
     $action->setType(Felamimail_Sieve_Rule_Action::FILEINTO)->setArgument('INBOX/UNITTEST');
     $rule->setEnabled(true)->setId(12)->setAction($action)->addCondition($condition);
     $script->addRule($rule);
     $sieveScript = $script->getSieve();
     #echo $sieveScript;
     $this->assertContains('if allof (address :contains "From" "info@example.com")', $sieveScript);
     $this->assertContains('fileinto "INBOX/UNITTEST";', $sieveScript);
     $this->assertContains('Felamimail_Sieve_Rule', $sieveScript);
 }
 /**
  * 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);
 }