Overview

Packages

  • Horde
    • Icalendar
      • UnitTests
  • Ingo
    • UnitTests
  • None

Classes

  • Horde_Core_Ui_VarRenderer_Ingo
  • Ingo
  • Ingo_Api
  • Ingo_Exception
  • Ingo_Exception_Pear
  • Ingo_LoginTasks_SystemTask_Upgrade
  • Ingo_Script
  • Ingo_Script_Imap
  • Ingo_Script_Imap_Api
  • Ingo_Script_Imap_Live
  • Ingo_Script_Maildrop
  • Ingo_Script_Maildrop_Comment
  • Ingo_Script_Maildrop_Recipe
  • Ingo_Script_Maildrop_Variable
  • Ingo_Script_Procmail
  • Ingo_Script_Procmail_Comment
  • Ingo_Script_Procmail_Recipe
  • Ingo_Script_Procmail_Variable
  • Ingo_Script_Sieve
  • Ingo_Script_Sieve_Action
  • Ingo_Script_Sieve_Action_Addflag
  • Ingo_Script_Sieve_Action_Discard
  • Ingo_Script_Sieve_Action_Fileinto
  • Ingo_Script_Sieve_Action_Flag
  • Ingo_Script_Sieve_Action_Keep
  • Ingo_Script_Sieve_Action_Notify
  • Ingo_Script_Sieve_Action_Redirect
  • Ingo_Script_Sieve_Action_Reject
  • Ingo_Script_Sieve_Action_Removeflag
  • Ingo_Script_Sieve_Action_Stop
  • Ingo_Script_Sieve_Action_Vacation
  • Ingo_Script_Sieve_Comment
  • Ingo_Script_Sieve_Else
  • Ingo_Script_Sieve_Elsif
  • Ingo_Script_Sieve_If
  • Ingo_Script_Sieve_Test
  • Ingo_Script_Sieve_Test_Address
  • Ingo_Script_Sieve_Test_Allof
  • Ingo_Script_Sieve_Test_Anyof
  • Ingo_Script_Sieve_Test_Body
  • Ingo_Script_Sieve_Test_Exists
  • Ingo_Script_Sieve_Test_False
  • Ingo_Script_Sieve_Test_Header
  • Ingo_Script_Sieve_Test_Not
  • Ingo_Script_Sieve_Test_Relational
  • Ingo_Script_Sieve_Test_Size
  • Ingo_Script_Sieve_Test_True
  • Ingo_Storage
  • Ingo_Storage_Blacklist
  • Ingo_Storage_Filters
  • Ingo_Storage_Filters_Sql
  • Ingo_Storage_Forward
  • Ingo_Storage_Mock
  • Ingo_Storage_Prefs
  • Ingo_Storage_Rule
  • Ingo_Storage_Spam
  • Ingo_Storage_Sql
  • Ingo_Storage_Vacation
  • Ingo_Storage_VacationTest
  • Ingo_Storage_Whitelist
  • Ingo_Test
  • Ingo_Transport
  • Ingo_Transport_Ldap
  • Ingo_Transport_Null
  • Ingo_Transport_Sivtest
  • Ingo_Transport_Timsieved
  • Ingo_Transport_Vfs
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Ingo_Script_Sieve_Action_Vacation class represents a vacation action.
  4:  *
  5:  * See the enclosed file LICENSE for license information (ASL).  If you
  6:  * did not receive this file, see http://www.horde.org/licenses/apache.
  7:  *
  8:  * @author  Mike Cochrane <mike@graftonhall.co.nz>
  9:  * @package Ingo
 10:  */
 11: class Ingo_Script_Sieve_Action_Vacation extends Ingo_Script_Sieve_Action
 12: {
 13:     /**
 14:      * Constructor.
 15:      *
 16:      * @param array $vars  Any required parameters.
 17:      */
 18:     public function __construct($vars = array())
 19:     {
 20:         $this->_vars = array_merge(array(
 21:             'days' => '',
 22:             'addresses' => '',
 23:             'subject' => '',
 24:             'reason' => '',
 25:             'start' => '',
 26:             'start_year' => '',
 27:             'start_month' => '',
 28:             'start_day' => '',
 29:             'end' => '',
 30:             'end_year' => '',
 31:             'end_month' => '',
 32:             'end_day' => ''
 33:         ), $vars);
 34:     }
 35: 
 36:     /**
 37:      * Returns a script snippet representing this rule and any sub-rules.
 38:      *
 39:      * @return string  A Sieve script snippet.
 40:      */
 41:     public function toCode()
 42:     {
 43:         $start_year = $this->_vars['start_year'];
 44:         $start_month = $this->_vars['start_month'];
 45:         $start_day = $this->_vars['start_day'];
 46: 
 47:         $end_year = $this->_vars['end_year'];
 48:         $end_month = $this->_vars['end_month'];
 49:         $end_day = $this->_vars['end_day'];
 50: 
 51:         $code = '';
 52: 
 53:         if (empty($this->_vars['start']) || empty($this->_vars['end'])) {
 54:             return $this->_vacationCode();
 55:         } elseif ($end_year > $start_year + 1) {
 56:             $code .= $this->_yearCheck($start_year + 1, $end_year - 1)
 57:                 . $this->_vacationCode()
 58:                 . "\n}\n"
 59:                 . $this->_yearCheck($start_year, $start_year);
 60:             if ($start_month < 12) {
 61:                 $code .= $this->_monthCheck($start_month + 1, 12)
 62:                     . $this->_vacationCode()
 63:                     . "\n}\n";
 64:             }
 65:             $code .= $this->_monthCheck($start_month, $start_month)
 66:                 . $this->_dayCheck($start_day, 31)
 67:                 . $this->_vacationCode()
 68:                 . "\n}\n}\n}\n"
 69:                 . $this->_yearCheck($end_year, $end_year);
 70:             if ($end_month > 1) {
 71:                 $code .= $this->_monthCheck(1, $end_month - 1)
 72:                     . $this->_vacationCode()
 73:                     . "\n}\n";
 74:             }
 75:             $code .= $this->_monthCheck($end_month, $end_month)
 76:                 . $this->_dayCheck(1, $end_day)
 77:                 . $this->_vacationCode()
 78:                 . "\n}\n}\n}\n";
 79:         } elseif ($end_year == $start_year + 1) {
 80:             $code .= $this->_yearCheck($start_year, $start_year);
 81:             if ($start_month < 12) {
 82:                 $code .= $this->_monthCheck($start_month + 1, 12)
 83:                     . $this->_vacationCode()
 84:                     . "\n}\n";
 85:             }
 86:             $code .= $this->_monthCheck($start_month, $start_month)
 87:                 . $this->_dayCheck($start_day, 31)
 88:                 . $this->_vacationCode()
 89:                 . "\n}\n}\n}\n"
 90:                 . $this->_yearCheck($end_year, $end_year);
 91:             if ($end_month > 1) {
 92:                 $code .= $this->_monthCheck(1, $end_month - 1)
 93:                     . $this->_vacationCode()
 94:                     . "\n}\n";
 95:             }
 96:             $code .= $this->_monthCheck($end_month, $end_month)
 97:                 . $this->_dayCheck(1, $end_day)
 98:                 . $this->_vacationCode()
 99:                 . "\n}\n}\n}\n";
100:         } elseif ($end_year == $start_year) {
101:             $code .= $this->_yearCheck($start_year, $start_year);
102:             if ($end_month > $start_month) {
103:                 if ($end_month > $start_month + 1) {
104:                     $code .= $this->_monthCheck($start_month + 1, $end_month - 1)
105:                         . $this->_vacationCode()
106:                         . "\n}\n";
107:                 }
108:                 $code .= $this->_monthCheck($start_month, $start_month)
109:                     . $this->_dayCheck($start_day, 31)
110:                     . $this->_vacationCode()
111:                     . "\n}\n}\n"
112:                     . $this->_monthCheck($end_month, $end_month)
113:                     . $this->_dayCheck(1, $end_day)
114:                     . $this->_vacationCode()
115:                     . "\n}\n}\n";
116:             } elseif ($end_month == $start_month) {
117:                 $code .= $this->_monthCheck($start_month, $start_month)
118:                     . $this->_dayCheck($start_day, $end_day)
119:                     . $this->_vacationCode()
120:                     . "\n}\n}\n";
121:             }
122:             $code .= "}\n";
123:         }
124: 
125:         return $code;
126:     }
127: 
128:     /**
129:      * Checks if the rule parameters are valid.
130:      *
131:      * @return boolean|string  True if this rule is valid, an error message
132:      *                         otherwise.
133:      */
134:     public function check()
135:     {
136:         return empty($this->_vars['reason'])
137:             ? _("Missing reason in vacation.")
138:             : true;
139:     }
140: 
141:     /**
142:      * Returns a list of sieve extensions required for this rule and any
143:      * sub-rules.
144:      *
145:      * @return array  A Sieve extension list.
146:      */
147:     public function requires()
148:     {
149:         return array('vacation', 'regex');
150:     }
151: 
152:     /**
153:      */
154:     protected function _vacationCode()
155:     {
156:         $code = 'vacation :days ' . $this->_vars['days'] . ' ';
157:         $addresses = $this->_vars['addresses'];
158:         $stringlist = '';
159:         if (count($addresses) > 1) {
160:             foreach ($addresses as $address) {
161:                 $address = trim($address);
162:                 if (!empty($address)) {
163:                     $stringlist .= empty($stringlist) ? '"' : ', "';
164:                     $stringlist .= Ingo_Script_Sieve::escapeString($address) . '"';
165:                 }
166:             }
167:             $stringlist = "[" . $stringlist . "] ";
168:         } elseif (count($addresses) == 1) {
169:             $stringlist = '"' . Ingo_Script_Sieve::escapeString($addresses[0]) . '" ';
170:         }
171: 
172:         if (!empty($stringlist)) {
173:             $code .= ':addresses ' . $stringlist;
174:         }
175: 
176:         if (!empty($this->_vars['subject'])) {
177:             $code .= ':subject "' . Horde_Mime::encode(Ingo_Script_Sieve::escapeString($this->_vars['subject']), 'UTF-8') . '" ';
178:         }
179:         return $code
180:             . '"' . Ingo_Script_Sieve::escapeString($this->_vars['reason'])
181:             . '";';
182:     }
183: 
184:     /**
185:      */
186:     protected function _yearCheck($begin, $end)
187:     {
188:         $code = 'if header :regex "Received" "^.*(' . $begin;
189:         for ($i = $begin + 1; $i <= $end; $i++) {
190:             $code .= '|' . $i;
191:         }
192:         return $code
193:             . ') (\\\\(.*\\\\) )?..:..:.. (\\\\(.*\\\\) )?((\\\\+|\\\\-)[[:digit:]]{4}|.{1,5})( \\\\(.*\\\\))?$" {'
194:             . "\n    ";
195:     }
196: 
197:     /**
198:      */
199:     protected function _monthCheck($begin, $end)
200:     {
201:         $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
202:                         'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
203:         $code = 'if header :regex "Received" "^.*(' . $months[$begin - 1];
204:         for ($i = $begin + 1; $i <= $end; $i++) {
205:             $code .= '|' . $months[$i - 1];
206:         }
207:         return $code
208:             . ') (\\\\(.*\\\\) )?.... (\\\\(.*\\\\) )?..:..:.. (\\\\(.*\\\\) )?((\\\\+|\\\\-)[[:digit:]]{4}|.{1,5})( \\\\(.*\\\\))?$" {'
209:             . "\n    ";
210:     }
211: 
212:     /**
213:      */
214:     protected function _dayCheck($begin, $end)
215:     {
216:         $code = 'if header :regex "Received" "^.*(' . str_repeat('[0 ]', 2 - strlen($begin)) . $begin;
217:         for ($i = $begin + 1; $i <= $end; $i++) {
218:             $code .= '|' . str_repeat('[0 ]', 2 - strlen($i)) . $i;
219:         }
220:         return $code
221:             . ') (\\\\(.*\\\\) )?... (\\\\(.*\\\\) )?.... (\\\\(.*\\\\) )?..:..:.. (\\\\(.*\\\\) )?((\\\\+|\\\\-)[[:digit:]]{4}|.{1,5})( \\\\(.*\\\\))?$" {'
222:             . "\n    ";
223:     }
224: 
225: }
226: 
API documentation generated by ApiGen