示例#1
0
文件: Sieve.php 项目: DSNS-LAB/Dmail
 /**
  * Adds all blocks necessary for the vacation rule.
  */
 protected function _addVacationBlocks()
 {
     if (!$this->_validRule(Ingo_Storage::ACTION_VACATION)) {
         return;
     }
     $vacation = $this->_params['storage']->retrieve(Ingo_Storage::ACTION_VACATION);
     $vacation_addr = $vacation->getVacationAddresses();
     if (!count($vacation_addr)) {
         return;
     }
     $vals = array('subject' => $vacation->getVacationSubject(), 'days' => $vacation->getVacationDays(), 'addresses' => $vacation_addr, 'start' => $vacation->getVacationStart(), 'start_year' => $vacation->getVacationStartYear(), 'start_month' => $vacation->getVacationStartMonth(), 'start_day' => $vacation->getVacationStartDay(), 'end' => $vacation->getVacationEnd(), 'end_year' => $vacation->getVacationEndYear(), 'end_month' => $vacation->getVacationEndMonth(), 'end_day' => $vacation->getVacationEndDay(), 'reason' => $vacation->getVacationReason());
     $action = $tests = array();
     $action[] = new Ingo_Script_Sieve_Action_Vacation($vals);
     if ($vacation->getVacationIgnorelist()) {
         $mime_headers = new Horde_Mime_Headers();
         $headers = $mime_headers->listHeaders();
         $headers['Mailing-List'] = null;
         foreach (array_keys($headers) as $h) {
             $tests[] = new Ingo_Script_Sieve_Test_Not(new Ingo_Script_Sieve_Test_Exists(array('headers' => $h)));
         }
         $vals = array('headers' => 'Precedence', 'match-type' => ':is', 'strings' => "list\nbulk\njunk", 'comparator' => 'i;ascii-casemap');
         $tmp = new Ingo_Script_Sieve_Test_Header($vals);
         $tests[] = new Ingo_Script_Sieve_Test_Not($tmp);
         $vals = array('headers' => 'To', 'match-type' => ':matches', 'strings' => 'Multiple recipients of*', 'comparator' => 'i;ascii-casemap');
         $tmp = new Ingo_Script_Sieve_Test_Header($vals);
         $tests[] = new Ingo_Script_Sieve_Test_Not($tmp);
     }
     $addrs = array();
     foreach ($vacation->getVacationExcludes() as $addr) {
         $addr = trim($addr);
         if (!empty($addr)) {
             $addrs[] = $addr;
         }
     }
     if ($addrs) {
         $tmp = new Ingo_Script_Sieve_Test_Address(array('headers' => "From\nSender\nResent-From", 'addresses' => implode("\n", $addrs)));
         $tests[] = new Ingo_Script_Sieve_Test_Not($tmp);
     }
     $this->_addItem(Ingo::RULE_VACATION, new Ingo_Script_Sieve_Comment(_("Vacation")));
     if ($tests) {
         $test = new Ingo_Script_Sieve_Test_Allof($tests);
         $if = new Ingo_Script_Sieve_If($test);
         $if->setActions($action);
         $this->_addItem(Ingo::RULE_VACATION, $if);
     } else {
         $this->_addItem(Ingo::RULE_VACATION, $action[0]);
     }
 }