commit | author | age
|
566747
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| This file is part of the Roundcube Webmail client | |
|
6 |
| Copyright (C) 2005-2011, The Roundcube Dev Team | |
|
7 |
| Copyright (C) 2011, Kolab Systems AG | |
|
8 |
| | |
|
9 |
| Licensed under the GNU General Public License version 3 or | |
|
10 |
| any later version with exceptions for skins & plugins. | |
|
11 |
| See the README file for a full license statement. | |
|
12 |
| | |
|
13 |
| PURPOSE: | |
|
14 |
| SORT/SEARCH/ESEARCH response handler | |
|
15 |
+-----------------------------------------------------------------------+ |
|
16 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
17 |
+-----------------------------------------------------------------------+ |
|
18 |
*/ |
|
19 |
|
|
20 |
/** |
|
21 |
* Class holding a set of rcube_result_index instances that together form a |
|
22 |
* result set of a multi-folder search |
|
23 |
* |
|
24 |
* @package Framework |
|
25 |
* @subpackage Storage |
|
26 |
*/ |
|
27 |
class rcube_result_multifolder |
|
28 |
{ |
|
29 |
public $multi = true; |
|
30 |
public $sets = array(); |
|
31 |
|
|
32 |
protected $meta = array(); |
|
33 |
protected $order = 'ASC'; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* Object constructor. |
|
38 |
*/ |
|
39 |
public function __construct() |
|
40 |
{ |
|
41 |
$this->meta = array('count' => 0); |
|
42 |
} |
|
43 |
|
|
44 |
|
|
45 |
/** |
|
46 |
* Initializes object with SORT command response |
|
47 |
* |
|
48 |
* @param string $data IMAP response string |
|
49 |
*/ |
|
50 |
public function add($result) |
|
51 |
{ |
|
52 |
$this->sets[] = $result; |
|
53 |
$this->meta['count'] += $result->count(); |
|
54 |
} |
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* Checks the result from IMAP command |
|
59 |
* |
|
60 |
* @return bool True if the result is an error, False otherwise |
|
61 |
*/ |
|
62 |
public function is_error() |
|
63 |
{ |
|
64 |
return false; |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
/** |
|
69 |
* Checks if the result is empty |
|
70 |
* |
|
71 |
* @return bool True if the result is empty, False otherwise |
|
72 |
*/ |
|
73 |
public function is_empty() |
|
74 |
{ |
|
75 |
return empty($this->sets) || $this->meta['count'] == 0; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
/** |
|
80 |
* Returns number of elements in the result |
|
81 |
* |
|
82 |
* @return int Number of elements |
|
83 |
*/ |
|
84 |
public function count() |
|
85 |
{ |
|
86 |
return $this->meta['count']; |
|
87 |
} |
|
88 |
|
|
89 |
|
|
90 |
/** |
|
91 |
* Returns number of elements in the result. |
|
92 |
* Alias for count() for compatibility with rcube_result_thread |
|
93 |
* |
|
94 |
* @return int Number of elements |
|
95 |
*/ |
|
96 |
public function count_messages() |
|
97 |
{ |
|
98 |
return $this->count(); |
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
/** |
|
103 |
* Reverts order of elements in the result |
|
104 |
*/ |
|
105 |
public function revert() |
|
106 |
{ |
|
107 |
$this->order = $this->order == 'ASC' ? 'DESC' : 'ASC'; |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
/** |
|
112 |
* Check if the given message ID exists in the object |
|
113 |
* |
|
114 |
* @param int $msgid Message ID |
|
115 |
* @param bool $get_index When enabled element's index will be returned. |
|
116 |
* Elements are indexed starting with 0 |
|
117 |
* @return mixed False if message ID doesn't exist, True if exists or |
|
118 |
* index of the element if $get_index=true |
|
119 |
*/ |
|
120 |
public function exists($msgid, $get_index = false) |
|
121 |
{ |
|
122 |
return false; |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
/** |
|
127 |
* Filters data set. Removes elements listed in $ids list. |
|
128 |
* |
|
129 |
* @param array $ids List of IDs to remove. |
|
130 |
* @param string $folder IMAP folder |
|
131 |
*/ |
|
132 |
public function filter($ids = array(), $folder = null) |
|
133 |
{ |
|
134 |
$this->meta['count'] = 0; |
|
135 |
foreach ($this->sets as $set) { |
|
136 |
if ($set->get_parameters('MAILBOX') == $folder) { |
|
137 |
$set->filter($ids); |
|
138 |
} |
|
139 |
$this->meta['count'] += $set->count(); |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Filters data set. Removes elements not listed in $ids list. |
|
145 |
* |
|
146 |
* @param array $ids List of IDs to keep. |
|
147 |
*/ |
|
148 |
public function intersect($ids = array()) |
|
149 |
{ |
|
150 |
// not implemented |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* Return all messages in the result. |
|
155 |
* |
|
156 |
* @return array List of message IDs |
|
157 |
*/ |
|
158 |
public function get() |
|
159 |
{ |
|
160 |
return array(); |
|
161 |
} |
|
162 |
|
|
163 |
|
|
164 |
/** |
|
165 |
* Return all messages in the result. |
|
166 |
* |
|
167 |
* @return array List of message IDs |
|
168 |
*/ |
|
169 |
public function get_compressed() |
|
170 |
{ |
|
171 |
return ''; |
|
172 |
} |
|
173 |
|
|
174 |
|
|
175 |
/** |
|
176 |
* Return result element at specified index |
|
177 |
* |
|
178 |
* @param int|string $index Element's index or "FIRST" or "LAST" |
|
179 |
* |
|
180 |
* @return int Element value |
|
181 |
*/ |
|
182 |
public function get_element($index) |
|
183 |
{ |
|
184 |
return null; |
|
185 |
} |
|
186 |
|
|
187 |
|
|
188 |
/** |
|
189 |
* Returns response parameters, e.g. ESEARCH's MIN/MAX/COUNT/ALL/MODSEQ |
|
190 |
* or internal data e.g. MAILBOX, ORDER |
|
191 |
* |
|
192 |
* @param string $param Parameter name |
|
193 |
* |
|
194 |
* @return array|string Response parameters or parameter value |
|
195 |
*/ |
|
196 |
public function get_parameters($param=null) |
|
197 |
{ |
|
198 |
return $params; |
|
199 |
} |
|
200 |
|
|
201 |
|
|
202 |
/** |
|
203 |
* Returns length of internal data representation |
|
204 |
* |
|
205 |
* @return int Data length |
|
206 |
*/ |
|
207 |
protected function length() |
|
208 |
{ |
|
209 |
return $this->count(); |
|
210 |
} |
|
211 |
} |