1: <?php
2: /**
3: * Copyright 2011-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2011-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Provides an interface to query a mailbox's settable permanent flags.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2011-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Imap_PermanentFlags implements IteratorAggregate
24: {
25: /* IMAP flag indicating flags can be created in mailbox. */
26: const CREATE = "\\*";
27:
28: /**
29: * Can new flags NOT be created?
30: *
31: * @var boolean
32: */
33: protected $_nocreate = false;
34:
35: /**
36: * List of unsettable flags.
37: *
38: * @var array
39: */
40: protected $_noset = array();
41:
42: /**
43: * List of settable flags.
44: *
45: * @var array
46: */
47: protected $_set = array();
48:
49: /**
50: * Constructor.
51: *
52: * @param array $permflags List of permanent flags in mailbox.
53: * @param array $flags List of flags in mailbox.
54: */
55: public function __construct(array $permflags = array(),
56: array $flags = array())
57: {
58: $this->_nocreate = !in_array(self::CREATE, $permflags);
59: $this->_noset = array_diff($permflags, $flags, array(self::CREATE));
60: $this->_set = array_intersect($permflags, $flags);
61: }
62:
63: /**
64: * Determines if the given flag is allowed to be changed permanently.
65: *
66: * @param string $flag The flag to query.
67: *
68: * @return boolean True if flag can be set permanently.
69: */
70: public function allowed($flag)
71: {
72: $flag = strtolower($flag);
73: return (!in_array($flag, $this->_noset) &&
74: (!$this->_nocreate || in_array($flag, $this->_set)));
75: }
76:
77: /* IteratorAggregate method. */
78:
79: public function getIterator()
80: {
81: return new ArrayIterator($this->_set);
82: }
83:
84: }
85: