1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: class IMP_Mailbox_List_Virtual extends IMP_Mailbox_List
25: {
26:
27: const IDX_SEP = "\0";
28:
29: 30: 31: 32: 33:
34: protected $_sortedMbox = array();
35:
36: 37:
38: protected function _buildMailboxQuery()
39: {
40: $this->_sortedMbox = array();
41: $imp_search = $GLOBALS['injector']->getInstance('IMP_Search');
42:
43: return $imp_search[strval($this->_mailbox)]->query;
44: }
45:
46: 47:
48: protected function _buildMailboxProcess($mbox, $sorted)
49: {
50: if (count($sorted)) {
51: $this->_sortedMbox = array_merge($this->_sortedMbox, array_fill(0, count($sorted), strval($mbox)));
52: }
53: }
54:
55: 56:
57: public function unseenMessages($results, array $opts = array())
58: {
59: $count = ($results == Horde_Imap_Client::SEARCH_RESULTS_COUNT);
60:
61: return ($count && $this->_mailbox->vinbox)
62: ? count($this)
63: : ($count ? 0 : array());
64: }
65:
66: 67:
68: public function mailboxStart($total)
69: {
70: return 1;
71: }
72:
73: 74:
75: public function getArrayIndex($uid, $mbox = null)
76: {
77: $this->_buildMailbox();
78:
79: 80:
81: foreach (array_keys($this->_sorted, $uid) as $key) {
82: if ($this->_sortedMbox[$key] == $mbox) {
83: return $key;
84: }
85: }
86:
87: return null;
88: }
89:
90: 91:
92: public function getIndicesOb()
93: {
94: $this->_buildMailbox();
95: $ob = new IMP_Indices();
96:
97: reset($this->_sorted);
98: while (list($k, $v) = each($this->_sorted)) {
99: $ob->add($this->_sortedMbox[$k], $v);
100: }
101:
102: return $ob;
103: }
104:
105: 106:
107: public function removeMsgs($indices)
108: {
109: if (!parent::removeMsgs($indices)) {
110: return false;
111: }
112:
113: foreach ($indices as $ob) {
114: foreach ($ob->uids as $uid) {
115: unset($this->_sortedMbox[$this->getArrayIndex($uid, $ob->mbox)]);
116: $idx = $ob->mbox . self::IDX_SEP . $uid;
117: if (($aindex = array_search($idx, $this->_buids)) !== false) {
118: unset($this->_buids[$aindex]);
119: }
120: }
121: }
122:
123: $this->_sortedMbox = array_values($this->_sortedMbox);
124:
125: return true;
126: }
127:
128: 129:
130: protected function _getMbox($id)
131: {
132: return IMP_Mailbox::get($this->_sortedMbox[$id]);
133: }
134:
135: 136:
137: public function getBuid($mbox, $uid)
138: {
139: $idx = $mbox . self::IDX_SEP . $uid;
140:
141: if (($aindex = array_search($idx, $this->_buids)) === false) {
142: $aindex = ++$this->_buidmax;
143: $this->_buids[$aindex] = $idx;
144: $this->changed = true;
145: }
146:
147: return $aindex;
148: }
149:
150: 151:
152: public function resolveBuid($buid)
153: {
154: if (!isset($this->_buids[$buid])) {
155: return null;
156: }
157:
158: $pos = strrpos($this->_buids[$buid], self::IDX_SEP);
159:
160: return array(
161: 'm' => IMP_Mailbox::get(substr($this->_buids[$buid], 0, $pos)),
162: 'u' => intval(substr($this->_buids[$buid], $pos + 1))
163: );
164: }
165:
166: 167:
168: protected function _serialize()
169: {
170: $data = parent::_serialize();
171:
172: if (!empty($this->_sortedMbox)) {
173: $data['som'] = $this->_sortedMbox;
174: }
175:
176: return $data;
177: }
178:
179: 180:
181: protected function _unserialize($data)
182: {
183: parent::_unserialize($data);
184:
185: if (isset($data['som'])) {
186: $this->_sortedMbox = $data['som'];
187: }
188: }
189:
190: }
191: