1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Ingo_Storage
13: {
14: 15: 16:
17: const COMBINE_ALL = 1;
18: const COMBINE_ANY = 2;
19:
20: 21: 22:
23: const ACTION_FILTERS = 0;
24: const ACTION_KEEP = 1;
25: const ACTION_MOVE = 2;
26: const ACTION_DISCARD = 3;
27: const ACTION_REDIRECT = 4;
28: const ACTION_REDIRECTKEEP = 5;
29: const ACTION_REJECT = 6;
30: const ACTION_BLACKLIST = 7;
31: const ACTION_VACATION = 8;
32: const ACTION_WHITELIST = 9;
33: const ACTION_FORWARD = 10;
34: const ACTION_MOVEKEEP = 11;
35: const ACTION_FLAGONLY = 12;
36: const ACTION_NOTIFY = 13;
37: const ACTION_SPAM = 14;
38:
39: 40: 41:
42: const FLAG_ANSWERED = 1;
43: const FLAG_DELETED = 2;
44: const FLAG_FLAGGED = 4;
45: const FLAG_SEEN = 8;
46:
47: 48: 49:
50: const = 1;
51: const TYPE_SIZE = 2;
52: const TYPE_BODY = 3;
53:
54: 55: 56: 57: 58:
59: protected $_params = array();
60:
61: 62: 63: 64: 65:
66: protected $_cache = array();
67:
68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79:
80: static public function factory($driver = null, $params = null)
81: {
82: if (is_null($driver)) {
83: $driver = $GLOBALS['conf']['storage']['driver'];
84: }
85:
86: $driver = basename($driver);
87:
88: if (is_null($params)) {
89: $params = Horde::getDriverConfig('storage', $driver);
90: }
91:
92: $class = 'Ingo_Storage_' . ucfirst($driver);
93: return class_exists($class)
94: ? new $class($params)
95: : false;
96: }
97:
98: 99: 100:
101: public function __construct()
102: {
103: register_shutdown_function(array($this, 'shutdown'));
104: }
105:
106: 107: 108:
109: public function shutdown()
110: {
111:
112: foreach ($this->_cache as $key => $val) {
113: if ($val['mod'] || !$GLOBALS['session']->exists('ingo', 'storage/' . $key)) {
114: $GLOBALS['session']->set('ingo', 'storage/' . $key, $GLOBALS['session']->store($val['ob'], false));
115: }
116: }
117: }
118:
119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129:
130: public function retrieve($field, $cache = true, $readonly = false)
131: {
132:
133: if ($cache && empty($GLOBALS['ingo_shares'])) {
134: if (!isset($this->_cache[$field])) {
135: $cached = $GLOBALS['session']->retrieve($GLOBALS['session']->get('ingo', 'storage/' . $field));
136: $this->_cache[$field] = array(
137: 'mod' => false,
138: 'ob' => $cached ? $cached : $this->_retrieve($field, $readonly)
139: );
140: }
141: $ob = $this->_cache[$field]['ob'];
142: } else {
143: $ob = $this->_retrieve($field, $readonly);
144: }
145:
146: return $ob;
147: }
148:
149: 150: 151: 152: 153: 154: 155: 156: 157:
158: protected function _retrieve($field, $readonly = false)
159: {
160: return false;
161: }
162:
163: 164: 165: 166: 167: 168: 169: 170:
171: public function store($ob, $cache = true)
172: {
173: $type = $ob->obType();
174: if (in_array($type, array(self::ACTION_BLACKLIST,
175: self::ACTION_VACATION,
176: self::ACTION_WHITELIST,
177: self::ACTION_FORWARD,
178: self::ACTION_SPAM))) {
179: $filters = $this->retrieve(self::ACTION_FILTERS);
180: if ($filters->findRuleId($type) === null) {
181: switch ($type) {
182: case self::ACTION_BLACKLIST:
183: $name = 'Blacklist';
184: break;
185:
186: case self::ACTION_VACATION:
187: $name = 'Vacation';
188: break;
189:
190: case self::ACTION_WHITELIST:
191: $name = 'Whitelist';
192: break;
193:
194: case self::ACTION_FORWARD:
195: $name = 'Forward';
196: break;
197:
198: case self::ACTION_SPAM:
199: $name = 'Spam Filter';
200: break;
201: }
202: $filters->addRule(array('action' => $type, 'name' => $name));
203: $this->store($filters, $cache);
204: }
205: }
206:
207: $this->_store($ob);
208: if ($cache) {
209: $this->_cache[$ob->obType()] = array('ob' => $ob, 'mod' => true);
210: }
211: }
212:
213: 214: 215: 216: 217:
218: protected function _store($ob)
219: {
220: }
221:
222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233:
234: public function getActionInfo($action)
235: {
236: $ob = new stdClass;
237: $ob->flags = false;
238: $ob->type = 'text';
239:
240: switch ($action) {
241: case self::ACTION_KEEP:
242: $ob->label = _("Deliver into my Inbox");
243: $ob->type = false;
244: $ob->flags = true;
245: break;
246:
247: case self::ACTION_MOVE:
248: $ob->label = _("Deliver to folder...");
249: $ob->type = 'folder';
250: $ob->flags = true;
251: break;
252:
253: case self::ACTION_DISCARD:
254: $ob->label = _("Delete message completely");
255: $ob->type = false;
256: break;
257:
258: case self::ACTION_REDIRECT:
259: $ob->label = _("Redirect to...");
260: break;
261:
262: case self::ACTION_REDIRECTKEEP:
263: $ob->label = _("Deliver into my Inbox and redirect to...");
264: $ob->flags = true;
265: break;
266:
267: case self::ACTION_MOVEKEEP:
268: $ob->label = _("Deliver into my Inbox and copy to...");
269: $ob->type = 'folder';
270: $ob->flags = true;
271: break;
272:
273: case self::ACTION_REJECT:
274: $ob->label = _("Reject with reason...");
275: break;
276:
277: case self::ACTION_FLAGONLY:
278: $ob->label = _("Only flag the message");
279: $ob->type = false;
280: $ob->flags = true;
281: break;
282:
283: case self::ACTION_NOTIFY:
284: $ob->label = _("Notify email address...");
285: break;
286: }
287:
288: return $ob;
289: }
290:
291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301:
302: public function getTestInfo($test)
303: {
304:
305: $labels = array(
306: 'contains' => _("Contains"),
307: 'not contain' => _("Doesn't contain"),
308: 'is' => _("Is"),
309: 'not is' => _("Isn't"),
310: 'begins with' => _("Begins with"),
311: 'not begins with' => _("Doesn't begin with"),
312: 'ends with' => _("Ends with"),
313: 'not ends with' => _("Doesn't end with"),
314: 'exists' => _("Exists"),
315: 'not exist' => _("Doesn't exist"),
316: 'regex' => _("Regular expression"),
317: 'matches' => _("Matches (with placeholders)"),
318: 'not matches' => _("Doesn't match (with placeholders)"),
319: 'less than' => _("Less than"),
320: 'less than or equal to' => _("Less than or equal to"),
321: 'greater than' => _("Greater than"),
322: 'greater than or equal to' => _("Greater than or equal to"),
323: 'equal' => _("Equal to"),
324: 'not equal' => _("Not equal to")
325: );
326:
327:
328: $types = array(
329: 'int' => array(
330: 'less than', 'less than or equal to', 'greater than',
331: 'greater than or equal to', 'equal', 'not equal'
332: ),
333: 'none' => array(
334: 'exists', 'not exist'
335: ),
336: 'text' => array(
337: 'contains', 'not contain', 'is', 'not is', 'begins with',
338: 'not begins with', 'ends with', 'not ends with', 'regex',
339: 'matches', 'not matches'
340: )
341: );
342:
343:
344: $ob = new stdClass;
345: $ob->label = $labels[$test];
346: foreach ($types as $key => $val) {
347: if (in_array($test, $val)) {
348: $ob->type = $key;
349: break;
350: }
351: }
352:
353: return $ob;
354: }
355:
356: 357: 358: 359: 360: 361: 362: 363:
364: public function removeUserData($user)
365: {
366: throw new Ingo_Exception(_("Removing user data is not supported with the current filter storage backend."));
367: }
368:
369: }
370: