1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Prefs_Special_SpecialMboxes
24: {
25: const PREF_DEFAULT = "default\0";
26: const PREF_NO_MBOX = "nombox\0";
27: const PREF_SPECIALUSE = "specialuse\0";
28:
29: 30: 31: 32: 33:
34: protected $_cache = null;
35:
36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
47: protected function _updateSpecialMboxes($pref, $form, $new, $type,
48: Horde_Core_Prefs_Ui $ui)
49: {
50: global $injector, $prefs;
51:
52: $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
53:
54: if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS) ||
55: $prefs->isLocked($pref)) {
56: return false;
57: }
58:
59: $cache = $injector->getInstance('IMP_Mailbox_SessionCache');
60: if ($mbox_ob = IMP_Mailbox::getPref($pref)) {
61: $cache->expire(
62: array(
63: IMP_Mailbox_SessionCache::CACHE_DISPLAY,
64: IMP_Mailbox_SessionCache::CACHE_LABEL,
65: IMP_Mailbox_SessionCache::CACHE_SPECIALMBOXES
66: ),
67: $mbox_ob
68: );
69: }
70:
71: if ($form == self::PREF_NO_MBOX) {
72: return $prefs->setValue($pref, '');
73: }
74:
75: if (strpos($form, self::PREF_SPECIALUSE) === 0) {
76: $mbox = IMP_Mailbox::get(substr($form, strlen(self::PREF_SPECIALUSE)));
77: } elseif (!empty($new)) {
78: $mbox = IMP_Mailbox::get($new)->namespace_append;
79:
80: $opts = is_null($type)
81: ? array()
82: : array('special_use' => array($type));
83:
84: if (!$mbox->create($opts)) {
85: $mbox = null;
86: }
87: } else {
88: $mbox = $form;
89: }
90:
91: if (!$mbox) {
92: return false;
93: }
94:
95: $cache->expire(
96: array(
97: IMP_Mailbox_SessionCache::CACHE_DISPLAY,
98: IMP_Mailbox_SessionCache::CACHE_LABEL
99: ),
100: $mbox
101: );
102:
103: return $prefs->setValue($pref, $mbox->pref_to);
104: }
105:
106: 107: 108: 109: 110: 111: 112:
113: protected function _getSpecialUse($use)
114: {
115: global $injector;
116:
117: if (is_null($this->_cache)) {
118: $this->_cache = $injector->getInstance('IMP_Factory_Imap')->create()->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array(
119: 'attributes' => true,
120: 'special_use' => true,
121: 'sort' => true
122: ));
123: }
124:
125: $special_use = array();
126:
127: $use = Horde_String::lower($use);
128:
129: foreach ($this->_cache as $val) {
130: if (in_array($use, $val['attributes'])) {
131: $mbox_ob = IMP_Mailbox::get($val['mailbox']);
132: $special_use[] = array(
133: 'l' => $mbox_ob->label,
134: 'v' => IMP_Mailbox::formTo(self::PREF_SPECIALUSE . $mbox_ob)
135: );
136: }
137: }
138:
139: if (empty($special_use)) {
140: return '';
141: }
142:
143: $view = new Horde_View(array(
144: 'templatePath' => IMP_TEMPLATES . '/prefs'
145: ));
146: $view->addHelper('Text');
147:
148: $view->special_use = $special_use;
149:
150: return $view->render('specialuse');
151: }
152:
153: }
154: