59177427 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
62f7daa5 |
4 | * mailbox_display.php |
5 | * |
6 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This contains functions that display mailbox information, such as the |
10 | * table row that has sender, date, subject, etc... |
11 | * |
12 | * @version $Id$ |
13 | * @package squirrelmail |
14 | */ |
a4c2cd49 |
15 | |
d6c32258 |
16 | /** The standard includes.. */ |
b68edc75 |
17 | require_once(SM_PATH . 'functions/strings.php'); |
18 | require_once(SM_PATH . 'functions/html.php'); |
19 | require_once(SM_PATH . 'class/html.class.php'); |
20 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
26454147 |
21 | require_once(SM_PATH . 'functions/imap_messages.php'); |
324ac3c5 |
22 | require_once(SM_PATH . 'functions/imap_asearch.php'); |
26454147 |
23 | require_once(SM_PATH . 'functions/mime.php'); |
b531f8ea |
24 | require_once(SM_PATH . 'functions/forms.php'); |
43fdb2a4 |
25 | |
d6c32258 |
26 | /** |
62f7daa5 |
27 | * default value for page_selector_max |
28 | */ |
6c930ade |
29 | define('PG_SEL_MAX', 10); |
30 | |
324ac3c5 |
31 | /** |
62f7daa5 |
32 | * The number of pages to cache msg headers |
33 | */ |
324ac3c5 |
34 | define('SQM_MAX_PAGES_IN_CACHE',5); |
35 | |
8cc8ec79 |
36 | /** |
62f7daa5 |
37 | * Sort constants used for sorting of messages |
38 | */ |
03975a39 |
39 | define('SQSORT_NONE',0); |
40 | define('SQSORT_DATE_ASC',1); |
41 | define('SQSORT_DATE_DEC',2); |
42 | define('SQSORT_FROM_ASC',3); |
43 | define('SQSORT_FROM_DEC',4); |
44 | define('SQSORT_SUBJ_ASC',5); |
45 | define('SQSORT_SUBJ_DEC',6); |
46 | define('SQSORT_SIZE_ASC',7); |
47 | define('SQSORT_SIZE_DEC',8); |
48 | define('SQSORT_TO_ASC',9); |
49 | define('SQSORT_TO_DEC',10); |
50 | define('SQSORT_CC_ASC',11); |
51 | define('SQSORT_CC_DEC',12); |
52 | define('SQSORT_INT_DATE_ASC',13); |
53 | define('SQSORT_INT_DATE_DEC',14); |
324ac3c5 |
54 | |
55 | define('SQSORT_THREAD',32); |
56 | |
57 | |
58 | define('MBX_PREF_SORT',0); |
59 | define('MBX_PREF_LIMIT',1); |
60 | define('MBX_PREF_AUTO_EXPUNGE',2); |
61 | define('MBX_PREF_INTERNALDATE',3); |
62 | define('SQM_MAX_MBX_IN_CACHE',3); |
63 | // define('MBX_PREF_FUTURE',unique integer key); |
64 | |
d6c32258 |
65 | /** |
62f7daa5 |
66 | * @param mixed $start UNDOCUMENTED |
67 | */ |
0fdc2fb6 |
68 | function elapsed($start) { |
69 | |
70 | $end = microtime(); |
71 | list($start2, $start1) = explode(" ", $start); |
72 | list($end2, $end1) = explode(" ", $end); |
73 | $diff1 = $end1 - $start1; |
74 | $diff2 = $end2 - $start2; |
75 | if( $diff2 < 0 ){ |
76 | $diff1 -= 1; |
77 | $diff2 += 1.0; |
78 | } |
79 | return $diff2 + $diff1; |
098ea084 |
80 | } |
81 | |
c7df3f1b |
82 | /** |
62f7daa5 |
83 | * Displays message header row in messages list |
84 | * |
85 | * @param array $aMsg contains all message related parameters |
86 | * @return void |
87 | */ |
0fdc2fb6 |
88 | |
8cc8ec79 |
89 | function printMessageInfo($aMsg) { |
e0e30169 |
90 | // FIX ME, remove these globals as well by adding an array as argument for the user settings |
91 | // specificly meant for header display |
8008456a |
92 | global $checkall, |
e0e30169 |
93 | $color, |
0fdc2fb6 |
94 | $default_use_priority, |
95 | $message_highlight_list, |
96 | $index_order, |
9294e269 |
97 | $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */ |
0fdc2fb6 |
98 | $email_address, |
9294e269 |
99 | $show_recipient_instead, /* show recipient name instead of default identity */ |
100 | $use_icons, /* indicates to use icons or text markers */ |
101 | $icon_theme; /* icons theming */ |
459e3347 |
102 | |
e9e5f0fa |
103 | $color_string = $color[4]; |
8008456a |
104 | |
03975a39 |
105 | // initialisation: |
8cc8ec79 |
106 | $mailbox = $aMsg['MAILBOX']; |
107 | $msg = $aMsg['HEADER']; |
108 | $t = $aMsg['INDX']; |
109 | $start_msg = $aMsg['PAGEOFFSET']; |
110 | $last = $aMsg['LAST']; |
111 | if (isset($aMsg['SEARCH']) && count($aMsg['SEARCH']) >1 ) { |
112 | $where = $aMsg['SEARCH'][0]; |
113 | $what = $aMsg['SEARCH'][1]; |
114 | } else { |
115 | $where = false; |
116 | $what = false; |
117 | } |
e0e30169 |
118 | $iIndent = $aMsg['INDENT']; |
8cc8ec79 |
119 | |
120 | $sSubject = (isset($msg['SUBJECT']) && $msg['SUBJECT'] != '') ? $msg['SUBJECT'] : _("(no subject)"); |
121 | $sFrom = (isset($msg['FROM'])) ? $msg['FROM'] : _("Unknown sender"); |
122 | $sTo = (isset($msg['TO'])) ? $msg['TO'] : _("Unknown recipient"); |
123 | $sCc = (isset($msg['CC'])) ? $msg['CC'] : ''; |
124 | $aFlags = (isset($msg['FLAGS'])) ? $msg['FLAGS'] : array(); |
125 | $iPrio = (isset($msg['PRIORITY'])) ? $msg['PRIORITY'] : 3; |
126 | $iSize = (isset($msg['SIZE'])) ? $msg['SIZE'] : 0; |
8d8da447 |
127 | |
128 | // These don't appear to be used... are they safe to remove |
8cc8ec79 |
129 | $sType0 = (isset($msg['TYPE0'])) ? $msg['TYPE0'] : 'text'; |
130 | $sType1 = (isset($msg['TYPE1'])) ? $msg['TYPE1'] : 'plain'; |
e0e30169 |
131 | if (isset($msg['INTERNALDATE'])) { |
132 | $sDate = getDateString(getTimeStamp(explode(' ',$msg['INTERNALDATE']))); |
133 | } else { |
134 | $sDate = (isset($msg['DATE'])) ? getDateString(getTimeStamp(explode(' ',$msg['DATE']))) : ''; |
135 | } |
324ac3c5 |
136 | $iId = (isset($msg['UID'])) ? $msg['UID'] : false; |
8cc8ec79 |
137 | |
8cc8ec79 |
138 | if (!$iId) { |
139 | return; |
140 | } |
03975a39 |
141 | |
8008456a |
142 | if ($GLOBALS['alt_index_colors']) { |
e0e30169 |
143 | if (!($t % 2)) { |
8008456a |
144 | if (!isset($color[12])) { |
145 | $color[12] = '#EAEAEA'; |
146 | } |
147 | $color_string = $color[12]; |
148 | } |
bdfb67f8 |
149 | } |
8008456a |
150 | |
8008456a |
151 | $urlMailbox = urlencode($mailbox); |
e9e5f0fa |
152 | |
e0e30169 |
153 | // FIXME, foldertype should be set in right_main.php |
154 | // in other words, handle as sent is obsoleted from now. |
155 | // We replace that by providing an array to aMailbox with the to shown headers |
156 | // that way we are free to show the user different layouts for different folders |
53ad5f60 |
157 | $bSentFolder = handleAsSent($mailbox); |
1ae2832e |
158 | if ((!$bSentFolder) && ($show_recipient_instead)) { |
159 | // If the From address is the same as $email_address, then handle as Sent |
03975a39 |
160 | $from_array = parseAddress($sFrom, 1); |
1ae2832e |
161 | if (!isset($email_address)) { |
0bb37159 |
162 | global $data_dir, $username; |
163 | $email_address = getPref($data_dir, $username, 'email_address'); |
1ae2832e |
164 | } |
165 | $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address)); |
8cc8ec79 |
166 | } else { |
1ae2832e |
167 | $bHandleAsSent = $bSentFolder; |
8cc8ec79 |
168 | } |
53ad5f60 |
169 | // If this is a Sent message, display To address instead of From |
03975a39 |
170 | if ($bHandleAsSent) { |
171 | $sFrom = $sTo; |
172 | } |
53ad5f60 |
173 | // Passing 1 below results in only 1 address being parsed, thus defeating the following code |
03975a39 |
174 | $sFrom = parseAddress($sFrom/*,1*/); |
9701e9c8 |
175 | |
0fdc2fb6 |
176 | /* |
e9e5f0fa |
177 | * This is done in case you're looking into Sent folders, |
178 | * because you can have multiple receivers. |
179 | */ |
03975a39 |
180 | $senderNames = $sFrom; |
098ea084 |
181 | $senderName = ''; |
26454147 |
182 | $senderAddress = ''; |
098ea084 |
183 | if (sizeof($senderNames)){ |
184 | foreach ($senderNames as $senderNames_part) { |
e9e5f0fa |
185 | if ($senderName != '') { |
186 | $senderName .= ', '; |
26454147 |
187 | $senderAddress .= ', '; |
e9e5f0fa |
188 | } |
26454147 |
189 | $sender_address_part = htmlspecialchars($senderNames_part[0]); |
53ad5f60 |
190 | $sender_name_part = str_replace(' ',' ', decodeHeader($senderNames_part[1])); |
26454147 |
191 | if ($sender_name_part) { |
192 | $senderName .= $sender_name_part; |
193 | $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>'; |
098ea084 |
194 | } else { |
26454147 |
195 | $senderName .= $sender_address_part; |
196 | $senderAddress .= $sender_address_part; |
098ea084 |
197 | } |
198 | } |
937c81fa |
199 | } |
53ad5f60 |
200 | // If Sent, prefix with To: but only if not Sent folder |
201 | if ($bHandleAsSent ^ $bSentFolder) { |
48027e89 |
202 | $senderName = _("To") . ': ' . $senderName; |
203 | $senderAddress = _("To") . ': ' . $senderAddress; |
53ad5f60 |
204 | } |
459e3347 |
205 | |
e0e30169 |
206 | // this is a column property which can apply to multiple columns. Do not use vars for one column |
207 | // only. instead we should use something like this: |
208 | // 1ed column $aMailbox['columns']['SUBJECT'] value: aray with properties ... |
209 | // 2ed column $aMailbox['columns']['FROM'] value: aray with properties ... |
210 | // NB in case of the sentfolder this could be the TO field |
211 | // properties array example: |
212 | // 'truncate' => length (0 is no truncate) |
213 | // 'prefix => if (x in b then do that ) |
8cc8ec79 |
214 | if ($truncate_sender > 0) { |
215 | $senderName = truncateWithEntities($senderName, $truncate_sender); |
bdfb67f8 |
216 | } |
8cc8ec79 |
217 | |
8d8da447 |
218 | $flag = $flag_end = $fontstr = $fontstr_end = $italic = $italic_end = ''; |
8cc8ec79 |
219 | $bold = '<b>'; |
220 | $bold_end = '</b>'; |
221 | |
8cc8ec79 |
222 | foreach ($aFlags as $sFlag => $value) { |
223 | switch ($sFlag) { |
224 | case '\\flagged': |
225 | if ($value) { |
226 | $flag = "<font color=\"$color[2]\">"; |
227 | $flag_end = '</font>'; |
228 | } |
229 | break; |
230 | case '\\seen': |
231 | if ($value) { |
232 | $bold = ''; |
233 | $bold_end = ''; |
234 | } |
235 | break; |
236 | case '\\deleted': |
237 | if ($value) { |
238 | $fontstr = "<font color=\"$color[9]\">"; |
239 | $fontstr_end = '</font>'; |
240 | } |
241 | break; |
242 | } |
bdfb67f8 |
243 | } |
53ad5f60 |
244 | if ($bHandleAsSent) { |
8008456a |
245 | $italic = '<i>'; |
246 | $italic_end = '</i>'; |
8008456a |
247 | } |
248 | |
d215ca7d |
249 | if ($where && $what) { |
250 | $searchstr = '&where='.$where.'&what='.$what; |
251 | } else { |
252 | $searchstr = ''; |
6a622b59 |
253 | } |
8cc8ec79 |
254 | /* |
255 | * Message highlight code |
256 | */ |
3667f469 |
257 | $matches = array('TO' => 'sTo', 'CC' => 'sCc', 'FROM' => 'sFrom', 'SUBJECT' => 'sSubject'); |
937c81fa |
258 | if (is_array($message_highlight_list) && count($message_highlight_list)) { |
03975a39 |
259 | $sTo = parseAddress($sTo); |
260 | $sCc = parseAddress($sCc); |
8008456a |
261 | foreach ($message_highlight_list as $message_highlight_list_part) { |
262 | if (trim($message_highlight_list_part['value']) != '') { |
c0d04f97 |
263 | $high_val = strtolower($message_highlight_list_part['value']); |
264 | $match_type = strtoupper($message_highlight_list_part['match_type']); |
8415b2d3 |
265 | if($match_type == 'TO_CC') { |
266 | $match = array('TO', 'CC'); |
267 | } else { |
268 | $match = array($match_type); |
269 | } |
270 | foreach($match as $match_type) { |
271 | switch($match_type) { |
272 | case('TO'): |
273 | case('CC'): |
274 | case('FROM'): |
3667f469 |
275 | foreach ($$matches[$match_type] as $address) { |
9701e9c8 |
276 | $address[0] = decodeHeader($address[0], true, false); |
277 | $address[1] = decodeHeader($address[1], true, false); |
8415b2d3 |
278 | if (strstr('^^' . strtolower($address[0]), $high_val) || |
279 | strstr('^^' . strtolower($address[1]), $high_val)) { |
280 | $hlt_color = $message_highlight_list_part['color']; |
281 | break 4; |
282 | } |
937c81fa |
283 | } |
937c81fa |
284 | break; |
8415b2d3 |
285 | default: |
3667f469 |
286 | $headertest = strtolower(decodeHeader($$matches[$match_type], true, false)); |
9701e9c8 |
287 | if (strstr('^^' . $headertest, $high_val)) { |
937c81fa |
288 | $hlt_color = $message_highlight_list_part['color']; |
4669e892 |
289 | break 3; |
937c81fa |
290 | } |
8415b2d3 |
291 | break; |
292 | } |
8008456a |
293 | } |
294 | } |
295 | } |
8cc8ec79 |
296 | } /* end Message highlight code */ |
8008456a |
297 | |
298 | if (!isset($hlt_color)) { |
299 | $hlt_color = $color_string; |
300 | } |
5e0efebf |
301 | $col = 0; |
03975a39 |
302 | $sSubject = str_replace(' ', ' ', decodeHeader($sSubject)); |
e0e30169 |
303 | $subject = processSubject($sSubject, $iIndent); |
8cc8ec79 |
304 | |
e1728a7a |
305 | echo html_tag( 'tr','','','','valign="top"') . "\n"; |
8cc8ec79 |
306 | |
6a622b59 |
307 | if (sizeof($index_order)) { |
8008456a |
308 | foreach ($index_order as $index_order_part) { |
309 | switch ($index_order_part) { |
310 | case 1: /* checkbox */ |
311 | echo html_tag( 'td', |
03975a39 |
312 | addCheckBox("msg[$t]", $checkall, $iId), |
0fdc2fb6 |
313 | 'center', |
314 | $hlt_color ); |
8008456a |
315 | break; |
316 | case 2: /* from */ |
26454147 |
317 | if ($senderAddress != $senderName) { |
318 | $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS))); |
319 | $title = ' title="' . str_replace('"', "''", $senderAddress) . '"'; |
8cc8ec79 |
320 | } else { |
26454147 |
321 | $title = ''; |
8cc8ec79 |
322 | } |
8008456a |
323 | echo html_tag( 'td', |
0fdc2fb6 |
324 | $italic . $bold . $flag . $fontstr . $senderName . |
325 | $fontstr_end . $flag_end . $bold_end . $italic_end, |
326 | 'left', |
327 | $hlt_color, $title ); |
8008456a |
328 | break; |
329 | case 3: /* date */ |
03975a39 |
330 | if ($sDate == '') { |
331 | $sDate = _("Unknown date"); |
53d9fbc5 |
332 | } |
8008456a |
333 | echo html_tag( 'td', |
03975a39 |
334 | $bold . $flag . $fontstr . $sDate . |
0fdc2fb6 |
335 | $fontstr_end . $flag_end . $bold_end, |
336 | 'center', |
337 | $hlt_color, |
338 | 'nowrap' ); |
8008456a |
339 | break; |
340 | case 4: /* subject */ |
341 | $td_str = $bold; |
e0e30169 |
342 | if ($iIndent) { |
343 | $td_str .= str_repeat(" ",$iIndent); |
8008456a |
344 | } |
e9e5f0fa |
345 | $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox |
324ac3c5 |
346 | . '&passed_id='. $iId |
6a622b59 |
347 | . '&startMessage='.$start_msg.$searchstr.'"'; |
158fa340 |
348 | $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr)); |
03975a39 |
349 | if ($subject != $sSubject) { |
8008456a |
350 | $title = get_html_translation_table(HTML_SPECIALCHARS); |
351 | $title = array_flip($title); |
03975a39 |
352 | $title = strtr($sSubject, $title); |
8008456a |
353 | $title = str_replace('"', "''", $title); |
354 | $td_str .= " title=\"$title\""; |
355 | } |
356 | $td_str .= ">$flag$subject$flag_end</a>$bold_end"; |
c1c17724 |
357 | echo html_tag( 'td', $td_str, 'left', $hlt_color ); |
8008456a |
358 | break; |
359 | case 5: /* flags */ |
6a622b59 |
360 | |
6395c46d |
361 | // icon message markers |
362 | // |
363 | if ($use_icons && $icon_theme != 'none') { |
364 | $td_str = "<b><small>"; |
03975a39 |
365 | if (isset($aFlags['\\flagged']) && $aFlags['\\flagged'] == true) { |
55103ede |
366 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/flagged.png" border="0" height="10" width="10" /> '; |
6395c46d |
367 | } |
368 | if ($default_use_priority) { |
03975a39 |
369 | if ( ($iPrio == 1) || ($iPrio == 2) ) { |
55103ede |
370 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/prio_high.png" border="0" height="10" width="5" /> '; |
6395c46d |
371 | } |
03975a39 |
372 | else if ($iPrio == 5) { |
55103ede |
373 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/prio_low.png" border="0" height="10" width="5" /> '; |
6395c46d |
374 | } |
0fdc2fb6 |
375 | else { |
55103ede |
376 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="5" /> '; |
6395c46d |
377 | } |
378 | } |
03975a39 |
379 | if ($sType1 == 'mixed') { |
55103ede |
380 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/attach.png" border="0" height="10" width="6" />'; |
0fdc2fb6 |
381 | } else { |
55103ede |
382 | $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="6" />'; |
6395c46d |
383 | } |
384 | |
385 | $msg_icon = ''; |
03975a39 |
386 | if (!isset($aFlags['\\seen']) || ($aFlags['\\seen']) == false) { |
6395c46d |
387 | $msg_alt = '(' . _("New") . ')'; |
388 | $msg_title = '(' . _("New") . ')'; |
389 | $msg_icon .= SM_PATH . 'images/themes/' . $icon_theme . '/msg_new'; |
0fdc2fb6 |
390 | } else { |
6395c46d |
391 | $msg_alt = '(' . _("Read") . ')'; |
392 | $msg_title = '(' . _("Read") . ')'; |
393 | $msg_icon .= SM_PATH . 'images/themes/' . $icon_theme . '/msg_read'; |
394 | } |
03975a39 |
395 | if (isset($aFlags['\\deleted']) && ($aFlags['\\deleted']) == true) { |
6395c46d |
396 | $msg_icon .= '_deleted'; |
397 | } |
03975a39 |
398 | if (isset($aFlags['\\answered']) && ($aFlags['\\answered']) == true) { |
d3685401 |
399 | $msg_alt = '(' . _("Answered") . ')'; |
400 | $msg_title = '(' . _("Answered") . ')'; |
6395c46d |
401 | $msg_icon .= '_reply'; |
402 | } |
55103ede |
403 | $td_str .= '<img src="' . $msg_icon . '.png" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" />'; |
6395c46d |
404 | $td_str .= '</small></b>'; |
405 | echo html_tag( 'td', |
0fdc2fb6 |
406 | $td_str, |
407 | 'right', |
408 | $hlt_color, |
409 | 'nowrap' ); |
8008456a |
410 | } |
6395c46d |
411 | |
6395c46d |
412 | // plain text message markers |
413 | // |
414 | else { |
415 | $stuff = false; |
416 | $td_str = "<b><small>"; |
03975a39 |
417 | if (isset($aFlags['\\answered']) && $aFlags['\\answered'] == true) { |
6395c46d |
418 | $td_str .= _("A"); |
8008456a |
419 | $stuff = true; |
420 | } |
03975a39 |
421 | if ($sType1 == 'mixed') { |
6395c46d |
422 | $td_str .= '+'; |
8008456a |
423 | $stuff = true; |
424 | } |
6395c46d |
425 | if ($default_use_priority) { |
03975a39 |
426 | if ( ($iPrio == 1) || ($iPrio == 2) ) { |
6395c46d |
427 | $td_str .= "<font color=\"$color[1]\">!</font>"; |
428 | $stuff = true; |
429 | } |
03975a39 |
430 | if ($iPrio == 5) { |
6395c46d |
431 | $td_str .= "<font color=\"$color[8]\">?</font>"; |
432 | $stuff = true; |
433 | } |
434 | } |
03975a39 |
435 | if (isset($aFlags['\\deleted']) && $aFlags['\\deleted'] == true) { |
6395c46d |
436 | $td_str .= "<font color=\"$color[1]\">D</font>"; |
437 | $stuff = true; |
438 | } |
439 | if (!$stuff) { |
440 | $td_str .= ' '; |
441 | } |
442 | $td_str .= '</small></b>'; |
443 | echo html_tag( 'td', |
0fdc2fb6 |
444 | $td_str, |
445 | 'center', |
446 | $hlt_color, |
447 | 'nowrap' ); |
8008456a |
448 | } |
8008456a |
449 | break; |
450 | case 6: /* size */ |
8008456a |
451 | echo html_tag( 'td', |
03975a39 |
452 | $bold . $fontstr . show_readable_size($iSize) . |
0fdc2fb6 |
453 | $fontstr_end . $bold_end, |
454 | 'right', |
455 | $hlt_color ); |
8008456a |
456 | break; |
457 | } |
ed230bc3 |
458 | ++$col; |
8008456a |
459 | } |
bdfb67f8 |
460 | } |
8cc8ec79 |
461 | /* html for separationlines between rows */ |
1c198ef7 |
462 | if ($last) { |
463 | echo '</tr>'."\n"; |
464 | } else { |
55103ede |
465 | echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' . |
0fdc2fb6 |
466 | $color[0] . '" height="1"></td></tr>' . "\n"; |
6a622b59 |
467 | } |
e9e5f0fa |
468 | } |
469 | |
324ac3c5 |
470 | |
471 | function setUserPref($username, $pref, $value) { |
472 | global $data_dir; |
473 | setPref($data_dir,$username,$pref,$value); |
474 | } |
475 | |
476 | /** |
477 | * Selects a mailbox for header retrieval. |
478 | * Cache control for message headers is embedded. |
479 | * |
480 | * @param resource $imapConnection imap socket handle |
481 | * @param string $mailbox mailbox to select and retrieve message headers from |
482 | * @param array $aConfig array with system config settings and incoming vars |
483 | * @param array $aProps mailbox specific properties |
484 | * @return array $aMailbox mailbox array with all relevant information |
485 | * @author Marc Groot Koerkamp |
486 | */ |
487 | function sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aProps) { |
488 | /** |
489 | * NB: retrieve this from the session before accessing this function |
490 | * and make sure you write it back at the end of the script after |
491 | * the aMailbox var is added so that the headers are added to the cache |
492 | */ |
493 | global $mailbox_cache; |
494 | /** |
495 | * In case the properties arrays are empty set the defaults. |
496 | */ |
8d8da447 |
497 | // Doesn't appear to be used... safe to remove? |
324ac3c5 |
498 | $aDefaultMbxPref = array (); |
499 | // MBX_PREF_SORT => 0, |
500 | // MBX_PREF_LIMIT => 15, |
501 | // MBX_PREF_AUTO_EXPUNGE => 0, |
502 | // MBX_PREF_INTERNALDATE => 0 |
503 | // ); |
504 | /* array_merge doesn't work with integers as keys */ |
505 | // foreach ($aDefaultMbxPref as $key => $value) { |
506 | // if (!isset($aProps[$key])) { |
507 | // $aProps[$key] = $value; |
508 | // } |
509 | // } |
510 | $aDefaultConfigProps = array( |
511 | // 'allow_thread_sort' => 0, |
512 | 'allow_server_sort' => sqimap_capability($imapConnection,'SORT'), |
513 | // 'charset' => 'US-ASCII', |
514 | 'user' => false, /* no pref storage if false */ |
515 | 'setindex' => 0, |
516 | // 'search' => 'ALL', |
517 | 'max_cache_size' => SQM_MAX_MBX_IN_CACHE |
518 | ); |
519 | |
520 | $aConfig = array_merge($aDefaultConfigProps,$aConfig); |
521 | $iSetIndx = $aConfig['setindex']; |
522 | |
523 | $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox); |
524 | |
525 | if ($mailbox_cache) { |
526 | if (isset($mailbox_cache[$mailbox])) { |
527 | $aCachedMailbox = $mailbox_cache[$mailbox]; |
528 | } else { |
529 | $aCachedMailbox = false; |
530 | } |
531 | /* cleanup cache */ |
532 | if (count($mailbox_cache) > $aConfig['max_cache_size'] -1) { |
533 | $aTime = array(); |
534 | foreach($mailbox_cache as $cachedmailbox => $aVal) { |
535 | $aTime[$aVal['TIMESTAMP']] = $cachedmailbox; |
536 | } |
537 | if (ksort($aTime,SORT_NUMERIC)) { |
538 | for ($i=0,$iCnt=count($mailbox_cache);$i<($iCnt-$aConfig['max_cache_size']);++$i) { |
539 | $sOldestMbx = array_shift($aTime); |
540 | /** |
541 | * Remove only the UIDSET and MSG_HEADERS from cache because those can |
542 | * contain large amounts of data. |
543 | */ |
544 | if (isset($mailbox_cache[$sOldestMbx]['UIDSET'])) { |
545 | $mailbox_cache[$sOldestMbx]['UIDSET']= false; |
546 | } |
547 | if (isset($mailbox_cache[$sOldestMbx]['MSG_HEADERS'])) { |
548 | $mailbox_cache[$sOldestMbx]['MSG_HEADERS'] = false; |
549 | } |
550 | } |
551 | } |
552 | } |
553 | |
554 | } else { |
555 | $aCachedMailbox = false; |
556 | } |
557 | |
558 | /** |
559 | * Deal with imap servers that do not return the required UIDNEXT or |
560 | * UIDVALIDITY response |
561 | * from a SELECT call (since rfc 3501 it's required). |
562 | */ |
563 | if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) { |
564 | $aStatus = sqimap_status_messages($imapConnection,$mailbox, |
565 | array('UIDNEXT','UIDVALIDITY')); |
566 | $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT']; |
567 | $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY']; |
568 | } |
569 | |
570 | $aMailbox['UIDSET'][$iSetIndx] = false; |
571 | $aMailbox['ID'] = false; |
572 | $aMailbox['SETINDEX'] = $iSetIndx; |
573 | |
574 | if ($aCachedMailbox) { |
575 | /** |
576 | * Validate integrity of cached data |
577 | */ |
578 | if ($aCachedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] && |
579 | $aMbxResponse['EXISTS'] && |
580 | $aCachedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] && |
581 | $aCachedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT'] && |
582 | isset($aCachedMailbox['SEARCH'][$iSetIndx]) && |
583 | (!isset($aConfig['search']) || /* always set search from the searchpage */ |
584 | $aCachedMailbox['SEARCH'][$iSetIndx] == $aConfig['search'])) { |
585 | if (isset($aCachedMailbox['MSG_HEADERS'])) { |
586 | $aMailbox['MSG_HEADERS'] = $aCachedMailbox['MSG_HEADERS']; |
587 | } |
588 | $aMailbox['ID'] = $aCachedMailbox['ID']; |
589 | if (isset($aCachedMailbox['UIDSET'][$iSetIndx]) && $aCachedMailbox['UIDSET'][$iSetIndx]) { |
590 | if (isset($aProps[MBX_PREF_SORT]) && $aProps[MBX_PREF_SORT] != $aCachedMailbox['SORT'] ) { |
591 | $newsort = $aProps[MBX_PREF_SORT]; |
592 | $oldsort = $aCachedMailbox['SORT']; |
593 | /** |
594 | * If it concerns a reverse sort we do not need to invalidate |
595 | * the cached sorted UIDSET, a reverse is sufficient. |
596 | */ |
597 | if ((($newsort % 2) && ($newsort + 1 == $oldsort)) || |
598 | (!($newsort % 2) && ($newsort - 1 == $oldsort))) { |
599 | $aMailbox['UIDSET'][$iSetIndx] = array_reverse($aCachedMailbox['UIDSET'][$iSetIndx]); |
600 | } else { |
324ac3c5 |
601 | $aMailbox['MSG_HEADERS'] = false; |
602 | $aMailbox['ID'] = false; |
603 | } |
604 | // store the new sort value in the mailbox pref |
605 | if ($aConfig['user']) { |
606 | // FIXME, in ideal situation, we write back the |
607 | // prefs at the end of the script |
608 | setUserPref($aConfig['user'],"pref_$mailbox",serialize($aProps)); |
609 | } |
610 | } else { |
611 | $aMailbox['UIDSET'][$iSetIndx] = $aCachedMailbox['UIDSET'][$iSetIndx]; |
612 | } |
613 | } |
614 | } |
615 | } |
616 | /** |
617 | * Restore the offset in the paginator if no new offset is provided. |
618 | */ |
619 | if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['offset']) && $aCachedMailbox['OFFSET']) { |
620 | $aMailbox['OFFSET'] = $aCachedMailbox['OFFSET']; |
621 | $aMailbox['PAGEOFFSET'] = $aCachedMailbox['PAGEOFFSET']; |
622 | } else { |
623 | $aMailbox['OFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ? $aConfig['offset'] -1 : 0; |
624 | $aMailbox['PAGEOFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ? $aConfig['offset'] : 1; |
625 | } |
626 | |
627 | /** |
628 | * Restore the showall value no new showall value is provided. |
629 | */ |
630 | if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['showall']) && |
631 | isset($aCachedMailbox['SHOWALL'][$iSetIndx]) && $aCachedMailbox['SHOWALL'][$iSetIndx]) { |
632 | $aMailbox['SHOWALL'][$iSetIndx] = $aCachedMailbox['SHOWALL'][$iSetIndx]; |
633 | } else { |
634 | $aMailbox['SHOWALL'][$iSetIndx] = (isset($aConfig['showall']) && $aConfig['showall']) ? 1 : 0; |
635 | } |
636 | |
637 | if (!isset($aProps[MBX_PREF_SORT]) && isset($aCachedMailbox['SORT'])) { |
638 | $aMailbox['SORT'] = $aCachedMailbox['SORT']; |
639 | } else { |
640 | $aMailbox['SORT'] = (isset($aProps[MBX_PREF_SORT])) ? $aProps[MBX_PREF_SORT] : 0; |
641 | } |
642 | |
643 | if (!isset($aProps[MBX_PREF_LIMIT]) && isset($aCachedMailbox['LIMIT'])) { |
644 | $aMailbox['LIMIT'] = $aCachedMailbox['LIMIT']; |
645 | } else { |
646 | $aMailbox['LIMIT'] = (isset($aProps[MBX_PREF_LIMIT])) ? $aProps[MBX_PREF_LIMIT] : 15; |
647 | } |
648 | |
649 | if (!isset($aProps[MBX_PREF_INTERNALDATE]) && isset($aCachedMailbox['INTERNALDATE'])) { |
650 | $aMailbox['INTERNALDATE'] = $aCachedMailbox['INTERNALDATE']; |
651 | } else { |
652 | $aMailbox['INTERNALDATE'] = (isset($aProps[MBX_PREF_INTERNALDATE])) ? $aProps[MBX_PREF_INTERNALDATE] : false; |
653 | } |
654 | |
655 | if (!isset($aProps[MBX_PREF_AUTO_EXPUNGE]) && isset($aCachedMailbox['AUTO_EXPUNGE'])) { |
656 | $aMailbox['AUTO_EXPUNGE'] = $aCachedMailbox['AUTO_EXPUNGE']; |
657 | } else { |
658 | $aMailbox['AUTO_EXPUNGE'] = (isset($aProps[MBX_PREF_AUTO_EXPUNGE])) ? $aProps[MBX_PREF_AUTO_EXPUNGE] : false; |
659 | } |
660 | |
661 | if (!isset($aConfig['allow_thread_sort']) && isset($aCachedMailbox['ALLOW_THREAD'])) { |
662 | $aMailbox['ALLOW_THREAD'] = $aCachedMailbox['ALLOW_THREAD']; |
663 | } else { |
664 | $aMailbox['ALLOW_THREAD'] = (isset($aConfig['allow_thread_sort'])) ? $aConfig['allow_thread_sort'] : false; |
665 | } |
666 | |
667 | if (!isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx])) { |
668 | $aMailbox['SEARCH'][$iSetIndx] = $aCachedMailbox['SEARCH'][$iSetIndx]; |
669 | } else { |
670 | $aMailbox['SEARCH'][$iSetIndx] = (isset($aConfig['search'])) ? $aConfig['search'] : 'ALL'; |
671 | } |
672 | |
673 | if (!isset($aConfig['charset']) && isset($aCachedMailbox['CHARSET'][$iSetIndx])) { |
674 | $aMailbox['CHARSET'][$iSetIndx] = $aCachedMailbox['CHARSET'][$iSetIndx]; |
675 | } else { |
676 | $aMailbox['CHARSET'][$iSetIndx] = (isset($aConfig['charset'])) ? $aConfig['charset'] : 'US-ASCII'; |
677 | } |
678 | |
679 | $aMailbox['NAME'] = $mailbox; |
680 | $aMailbox['EXISTS'] = $aMbxResponse['EXISTS']; |
681 | $aMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ? $aMbxResponse['SEEN'] : $aMbxResponse['EXISTS']; |
682 | $aMailbox['RECENT'] = (isset($aMbxResponse['RECENT'])) ? $aMbxResponse['RECENT'] : 0; |
683 | $aMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY']; |
684 | $aMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT']; |
685 | $aMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS']; |
686 | $aMailbox['RIGHTS'] = $aMbxResponse['RIGHTS']; |
687 | |
688 | |
689 | |
690 | /* decide if we are thread sorting or not */ |
691 | if (!$aMailbox['ALLOW_THREAD']) { |
692 | if ($aMailbox['SORT'] & SQSORT_THREAD) { |
693 | $aMailbox['SORT'] -= SQSORT_THREAD; |
694 | } |
695 | } |
696 | if ($aMailbox['SORT'] & SQSORT_THREAD) { |
697 | $aMailbox['SORT_METHOD'] = 'THREAD'; |
698 | $aMailbox['THREAD_INDENT'] = $aCachedMailbox['THREAD_INDENT']; |
699 | } else if (isset($aConfig['allow_server_sort']) && $aConfig['allow_server_sort']) { |
700 | $aMailbox['SORT_METHOD'] = 'SERVER'; |
701 | $aMailbox['THREAD_INDENT'] = false; |
702 | } else { |
703 | $aMailbox['SORT_METHOD'] = 'SQUIRREL'; |
704 | $aMailbox['THREAD_INDENT'] = false; |
705 | } |
706 | |
707 | /* set a timestamp for cachecontrol */ |
708 | $aMailbox['TIMESTAMP'] = time(); |
709 | return $aMailbox; |
710 | } |
711 | |
712 | |
713 | |
c7df3f1b |
714 | /** |
62f7daa5 |
715 | * Does the $srt $_GET var to field mapping |
716 | * |
717 | * @param int $srt Field to sort on |
718 | * @param bool $bServerSort Server sorting is true |
719 | * @return string $sSortField Field to sort on |
720 | */ |
03975a39 |
721 | function getSortField($sort,$bServerSort) { |
722 | switch($sort) { |
723 | case SQSORT_NONE: |
724 | $sSortField = 'UID'; |
725 | break; |
726 | case SQSORT_DATE_ASC: |
727 | case SQSORT_DATE_DEC: |
728 | $sSortField = 'DATE'; |
729 | break; |
730 | case SQSORT_FROM_ASC: |
731 | case SQSORT_FROM_DEC: |
732 | $sSortField = 'FROM'; |
733 | break; |
734 | case SQSORT_SUBJ_ASC: |
735 | case SQSORT_SUBJ_DEC: |
736 | $sSortField = 'SUBJECT'; |
737 | break; |
738 | case SQSORT_SIZE_ASC: |
739 | case SQSORT_SIZE_DEC: |
740 | $sSortField = ($bServerSort) ? 'SIZE' : 'RFC822.SIZE'; |
741 | break; |
742 | case SQSORT_TO_ASC: |
743 | case SQSORT_TO_DEC: |
744 | $sSortField = 'TO'; |
745 | break; |
746 | case SQSORT_CC_ASC: |
747 | case SQSORT_CC_DEC: |
748 | $sSortField = 'CC'; |
749 | break; |
750 | case SQSORT_INT_DATE_ASC: |
751 | case SQSORT_INT_DATE_DEC: |
752 | $sSortField = ($bServerSort) ? 'ARRIVAL' : 'INTERNALDATE'; |
753 | break; |
e0e30169 |
754 | case SQSORT_THREAD: |
03975a39 |
755 | break; |
e0e30169 |
756 | default: $sSortField = 'UID'; |
757 | break; |
758 | |
fe6efa94 |
759 | } |
03975a39 |
760 | return $sSortField; |
e9e5f0fa |
761 | } |
762 | |
324ac3c5 |
763 | function get_sorted_msgs_list($imapConnection,&$aMailbox,&$error) { |
764 | $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0; |
e0e30169 |
765 | $bDirection = ($aMailbox['SORT'] % 2); |
03975a39 |
766 | $error = false; |
324ac3c5 |
767 | if (!$aMailbox['SEARCH'][$iSetIndx]) { |
768 | $aMailbox['SEARCH'][$iSetIndx] = 'ALL'; |
769 | } |
e0e30169 |
770 | switch ($aMailbox['SORT_METHOD']) { |
8cc8ec79 |
771 | case 'THREAD': |
324ac3c5 |
772 | $aRes = get_thread_sort($imapConnection,$aMailbox['SEARCH'][$iSetIndx]); |
773 | if ($aRes === false) { |
03975a39 |
774 | $error = '<b><small><center><font color=red>' . |
ce45831c |
775 | _("Thread sorting is not supported by your IMAP server.") . '<br />' . |
d3b3a524 |
776 | _("Please contact your system administrator and report this error.") . |
ce45831c |
777 | '</center></small></b>'; |
324ac3c5 |
778 | $aMailbox['SORT'] -= SQSORT_THREAD; |
779 | } else { |
780 | $aMailbox['UIDSET'][$iSetIndx] = $aRes[0]; |
781 | $aMailbox['THREAD_INDENT'][$iSetIndx] = $aRes[1]; |
03975a39 |
782 | } |
783 | break; |
8cc8ec79 |
784 | case 'SERVER': |
e0e30169 |
785 | $sSortField = getSortField($aMailbox['SORT'],true); |
324ac3c5 |
786 | $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection, $aMailbox['SEARCH'][$iSetIndx]); |
03975a39 |
787 | if ($id === false) { |
788 | $error = '<b><small><center><font color=red>' . |
ce45831c |
789 | _("Server-side sorting is not supported by your IMAP server.") . '<br />' . |
d3b3a524 |
790 | _("Please contact your system administrator and report this error.") . |
03975a39 |
791 | '</center></small></b>'; |
324ac3c5 |
792 | } else { |
793 | $aMailbox['UIDSET'][$iSetIndx] = $id; |
83cdc70b |
794 | } |
03975a39 |
795 | break; |
796 | default: |
324ac3c5 |
797 | $id = NULL; |
798 | if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') { |
799 | $id = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]); |
800 | } |
e0e30169 |
801 | $sSortField = getSortField($aMailbox['SORT'],false); |
324ac3c5 |
802 | $aMailbox['UIDSET'][$iSetIndx] = get_squirrel_sort($imapConnection, $sSortField, $bDirection, $id); |
03975a39 |
803 | break; |
e9e5f0fa |
804 | } |
324ac3c5 |
805 | return $error; |
e9e5f0fa |
806 | } |
807 | |
8cc8ec79 |
808 | |
8cc8ec79 |
809 | |
324ac3c5 |
810 | |
811 | function fetchMessageHeaders($imapConnection, &$aMailbox) { |
812 | |
813 | /** |
814 | * Retrieve the UIDSET. |
815 | * Setindex is used to be able to store multiple uid sets. That will make it |
816 | * possible to display the mailbox multiple times in different sort order |
817 | * or to store serach results separate from normal mailbox view. |
818 | */ |
819 | $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0; |
820 | |
821 | $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT']; |
822 | /** |
823 | * Adjust the start_msg |
824 | */ |
825 | $start_msg = $aMailbox['PAGEOFFSET']; |
826 | if($aMailbox['PAGEOFFSET'] > $aMailbox['EXISTS']) { |
827 | $start_msg -= $aMailbox['LIMIT']; |
828 | if($start_msg < 1) { |
829 | $start_msg = 1; |
830 | } |
831 | } |
832 | |
833 | |
834 | if (is_array($aMailbox['UIDSET'])) { |
835 | $aUid =& $aMailbox['UIDSET'][$iSetIndx]; |
f6b262a3 |
836 | } else { |
324ac3c5 |
837 | $aUid = false; |
838 | } |
839 | |
840 | // initialize the fields we want to retrieve: |
841 | $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Content-Type'); |
842 | $aFetchItems = array('FLAGS', 'RFC822.SIZE'); |
843 | |
844 | // Are we sorting on internaldate then retrieve the internaldate value as well |
845 | if ($aMailbox['INTERNALDATE']) { |
846 | $aFetchItems[] = 'INTERNALDATE'; |
847 | } |
848 | |
849 | |
850 | /** |
851 | * A uidset with sorted uid's is available. We can use the cache |
852 | */ |
853 | if (($aMailbox['SORT'] != SQSORT_NONE || $aMailbox['SEARCH'][$iSetIndx] != 'ALL') && |
854 | isset($aUid) && $aUid ) { |
855 | |
856 | // limit the cache to SQM_MAX_PAGES_IN_CACHE |
857 | if (!$aMailbox['SHOWALL'][$iSetIndx]) { |
858 | $iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE; |
859 | $iCacheSize = count($aMailbox['MSG_HEADERS']); |
860 | if ($iCacheSize > $iMaxMsgs) { |
861 | $iReduce = $iCacheSize - $iMaxMsgs; |
862 | foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) { |
863 | if ($iReduce) { |
864 | unset($aMailbox['MSG_HEADERS'][$iUid]); |
865 | } else { |
866 | break; |
867 | } |
868 | --$iReduce; |
869 | } |
6a622b59 |
870 | } |
e9e5f0fa |
871 | } |
324ac3c5 |
872 | |
873 | $id_slice = array_slice($aUid,$start_msg-1,$iLimit); |
874 | /* do some funky cache checks */ |
875 | $aUidCached = array_keys($aMailbox['MSG_HEADERS']); |
876 | $aUidNotCached = array_values(array_diff($id_slice,$aUidCached)); |
877 | /** |
878 | * $aUidNotCached contains an array with UID's which need to be fetched to |
879 | * complete the needed message headers. |
880 | */ |
881 | if (count($aUidNotCached)) { |
882 | $aMsgs = sqimap_get_small_header_list($imapConnection,$aUidNotCached, |
883 | $aHeaderFields,$aFetchItems); |
884 | // append the msgs to the existend headers |
885 | $aMailbox['MSG_HEADERS'] += $aMsgs; |
8cc8ec79 |
886 | } |
6a622b59 |
887 | |
324ac3c5 |
888 | } else { |
889 | /** |
890 | * Initialize the sorted UID list and fetch the visible message headers |
891 | */ |
892 | if ($aMailbox['SORT'] != SQSORT_NONE || $aMailbox['SEARCH'][$iSetIndx] != 'ALL') {// || $aMailbox['SORT_METHOD'] & SQSORT_THREAD 'THREAD') { |
893 | |
894 | $error = false; |
895 | if ($aMailbox['SEARCH'][$iSetIndx] && $aMailbox['SORT'] == 0) { |
896 | $aUid = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]); |
897 | } else { |
898 | $error = get_sorted_msgs_list($imapConnection,$aMailbox,$error); |
899 | $aUid = $aMailbox['UIDSET'][$iSetIndx]; |
03975a39 |
900 | } |
324ac3c5 |
901 | if ($error === false) { |
902 | $id_slice = array_slice($aUid,$aMailbox['OFFSET'], $iLimit); |
903 | if (count($id_slice)) { |
904 | $aMailbox['MSG_HEADERS'] = sqimap_get_small_header_list($imapConnection,$id_slice, |
905 | $aHeaderFields,$aFetchItems); |
906 | } else { |
907 | return false; |
908 | } |
e0e30169 |
909 | |
03975a39 |
910 | } else { |
324ac3c5 |
911 | // FIX ME, format message and fallback to squirrel sort |
912 | if ($error) { |
913 | echo $error; |
914 | } |
03975a39 |
915 | } |
03975a39 |
916 | } else { |
324ac3c5 |
917 | // limit the cache to SQM_MAX_PAGES_IN_CACHE |
918 | if (!$aMailbox['SHOWALL'][$iSetIndx] && isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) { |
919 | $iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE; |
920 | $iCacheSize = count($aMailbox['MSG_HEADERS']); |
921 | if ($iCacheSize > $iMaxMsgs) { |
922 | $iReduce = $iCacheSize - $iMaxMsgs; |
923 | foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) { |
924 | if ($iReduce) { |
925 | $iId = $aMailbox['MSG_HEADERS'][$iUid]['ID']; |
926 | unset($aMailbox['MSG_HEADERS'][$iUid]); |
927 | unset($aMailbox['ID'][$iId]); |
928 | } else { |
929 | break; |
930 | } |
931 | --$iReduce; |
932 | } |
933 | } |
03975a39 |
934 | } |
e0e30169 |
935 | |
324ac3c5 |
936 | /** |
62f7daa5 |
937 | * retrieve messages by sequence id's and fetch the UID to retrieve |
938 | * the UID. for sorted lists this is not needed because a UID FETCH |
939 | * automaticly add the UID value in fetch results |
940 | **/ |
324ac3c5 |
941 | $aFetchItems[] = 'UID'; |
942 | |
943 | //create id range |
944 | $iRangeStart = $aMailbox['EXISTS'] - $aMailbox['OFFSET']; |
945 | $iRangeEnd = ($iRangeStart > $iLimit) ? |
946 | ($iRangeStart - $iLimit+1):1; |
947 | |
948 | $id_slice = range($iRangeStart, $iRangeEnd); |
949 | /** |
950 | * Non sorted mailbox with cached message headers |
951 | */ |
952 | if (isset($aMailbox['ID']) && is_array($aMailbox['ID'])) { |
953 | // the fetched id => uid relation |
954 | $aId = $aMailbox['ID']; |
955 | $aIdCached = array(); |
956 | foreach ($aId as $iId => $iUid) { |
957 | if (isset($aMailbox['MSG_HEADERS'][$iUid])) { |
958 | if ($iId <= $iRangeStart && $iId >= $iRangeEnd) { |
959 | $aIdCached[] = $iId; |
960 | } |
f6b262a3 |
961 | } |
6a622b59 |
962 | } |
324ac3c5 |
963 | $aIdNotCached = array_diff($id_slice,$aIdCached); |
03975a39 |
964 | } else { |
324ac3c5 |
965 | $aIdNotCached = $id_slice; |
8cc8ec79 |
966 | } |
324ac3c5 |
967 | |
968 | if (count($aIdNotCached)) { |
969 | $aMsgs = sqimap_get_small_header_list($imapConnection,$aIdNotCached, |
970 | $aHeaderFields,$aFetchItems); |
971 | // append the msgs to the existend headers |
972 | if (isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) { |
973 | $aMailbox['MSG_HEADERS'] += $aMsgs; |
974 | } else { |
975 | $aMailbox['MSG_HEADERS'] = $aMsgs; |
976 | } |
977 | // update the ID array |
978 | foreach ($aMsgs as $iUid => $aMsg) { |
979 | if (isset($aMsg['ID'])) { |
980 | $aMailbox['ID'][$aMsg['ID']] = $iUid; |
981 | } |
982 | } |
03975a39 |
983 | } |
7b73b809 |
984 | |
324ac3c5 |
985 | /** |
986 | * In unsorted state we show newest messages first which means |
987 | * that the UIDSET which represents the order of the messages |
988 | * should contain a high to low ordered UID list |
989 | */ |
990 | $aSortedUidList = array(); |
991 | foreach ($id_slice as $iId) { |
992 | if (isset($aMailbox['ID'][$iId])) { |
993 | $aSortedUidList[] = $aMailbox['ID'][$iId]; |
994 | } |
995 | } |
996 | $aMailbox['UIDSET'][$iSetIndx] = $aSortedUidList; |
997 | $aMailbox['OFFSET'] = 0; |
e0e30169 |
998 | } |
324ac3c5 |
999 | } |
1000 | return true; |
1001 | } |
6a622b59 |
1002 | |
324ac3c5 |
1003 | /** |
62f7daa5 |
1004 | * This function loops through a group of messages in the mailbox |
1005 | * and shows them to the user. |
1006 | * |
1007 | * @param mixed $imapConnection |
1008 | * @param array $aMailbox associative array with mailbox related vars |
1009 | */ |
324ac3c5 |
1010 | function showMessagesForMailbox($imapConnection, &$aMailbox) { |
0bb37159 |
1011 | global $color, $javascript_on, $compact_paginator; |
324ac3c5 |
1012 | |
1013 | // to retrieve the internaldate pref: (I know this is not the right place to do that, move up in front |
1014 | // and use a properties array as function argument to provide user preferences |
1015 | global $data_dir, $username; |
1016 | |
1017 | if (!fetchMessageHeaders($imapConnection, $aMailbox)) { |
1018 | return false; |
1019 | } |
1020 | $iSetIndx = $aMailbox['SETINDEX']; |
1021 | $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT']; |
1022 | $iEnd = ($aMailbox['PAGEOFFSET'] + ($iLimit - 1) < $aMailbox['EXISTS']) ? |
1023 | $aMailbox['PAGEOFFSET'] + $iLimit - 1 : $aMailbox['EXISTS']; |
6a622b59 |
1024 | |
324ac3c5 |
1025 | $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], |
0bb37159 |
1026 | $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SHOWALL'][$iSetIndx]); |
6a622b59 |
1027 | |
e0e30169 |
1028 | $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']); |
6a622b59 |
1029 | |
1030 | do_hook('mailbox_index_before'); |
0bb37159 |
1031 | |
1032 | if ($javascript_on && $compact_paginator) { |
1033 | // Insert compact paginator javascript |
1034 | echo "\n<!-- start of compact paginator javascript -->\n" |
1035 | . "<script language=\"JavaScript\">\n" |
1036 | . "function SubmitOnSelect(select, URL)\n" |
1037 | . "{\n" |
1038 | . " URL += select.options[select.selectedIndex].value;\n" |
1039 | . " window.location.href = URL;\n" |
1040 | . "}\n" |
1041 | . "</script>\n" |
1042 | . "<!-- end of compact paginator javascript -->\n"; |
1043 | } ?> |
1044 | |
abafb676 |
1045 | <table border="0" width="100%" cellpadding="0" cellspacing="0"> |
0fdc2fb6 |
1046 | <tr> |
abafb676 |
1047 | <td> |
8cc8ec79 |
1048 | <?php mail_message_listing_beginning($imapConnection, $aMailbox, $msg_cnt_str, $paginator_str); ?> |
abafb676 |
1049 | </td> |
0fdc2fb6 |
1050 | </tr> |
1051 | <tr><td height="5" bgcolor="<?php echo $color[4]; ?>"></td></tr> |
1052 | <tr> |
abafb676 |
1053 | <td> |
0fdc2fb6 |
1054 | <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[9]; ?>"> |
abafb676 |
1055 | <tr> |
0fdc2fb6 |
1056 | <td> |
abafb676 |
1057 | <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[5]; ?>"> |
0fdc2fb6 |
1058 | <tr> |
abafb676 |
1059 | <td> |
0fdc2fb6 |
1060 | <?php |
8cc8ec79 |
1061 | printHeader($aMailbox); |
1062 | displayMessageArray($imapConnection, $aMailbox); |
0fdc2fb6 |
1063 | ?> |
abafb676 |
1064 | </td> |
0fdc2fb6 |
1065 | </tr> |
abafb676 |
1066 | </table> |
0fdc2fb6 |
1067 | </td> |
abafb676 |
1068 | </tr> |
0fdc2fb6 |
1069 | </table> |
0bb37159 |
1070 | </td> |
1071 | </tr> |
1072 | <tr> |
1073 | <td> |
1074 | <?php |
1075 | mail_message_listing_end($aMailbox, $paginator_str, $msg_cnt_str); |
1076 | ?> |
abafb676 |
1077 | </td> |
0fdc2fb6 |
1078 | </tr> |
abafb676 |
1079 | </table> |
1080 | <?php |
324ac3c5 |
1081 | |
6c930ade |
1082 | } |
bdfb67f8 |
1083 | |
c7df3f1b |
1084 | /** |
62f7daa5 |
1085 | * Function to map an uid list with a msg header array by uid |
1086 | * The mapped headers are printed with printMessage |
1087 | * aMailbox parameters contains info about the page we are on, the |
1088 | * used search criteria, the number of messages to show |
1089 | * |
1090 | * @param resource $imapConnection socket handle to imap |
1091 | * @param array $aMailbox array with required elements MSG_HEADERS, UIDSET, OFFSET, LIMIT |
1092 | * @return void |
1093 | **/ |
8cc8ec79 |
1094 | function displayMessageArray($imapConnection, $aMailbox) { |
324ac3c5 |
1095 | $iSetIndx = $aMailbox['SETINDEX']; |
1096 | $aId = $aMailbox['UIDSET'][$iSetIndx]; |
8cc8ec79 |
1097 | $aHeaders = $aMailbox['MSG_HEADERS']; |
1098 | $iOffset = $aMailbox['OFFSET']; |
1099 | $sort = $aMailbox['SORT']; |
1100 | $iPageOffset = $aMailbox['PAGEOFFSET']; |
1101 | $sMailbox = $aMailbox['NAME']; |
324ac3c5 |
1102 | $sSearch = (isset($aMailbox['SEARCH'][$aMailbox['SETINDEX']])) ? $aMailbox['SEARCH'][$aMailbox['SETINDEX']] : false; |
1103 | $aSearch = ($sSearch) ? array('search.php',$aMailbox['SETINDEX']) : null; |
1104 | |
1105 | if ($aMailbox['SORT'] & SQSORT_THREAD) { |
1106 | $aIndentArray =& $aMailbox['THREAD_INDENT'][$aMailbox['SETINDEX']]; |
e0e30169 |
1107 | $bThread = true; |
1108 | } else { |
1109 | $bThread = false; |
1110 | } |
6a622b59 |
1111 | /* |
0fdc2fb6 |
1112 | * Loop through and display the info for each message. |
1113 | * ($t is used for the checkbox number) |
1114 | */ |
324ac3c5 |
1115 | $iEnd = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $iOffset + $aMailbox['LIMIT']; |
8cc8ec79 |
1116 | for ($i=$iOffset,$t=0;$i<$iEnd;++$i) { |
1117 | if (isset($aId[$i])) { |
1118 | $bLast = ((isset($aId[$i+1]) && isset($aHeaders[$aId[$i+1]])) |
1119 | || ($i == $iEnd )) ? false : true; |
e0e30169 |
1120 | if ($bThread) { |
1121 | $indent = (isset($aIndentArray[$aId[$i]])) ? $aIndentArray[$aId[$i]] : 0; |
1122 | } else { |
1123 | $indent = 0; |
1124 | } |
8cc8ec79 |
1125 | $aMsg = array( |
1126 | 'HEADER' => $aHeaders[$aId[$i]], |
1127 | 'INDX' => $t, |
1128 | 'OFFSET' => $iOffset, |
1129 | 'PAGEOFFSET' => $iPageOffset, |
1130 | 'SORT' => $sort, |
1131 | 'SEARCH' => $aSearch, |
1132 | 'MAILBOX' => $sMailbox, |
e0e30169 |
1133 | 'INDENT' => $indent, |
8cc8ec79 |
1134 | 'LAST' => $bLast |
1135 | ); |
324ac3c5 |
1136 | printMessageInfo($aMsg); |
0fdc2fb6 |
1137 | ++$t; |
6a622b59 |
1138 | } else { |
1c198ef7 |
1139 | break; |
6a622b59 |
1140 | } |
94ac35c6 |
1141 | } |
bdfb67f8 |
1142 | } |
1143 | |
c7df3f1b |
1144 | /** |
62f7daa5 |
1145 | * Displays the standard message list header. |
1146 | * |
1147 | * To finish the table, you need to do a "</table></table>"; |
1148 | * |
1149 | * @param resource $imapConnection |
1150 | * @param array $aMailbox associative array with mailbox related information |
1151 | * @param string $msg_cnt_str |
1152 | * @param string $paginator Paginator string |
1153 | */ |
6a622b59 |
1154 | function mail_message_listing_beginning ($imapConnection, |
8cc8ec79 |
1155 | $aMailbox, |
1156 | $msg_cnt_str = '', |
1157 | $paginator = ' ' |
1158 | ) { |
324ac3c5 |
1159 | global $color, $show_flag_buttons, $PHP_SELF; |
1012f961 |
1160 | global $lastTargetMailbox, $boxes; |
6a622b59 |
1161 | |
1162 | $php_self = $PHP_SELF; |
324ac3c5 |
1163 | |
6a622b59 |
1164 | if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) { |
1165 | $source_url = $regs[1]; |
1166 | } else { |
1167 | $source_url = $php_self; |
1168 | } |
1169 | |
1170 | if (!isset($msg)) { |
1171 | $msg = ''; |
1172 | } |
abafb676 |
1173 | |
b531f8ea |
1174 | $moveFields = addHidden('msg', $msg). |
8cc8ec79 |
1175 | addHidden('mailbox', $aMailbox['NAME']). |
324ac3c5 |
1176 | addHidden('startMessage', $aMailbox['PAGEOFFSET']); |
8fe969f6 |
1177 | |
5e0539cd |
1178 | /* build thread sorting links */ |
324ac3c5 |
1179 | $sort = $aMailbox['SORT']; |
8cc8ec79 |
1180 | if ($aMailbox['ALLOW_THREAD']) { |
324ac3c5 |
1181 | if ($aMailbox['SORT'] & SQSORT_THREAD) { |
1182 | $sort -= SQSORT_THREAD; |
8cc8ec79 |
1183 | $thread_name = _("Unthread View"); |
1184 | } else { |
8cc8ec79 |
1185 | $thread_name = _("Thread View"); |
324ac3c5 |
1186 | $sort = $aMailbox['SORT'] + SQSORT_THREAD; |
8cc8ec79 |
1187 | } |
324ac3c5 |
1188 | $thread_link_str = '<small>[<a href="' . $source_url . '?srt=' |
1189 | . $sort . '&start_messages=1' |
8cc8ec79 |
1190 | . '&mailbox=' . urlencode($aMailbox['NAME']) . '">' . $thread_name |
1191 | . '</a>]</small>'; |
1192 | } else { |
1193 | $thread_link_str =''; |
1194 | } |
6a622b59 |
1195 | /* |
0fdc2fb6 |
1196 | * This is the beginning of the message list table. |
1197 | * It wraps around all messages |
1198 | */ |
8cc8ec79 |
1199 | $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']); |
3027826a |
1200 | $form_name = "FormMsgs" . $safe_name; |
3da12e67 |
1201 | |
324ac3c5 |
1202 | echo '<form name="' . $form_name . '" method="post" action="'.$php_self.'">' ."\n" |
0fdc2fb6 |
1203 | . $moveFields; |
324ac3c5 |
1204 | |
9294e269 |
1205 | $button_str = ''; |
1206 | // display flag buttons only if supported |
1207 | if ($show_flag_buttons && |
1208 | in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true) ) { |
e1728a7a |
1209 | $button_str .= getButton('submit', 'markUnflagged', _("Unflag")); |
1210 | $button_str .= getButton('submit', 'markFlagged', _("Flag")); |
9294e269 |
1211 | $button_str .= " \n"; |
1212 | } |
1213 | if (in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true)) { |
e1728a7a |
1214 | $button_str .= getButton('submit', 'markUnread', _("Unread")); |
1215 | $button_str .= getButton('submit', 'markRead', _("Read")); |
9294e269 |
1216 | $button_str .= " \n"; |
1217 | } |
e1728a7a |
1218 | $button_str .= getButton('submit', 'attache',_("Forward")) . |
9294e269 |
1219 | " \n"; |
1220 | if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) { |
e1728a7a |
1221 | $button_str .= getButton('submit', 'delete',_("Delete")); |
9294e269 |
1222 | $button_str .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash"); |
1223 | $button_str .= " \n"; |
1224 | } |
1225 | if (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY') { |
e1728a7a |
1226 | $button_str .= getButton('submit', 'expungeButton',_("Expunge")) .' ' . _("mailbox") . "\n"; |
9294e269 |
1227 | $button_str .= ' '; |
1228 | } |
abafb676 |
1229 | ?> |
0fdc2fb6 |
1230 | <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>"> |
abafb676 |
1231 | <tr> |
0fdc2fb6 |
1232 | <td> |
abafb676 |
1233 | <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0"> |
0fdc2fb6 |
1234 | <tr> |
9294e269 |
1235 | <?php echo html_tag('td', '<small>' . $paginator . $thread_link_str . '</small>', 'left') . "\n"; ?> |
1236 | <?php echo html_tag('td', '', 'center') . "\n"; ?> |
1237 | <?php echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right') . "\n"; ?> |
0fdc2fb6 |
1238 | </tr> |
abafb676 |
1239 | </table> |
0fdc2fb6 |
1240 | </td> |
abafb676 |
1241 | </tr> |
1242 | <tr width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="<?php echo $color[0]; ?>"> |
0fdc2fb6 |
1243 | <td> |
abafb676 |
1244 | <table border="0" width="100%" cellpadding="1" cellspacing="0"> |
0fdc2fb6 |
1245 | <tr> |
9294e269 |
1246 | <?php echo html_tag('td', '', 'left') . "\n"; ?> |
1247 | <small> |
1248 | <?php echo $button_str; ?> |
1249 | <?php do_hook('mailbox_display_buttons'); ?> |
1250 | </small> |
abafb676 |
1251 | </td> |
4669e892 |
1252 | <?php |
c075fcfe |
1253 | if (in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) { |
9294e269 |
1254 | ?> |
1255 | <?php echo html_tag('td', '', 'right'); ?> |
1256 | <small> <tt> |
1257 | <select name="targetMailbox"> |
1258 | <?php echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes); ?> |
1259 | </select></tt> |
e1728a7a |
1260 | <?php echo getButton('submit', 'moveButton',_("Move")); ?> |
9294e269 |
1261 | </small> |
1262 | <?php |
4669e892 |
1263 | } |
1264 | ?> |
abafb676 |
1265 | </td> |
0fdc2fb6 |
1266 | </tr> |
abafb676 |
1267 | </table> |
0fdc2fb6 |
1268 | </td> |
abafb676 |
1269 | </tr> |
0fdc2fb6 |
1270 | </table> |
abafb676 |
1271 | <?php |
1b91be0c |
1272 | do_hook('mailbox_form_before'); |
e9e5f0fa |
1273 | } |
a966982b |
1274 | |
c7df3f1b |
1275 | /** |
62f7daa5 |
1276 | * Function to add the last row in a message list, it contains the paginator and info about |
1277 | * the number of messages. |
1278 | * |
0bb37159 |
1279 | * @param array $aMailbox associative array with mailbox related information |
62f7daa5 |
1280 | * @param string $paginator_str Paginator string [Prev | Next] [ 1 2 3 ... 91 92 94 ] [Show all] |
1281 | * @param string $msg_cnt_str Message count string Viewing Messages: 21 to 1861 (20 total) |
1282 | */ |
0bb37159 |
1283 | function mail_message_listing_end($aMailbox, $paginator_str, $msg_cnt_str) { |
1284 | global $color; |
1285 | |
1286 | if ($aMailbox['EXISTS']) { |
1287 | /* space between list and footer */ |
1288 | |
abafb676 |
1289 | ?> |
0fdc2fb6 |
1290 | <tr><td height="5" bgcolor="<?php echo $color[4]; ?>" colspan="1"></td></tr> |
1291 | <tr> |
abafb676 |
1292 | <td> |
0fdc2fb6 |
1293 | <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>"> |
abafb676 |
1294 | <tr> |
0fdc2fb6 |
1295 | <td> |
abafb676 |
1296 | <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0"> |
0fdc2fb6 |
1297 | <tr> |
9294e269 |
1298 | <?php echo html_tag('td', '<small>' . $paginator_str . '</small>', 'left'); ?> |
1299 | <?php echo html_tag('td', '<small>' . $msg_cnt_str . '</small>', 'right'); ?> |
0fdc2fb6 |
1300 | </tr> |
abafb676 |
1301 | </table> |
0fdc2fb6 |
1302 | </td> |
abafb676 |
1303 | </tr> |
0fdc2fb6 |
1304 | </table> |
abafb676 |
1305 | </td> |
0fdc2fb6 |
1306 | </tr> |
abafb676 |
1307 | <?php |
0fdc2fb6 |
1308 | } |
6a622b59 |
1309 | /* End of message-list table */ |
a966982b |
1310 | |
6a622b59 |
1311 | do_hook('mailbox_index_after'); |
c7df3f1b |
1312 | echo "</form>\n"; |
a966982b |
1313 | } |
1314 | |
c7df3f1b |
1315 | /** |
62f7daa5 |
1316 | * Prints the table header for the messages list view |
1317 | * |
1318 | * @param array $aMailbox |
1319 | */ |
8cc8ec79 |
1320 | function printHeader($aMailbox) { |
1321 | global $index_order, $internal_date_sort, $color; |
1322 | |
1323 | if ($aMailbox['SORT_METHOD'] != 'THREAD') { |
1324 | $showsort = true; |
1325 | } else { |
1326 | $showsort = false; |
1327 | } |
1328 | |
1b91be0c |
1329 | echo html_tag( 'tr' ,'' , 'center', $color[5] ); |
e4b5f9d1 |
1330 | |
1331 | /* calculate the width of the subject column based on the |
62f7daa5 |
1332 | * widths of the other columns */ |
e4b5f9d1 |
1333 | $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5); |
1334 | $subjectwidth = 100; |
1335 | foreach($index_order as $item) { |
4669e892 |
1336 | $subjectwidth -= $widths[$item]; |
e4b5f9d1 |
1337 | } |
1338 | |
1339 | foreach ($index_order as $item) { |
1340 | switch ($item) { |
8008456a |
1341 | case 1: /* checkbox */ |
8cc8ec79 |
1342 | echo html_tag( 'td',get_selectall_link($aMailbox) , '', '', 'width="1%"' ); |
abafb676 |
1343 | break; |
8008456a |
1344 | case 5: /* flags */ |
abafb676 |
1345 | echo html_tag( 'td','' , '', '', 'width="1%"' ); |
8008456a |
1346 | break; |
1347 | case 2: /* from */ |
8cc8ec79 |
1348 | if (handleAsSent($aMailbox['NAME'])) { |
1b91be0c |
1349 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
0fdc2fb6 |
1350 | . '<b>' . _("To") . '</b>'; |
03975a39 |
1351 | if ($showsort) { |
8cc8ec79 |
1352 | ShowSortButton($aMailbox, SQSORT_TO_ASC, SQSORT_TO_DEC); |
03975a39 |
1353 | } |
8008456a |
1354 | } else { |
1b91be0c |
1355 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
0fdc2fb6 |
1356 | . '<b>' . _("From") . '</b>'; |
03975a39 |
1357 | if ($showsort) { |
8cc8ec79 |
1358 | ShowSortButton($aMailbox, SQSORT_FROM_ASC, SQSORT_FROM_DEC); |
03975a39 |
1359 | } |
8008456a |
1360 | } |
1b91be0c |
1361 | echo "</td>\n"; |
8008456a |
1362 | break; |
1363 | case 3: /* date */ |
1b91be0c |
1364 | echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' ) |
0fdc2fb6 |
1365 | . '<b>' . _("Date") . '</b>'; |
a966982b |
1366 | if ($showsort) { |
03975a39 |
1367 | if ($internal_date_sort) { |
8cc8ec79 |
1368 | ShowSortButton($aMailbox, SQSORT_INT_DATE_ASC, SQSORT_INT_DATE_DEC); |
03975a39 |
1369 | } else { |
8cc8ec79 |
1370 | ShowSortButton($aMailbox, SQSORT_DATE_ASC, SQSORT_DATE_DEC); |
03975a39 |
1371 | } |
8008456a |
1372 | } |
1b91be0c |
1373 | echo "</td>\n"; |
8008456a |
1374 | break; |
a966982b |
1375 | case 4: /* subject */ |
e4b5f9d1 |
1376 | echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' ) |
0fdc2fb6 |
1377 | . '<b>' . _("Subject") . '</b>'; |
a966982b |
1378 | if ($showsort) { |
8cc8ec79 |
1379 | ShowSortButton($aMailbox, SQSORT_SUBJ_ASC, SQSORT_SUBJ_DEC); |
8008456a |
1380 | } |
1b91be0c |
1381 | echo "</td>\n"; |
8008456a |
1382 | break; |
1383 | case 6: /* size */ |
03975a39 |
1384 | echo html_tag( 'td', '', 'center','','width="5%" nowrap') |
1385 | . '<b>' . _("Size") . '</b>'; |
1386 | if ($showsort) { |
8cc8ec79 |
1387 | ShowSortButton($aMailbox, SQSORT_SIZE_ASC, SQSORT_SIZE_DEC); |
03975a39 |
1388 | } |
1389 | echo "</td>\n"; |
8008456a |
1390 | break; |
1391 | } |
bdfb67f8 |
1392 | } |
1b91be0c |
1393 | echo "</tr>\n"; |
bdfb67f8 |
1394 | } |
1395 | |
e9e5f0fa |
1396 | |
c7df3f1b |
1397 | /** |
62f7daa5 |
1398 | * This function shows the sort button. Isn't this a good comment? |
1399 | * |
1400 | * @param array $aMailbox |
1401 | * @param integer $Down |
1402 | * @param integer $Up |
1403 | */ |
8cc8ec79 |
1404 | function ShowSortButton($aMailbox, $Down, $Up ) { |
6a622b59 |
1405 | global $PHP_SELF; |
94a4ea53 |
1406 | |
6a622b59 |
1407 | /* Figure out which image we want to use. */ |
8cc8ec79 |
1408 | if ($aMailbox['SORT'] != $Up && $aMailbox['SORT'] != $Down) { |
6a622b59 |
1409 | $img = 'sort_none.png'; |
1410 | $which = $Up; |
8cc8ec79 |
1411 | } elseif ($aMailbox['SORT'] == $Up) { |
6a622b59 |
1412 | $img = 'up_pointer.png'; |
1413 | $which = $Down; |
6c930ade |
1414 | } else { |
6a622b59 |
1415 | $img = 'down_pointer.png'; |
03975a39 |
1416 | $which = 0; |
e35045b7 |
1417 | } |
6a622b59 |
1418 | |
1419 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
1420 | $source_url = $regs[1]; |
e35045b7 |
1421 | } else { |
6a622b59 |
1422 | $source_url = $PHP_SELF; |
6c930ade |
1423 | } |
6a622b59 |
1424 | |
1425 | /* Now that we have everything figured out, show the actual button. */ |
324ac3c5 |
1426 | echo ' <a href="' . $source_url .'?srt=' . $which |
8cc8ec79 |
1427 | . '&startMessage=1&mailbox=' . urlencode($aMailbox['NAME']) |
0fdc2fb6 |
1428 | . '"><img src="../images/' . $img |
1429 | . '" border="0" width="12" height="10" alt="sort" title="' |
494607f5 |
1430 | . _("Click here to change the sorting of the message list") .'" /></a>'; |
6a622b59 |
1431 | } |
1432 | |
c7df3f1b |
1433 | /** |
62f7daa5 |
1434 | * FIXME: Undocumented function |
1435 | * |
1436 | * @param array $aMailbox |
1437 | */ |
8cc8ec79 |
1438 | function get_selectall_link($aMailbox) { |
1439 | global $checkall, $javascript_on; |
324ac3c5 |
1440 | global $PHP_SELF; |
6a622b59 |
1441 | |
1442 | $result = ''; |
1443 | if ($javascript_on) { |
8cc8ec79 |
1444 | $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']); |
3027826a |
1445 | $func_name = "CheckAll" . $safe_name; |
1446 | $form_name = "FormMsgs" . $safe_name; |
6a622b59 |
1447 | $result = '<script language="JavaScript" type="text/javascript">' |
1448 | . "\n<!-- \n" |
3027826a |
1449 | . "function " . $func_name . "() {\n" |
1450 | . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n" |
3962deff |
1451 | . " if(document." . $form_name . ".elements[i].type == 'checkbox' && " |
e0b57c62 |
1452 | . " document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n" |
3027826a |
1453 | . " document." . $form_name . ".elements[i].checked = " |
1454 | . " !(document." . $form_name . ".elements[i].checked);\n" |
6a622b59 |
1455 | . " }\n" |
1456 | . " }\n" |
1457 | . "}\n" |
1458 | . "//-->\n" |
abafb676 |
1459 | . '</script>' |
c7df3f1b |
1460 | . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();" />'; |
abafb676 |
1461 | // . <a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All") |
1462 | // . "</a>\n"; |
e35045b7 |
1463 | } else { |
a6d36aa5 |
1464 | $result .= "<a href=\"$PHP_SELF"; |
1465 | // FIXME: why strpos() is used to detect presense of the symbol in the string. |
1466 | // Function returns boolean value only when symbol is not found |
6a622b59 |
1467 | if (strpos($PHP_SELF, "?")) { |
a6d36aa5 |
1468 | $prefix = '&'; |
6a622b59 |
1469 | } else { |
a6d36aa5 |
1470 | $prefix = '?'; |
6a622b59 |
1471 | } |
a6d36aa5 |
1472 | |
1473 | // If variables are part of GET request, they are present in $PHP_SELF |
1474 | // maybe other functions can be used instead of sqgetGlobalVar (like preg_match) |
1475 | if (! sqgetGlobalVar('mailbox',$tmp,SQ_GET)) { |
1476 | $result .= $prefix . 'mailbox=' . urlencode($aMailbox['NAME']); |
1477 | $prefix = '&'; |
1478 | } |
1479 | if (! sqgetGlobalVar('startMessage',$tmp,SQ_GET)) { |
1480 | $result .= $prefix . 'startMessage=' . $aMailbox['PAGEOFFSET']; |
1481 | $prefix = '&'; |
1482 | } |
1483 | if (! sqgetGlobalVar('str',$tmp,SQ_GET)) { |
1484 | $result .= $prefix . 'str=' . $aMailbox['SORT']; |
1485 | $prefix = '&'; |
1486 | } |
1487 | |
6a622b59 |
1488 | if (isset($checkall) && $checkall == '1') { |
a6d36aa5 |
1489 | $checkall_val = '0'; |
1490 | } else { |
1491 | $checkall_val = '1'; |
1492 | } |
1493 | if (! sqgetGlobalVar('checkall',$tmp,SQ_GET) ) { |
1494 | $result .= $prefix . 'checkall=' . $checkall_val; |
1495 | $prefix = '&'; |
6a622b59 |
1496 | } else { |
a6d36aa5 |
1497 | // checkall is already present in php_self. replace it |
1498 | $result = preg_replace("/checkall=(\d)/","checkall=$checkall_val",$result); |
6a622b59 |
1499 | } |
1500 | |
91e0dccc |
1501 | // FIXME: I suspect that search pages use different variables in 1.5.1cvs |
a6d36aa5 |
1502 | // and these variables are present in $PHP_SELF. |
1503 | if (isset($aMailbox['SEARCH']) && isset($aMailbox['SEARCH'][0]) && ! sqgetGlobalVar('where',$tmp,SQ_GET)) { |
1504 | $result .= '&where=' . urlencode($aMailbox['SEARCH'][0]); |
1505 | if (isset($aMailbox['SEARCH'][1]) && ! sqgetGlobalVar('what',$tmp,SQ_GET)) { |
1506 | $result .= '&what=' . urlencode($aMailbox['SEARCH'][1]); |
0bb37159 |
1507 | } |
6a622b59 |
1508 | } |
1509 | $result .= "\">"; |
98a9cc03 |
1510 | $result .= _("All"); |
c7df3f1b |
1511 | $result .= "</a>\n"; |
e35045b7 |
1512 | } |
23d6bd09 |
1513 | |
6a622b59 |
1514 | /* Return our final result. */ |
1515 | return ($result); |
bdfb67f8 |
1516 | } |
1a0e0983 |
1517 | |
c7df3f1b |
1518 | /** |
62f7daa5 |
1519 | * This function computes the "Viewing Messages..." string. |
1520 | * |
1521 | * @param integer $start_msg first message number |
1522 | * @param integer $end_msg last message number |
1523 | * @param integer $num_msgs total number of message in folder |
1524 | * @return string |
1525 | */ |
bdfb67f8 |
1526 | function get_msgcnt_str($start_msg, $end_msg, $num_msgs) { |
6a622b59 |
1527 | /* Compute the $msg_cnt_str. */ |
1528 | $result = ''; |
1529 | if ($start_msg < $end_msg) { |
c7df3f1b |
1530 | $result = sprintf(_("Viewing Messages: %s to %s (%s total)"), |
0fdc2fb6 |
1531 | '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs); |
6a622b59 |
1532 | } else if ($start_msg == $end_msg) { |
043f9c14 |
1533 | $result = sprintf(_("Viewing Message: %s (%s total)"), '<b>'.$start_msg.'</b>', $num_msgs); |
6a622b59 |
1534 | } else { |
c7df3f1b |
1535 | $result = '<br />'; |
6a622b59 |
1536 | } |
1537 | /* Return our result string. */ |
1538 | return ($result); |
bdfb67f8 |
1539 | } |
1540 | |
c7df3f1b |
1541 | /** |
62f7daa5 |
1542 | * Generate a paginator link. |
1543 | * |
1544 | * @param mixed $box Mailbox name |
1545 | * @param mixed $start_msg Message Offset |
1546 | * @param mixed $use |
1547 | * @param string $text text used for paginator link |
1548 | * @return string |
1549 | */ |
324ac3c5 |
1550 | function get_paginator_link($box, $start_msg, $text) { |
1551 | sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER); |
1552 | $result = "<a href=\"$php_self?startMessage=$start_msg&mailbox=$box\" " |
c7df3f1b |
1553 | . ">$text</a>"; |
6a622b59 |
1554 | |
6a622b59 |
1555 | return ($result); |
7b294953 |
1556 | } |
1557 | |
c7df3f1b |
1558 | /** |
62f7daa5 |
1559 | * This function computes the paginator string. |
1560 | * |
1561 | * @param string $box mailbox name |
1562 | * @param integer $iOffset offset in total number of messages |
1563 | * @param integer $iTotal total number of messages |
1564 | * @param integer $iLimit maximum number of messages to show on a page |
1565 | * @param bool $bShowAll show all messages at once (non paginate mode) |
1566 | * @return string $result paginate string with links to pages |
1567 | */ |
324ac3c5 |
1568 | function get_paginator_str($box, $iOffset, $iTotal, $iLimit, $bShowAll) { |
0bb37159 |
1569 | global $username, $data_dir, $javascript_on; |
1570 | // page selector globals |
1571 | global $page_selector, $page_selector_max, $compact_paginator; |
324ac3c5 |
1572 | sqgetGlobalVar('PHP_SELF',$php_self,SQ_SERVER); |
6a622b59 |
1573 | |
1574 | /* Initialize paginator string chunks. */ |
1575 | $prv_str = ''; |
1576 | $nxt_str = ''; |
eac26493 |
1577 | $pg_str = ''; |
6a622b59 |
1578 | $all_str = ''; |
6a622b59 |
1579 | |
1580 | $box = urlencode($box); |
324ac3c5 |
1581 | |
6a622b59 |
1582 | /* Create simple strings that will be creating the paginator. */ |
1583 | $spc = ' '; /* This will be used as a space. */ |
1584 | $sep = '|'; /* This will be used as a seperator. */ |
1585 | |
6a622b59 |
1586 | /* Make sure that our start message number is not too big. */ |
324ac3c5 |
1587 | $iOffset = min($iOffset, $iTotal); |
6a622b59 |
1588 | |
6a622b59 |
1589 | /* Compute the starting message of the previous and next page group. */ |
324ac3c5 |
1590 | $next_grp = $iOffset + $iLimit; |
1591 | $prev_grp = $iOffset - $iLimit; |
1592 | |
1593 | if (!$bShowAll) { |
1594 | /* Compute the basic previous and next strings. */ |
0bb37159 |
1595 | if ($compact_paginator) { |
1596 | if (($next_grp <= $iTotal) && ($prev_grp >= 0)) { |
1597 | $prv_str = get_paginator_link($box, $prev_grp, '<'); |
1598 | $nxt_str = get_paginator_link($box, $next_grp, '>'); |
1599 | } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) { |
1600 | $prv_str = get_paginator_link($box, $prev_grp, '<'); |
1601 | $nxt_str = '>'; |
1602 | } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) { |
1603 | $prv_str = '<'; |
1604 | $nxt_str = get_paginator_link($box, $next_grp, '>'); |
1605 | } |
1606 | } else { |
1607 | if (($next_grp <= $iTotal) && ($prev_grp >= 0)) { |
1608 | $prv_str = get_paginator_link($box, $prev_grp, _("Previous")); |
1609 | $nxt_str = get_paginator_link($box, $next_grp, _("Next")); |
1610 | } else if (($next_grp > $iTotal) && ($prev_grp >= 0)) { |
1611 | $prv_str = get_paginator_link($box, $prev_grp, _("Previous")); |
1612 | $nxt_str = _("Next"); |
1613 | } else if (($next_grp <= $iTotal) && ($prev_grp < 0)) { |
1614 | $prv_str = _("Previous"); |
1615 | $nxt_str = get_paginator_link($box, $next_grp, _("Next")); |
1616 | } |
324ac3c5 |
1617 | } |
6a622b59 |
1618 | |
324ac3c5 |
1619 | /* Page selector block. Following code computes page links. */ |
0bb37159 |
1620 | if ($iLimit != 0 && $page_selector && ($iTotal > $iLimit)) { |
324ac3c5 |
1621 | /* Most importantly, what is the current page!!! */ |
1622 | $cur_pg = intval($iOffset / $iLimit) + 1; |
6a622b59 |
1623 | |
324ac3c5 |
1624 | /* Compute total # of pages and # of paginator page links. */ |
1625 | $tot_pgs = ceil($iTotal / $iLimit); /* Total number of Pages */ |
6a622b59 |
1626 | |
0bb37159 |
1627 | if (!$compact_paginator) { |
1628 | $vis_pgs = min($page_selector_max, $tot_pgs - 1); /* Visible Pages */ |
6a622b59 |
1629 | |
0bb37159 |
1630 | /* Compute the size of the four quarters of the page links. */ |
324ac3c5 |
1631 | |
0bb37159 |
1632 | /* If we can, just show all the pages. */ |
1633 | if (($tot_pgs - 1) <= $page_selector_max) { |
324ac3c5 |
1634 | $q1_pgs = $cur_pg - 1; |
0bb37159 |
1635 | $q2_pgs = $q3_pgs = 0; |
324ac3c5 |
1636 | $q4_pgs = $tot_pgs - $cur_pg; |
0bb37159 |
1637 | |
1638 | /* Otherwise, compute some magic to choose the four quarters. */ |
1639 | } else { |
1640 | /* |
1641 | * Compute the magic base values. Added together, |
1642 | * these values will always equal to the $pag_pgs. |
1643 | * NOTE: These are DEFAULT values and do not take |
1644 | * the current page into account. That is below. |
1645 | */ |
1646 | $q1_pgs = floor($vis_pgs/4); |
1647 | $q2_pgs = round($vis_pgs/4, 0); |
1648 | $q3_pgs = ceil($vis_pgs/4); |
1649 | $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0); |
1650 | |
1651 | /* Adjust if the first quarter contains the current page. */ |
1652 | if (($cur_pg - $q1_pgs) < 1) { |
1653 | $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs; |
1654 | $q1_pgs = $cur_pg - 1; |
1655 | $q2_pgs = 0; |
1656 | $q3_pgs += ceil($extra_pgs / 2); |
1657 | $q4_pgs += floor($extra_pgs / 2); |
1658 | |
1659 | /* Adjust if the first and second quarters intersect. */ |
1660 | } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) { |
1661 | $extra_pgs = $q2_pgs; |
1662 | $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4); |
1663 | $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4); |
1664 | $q3_pgs += ceil($extra_pgs / 2); |
1665 | $q4_pgs += floor($extra_pgs / 2); |
1666 | |
1667 | /* Adjust if the fourth quarter contains the current page. */ |
1668 | } else if (($cur_pg + $q4_pgs) >= $tot_pgs) { |
1669 | $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs; |
1670 | $q3_pgs = 0; |
1671 | $q4_pgs = $tot_pgs - $cur_pg; |
1672 | $q1_pgs += floor($extra_pgs / 2); |
1673 | $q2_pgs += ceil($extra_pgs / 2); |
1674 | |
1675 | /* Adjust if the third and fourth quarter intersect. */ |
1676 | } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) { |
1677 | $extra_pgs = $q3_pgs; |
1678 | $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4); |
1679 | $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4); |
1680 | $q1_pgs += floor($extra_pgs / 2); |
1681 | $q2_pgs += ceil($extra_pgs / 2); |
1682 | } |
324ac3c5 |
1683 | } |
e35045b7 |
1684 | |
0bb37159 |
1685 | /* |
1686 | * I am leaving this debug code here, commented out, because |
1687 | * it is a really nice way to see what the above code is doing. |
1688 | * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " |
1689 | * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br />'; |
1690 | */ |
6a622b59 |
1691 | |
0bb37159 |
1692 | /* Print out the page links from the compute page quarters. */ |
6a622b59 |
1693 | |
0bb37159 |
1694 | /* Start with the first quarter. */ |
1695 | if (($q1_pgs == 0) && ($cur_pg > 1)) { |
324ac3c5 |
1696 | $pg_str .= "...$spc"; |
0bb37159 |
1697 | } else { |
1698 | for ($pg = 1; $pg <= $q1_pgs; ++$pg) { |
1699 | $start = (($pg-1) * $iLimit) + 1; |
1700 | $pg_str .= get_paginator_link($box, $start, $pg) . $spc; |
1701 | } |
1702 | if ($cur_pg - $q2_pgs - $q1_pgs > 1) { |
1703 | $pg_str .= "...$spc"; |
1704 | } |
324ac3c5 |
1705 | } |
6a622b59 |
1706 | |
0bb37159 |
1707 | /* Continue with the second quarter. */ |
1708 | for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) { |
1709 | $start = (($pg-1) * $iLimit) + 1; |
1710 | $pg_str .= get_paginator_link($box, $start, $pg) . $spc; |
1711 | } |
6a622b59 |
1712 | |
0bb37159 |
1713 | /* Now print the current page. */ |
1714 | $pg_str .= $cur_pg . $spc; |
6a622b59 |
1715 | |
0bb37159 |
1716 | /* Next comes the third quarter. */ |
1717 | for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) { |
1718 | $start = (($pg-1) * $iLimit) + 1; |
1719 | $pg_str .= get_paginator_link($box, $start, $pg) . $spc; |
1720 | } |
6a622b59 |
1721 | |
0bb37159 |
1722 | /* And last, print the forth quarter page links. */ |
1723 | if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) { |
324ac3c5 |
1724 | $pg_str .= "...$spc"; |
0bb37159 |
1725 | } else { |
1726 | if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) { |
1727 | $pg_str .= "...$spc"; |
1728 | } |
1729 | for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) { |
1730 | $start = (($pg-1) * $iLimit) + 1; |
1731 | $pg_str .= get_paginator_link($box, $start,$pg) . $spc; |
1732 | } |
324ac3c5 |
1733 | } |
6a622b59 |
1734 | } |
0bb37159 |
1735 | $last_grp = (($tot_pgs - 1) * $iLimit) + 1; |
6a622b59 |
1736 | } |
324ac3c5 |
1737 | } else { |
1738 | $pg_str = "<a href=\"$php_self?showall=0" |
1739 | . "&startMessage=1&mailbox=$box\" " |
c7df3f1b |
1740 | . ">" ._("Paginate") . '</a>'; |
6a622b59 |
1741 | } |
1742 | |
6a622b59 |
1743 | /* Put all the pieces of the paginator string together. */ |
1744 | /** |
62f7daa5 |
1745 | * Hairy code... But let's leave it like it is since I am not certain |
1746 | * a different approach would be any easier to read. ;) |
1747 | */ |
6a622b59 |
1748 | $result = ''; |
324ac3c5 |
1749 | if ( $prv_str || $nxt_str ) { |
1750 | |
1751 | /* Compute the 'show all' string. */ |
1752 | $all_str = "<a href=\"$php_self?showall=1" |
1753 | . "&startMessage=1&mailbox=$box\" " |
0fdc2fb6 |
1754 | . ">" . _("Show All") . '</a>'; |
abafb676 |
1755 | } |
eac26493 |
1756 | |
0bb37159 |
1757 | if ($compact_paginator) { |
1758 | if ( $prv_str || $nxt_str ) { |
1759 | $result .= '[' . get_paginator_link($box, 1, '<<') . ']'; |
1760 | $result .= '[' . $prv_str . ']'; |
1761 | |
1762 | $pg_url = $php_self . '?mailbox=' . $box; |
6a622b59 |
1763 | |
0bb37159 |
1764 | $result .= '[' . $nxt_str . ']'; |
1765 | $result .= '[' . get_paginator_link($box, $last_grp, '>>') . ']'; |
1766 | |
1767 | if ($page_selector) { |
1768 | $result .= $spc . '<select name="startMessage"'; |
1769 | if ($javascript_on) { |
1770 | $result .= ' onchange="JavaScript:SubmitOnSelect' |
1771 | . '(this, \'' . $pg_url . '&startMessage=\')"'; |
1772 | } |
1773 | $result .='>'; |
1774 | |
1775 | for ($p = 0; $p < $tot_pgs; $p++) { |
1776 | $result .= '<option '; |
1777 | if (($p+1) == $cur_pg) $result .= 'selected '; |
1778 | $result .= 'value="' . (($p*$iLimit)+1) . '">' |
1779 | . ($p+1) . "/$tot_pgs" . '</option>'; |
1780 | } |
1781 | |
1782 | $result .= '</select>'; |
1783 | |
1784 | if ($javascript_on) { |
1785 | $result .= '<noscript language="JavaScript">' |
1786 | . addSubmit(_("Go")) |
1787 | . '</noscript>'; |
1788 | } else { |
1789 | $result .= addSubmit(_("Go")); |
1790 | } |
1791 | } |
1792 | } |
1793 | |
1794 | $result .= ($pg_str != '' ? '['.$pg_str.']' . $spc : ''); |
1795 | $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : ''); |
1796 | } else { |
1797 | if ( $prv_str || $nxt_str ) { |
1798 | $result .= '['; |
1799 | $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : ''); |
1800 | $result .= ($nxt_str != '' ? $nxt_str : ''); |
1801 | $result .= ']' . $spc ; |
1802 | } |
1803 | |
1804 | $result .= ($pg_str != '' ? $spc . '['.$spc.$pg_str.']' . $spc : ''); |
1805 | $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : ''); |
1806 | } |
6a622b59 |
1807 | /* If the resulting string is blank, return a non-breaking space. */ |
1808 | if ($result == '') { |
1809 | $result = ' '; |
1810 | } |
6a622b59 |
1811 | /* Return our final magical paginator string. */ |
1812 | return ($result); |
bdfb67f8 |
1813 | } |
1814 | |
c7df3f1b |
1815 | /** |
62f7daa5 |
1816 | * FIXME: Undocumented function |
1817 | */ |
eaa4f45f |
1818 | function truncateWithEntities($subject, $trim_at) |
1819 | { |
341aa42f |
1820 | $ent_strlen = strlen($subject); |
1821 | if (($trim_at <= 0) || ($ent_strlen <= $trim_at)) |
6a622b59 |
1822 | return $subject; |
eaa4f45f |
1823 | |
1824 | global $languages, $squirrelmail_language; |
6a622b59 |
1825 | |
6a622b59 |
1826 | /* |
62f7daa5 |
1827 | * see if this is entities-encoded string |
1828 | * If so, Iterate through the whole string, find out |
1829 | * the real number of characters, and if more |
1830 | * than $trim_at, substr with an updated trim value. |
1831 | */ |
341aa42f |
1832 | $trim_val = $trim_at; |
1833 | $ent_offset = 0; |
1834 | $ent_loc = 0; |
a1440f89 |
1835 | while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) && |
1836 | (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) { |
1837 | $trim_val += ($ent_loc_end-$ent_loc); |
6a622b59 |
1838 | $ent_offset = $ent_loc_end+1; |
1839 | } |
341aa42f |
1840 | if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val + 6))) { |
a1440f89 |
1841 | $i = strpos($subject,';',$trim_val); |
1842 | if ($i) { |
1843 | $trim_val = strpos($subject,';',$trim_val); |
1844 | } |
46a49f65 |
1845 | } |
341aa42f |
1846 | // only print '...' when we're actually dropping part of the subject |
1847 | if ($ent_strlen <= $trim_val) |
6a622b59 |
1848 | return $subject; |
6a622b59 |
1849 | |
1850 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
b3e4bf71 |
1851 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth')) { |
1852 | return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth', $subject, $trim_val); |
6a622b59 |
1853 | } |
ecaf6352 |
1854 | |
341aa42f |
1855 | return substr_replace($subject, '...', $trim_val); |
bdfb67f8 |
1856 | } |
f93c93b9 |
1857 | |
c7df3f1b |
1858 | /** |
62f7daa5 |
1859 | * FIXME: Undocumented function |
1860 | */ |
eaa4f45f |
1861 | function processSubject($subject, $threadlevel = 0) { |
1862 | /* Shouldn't ever happen -- caught too many times in the IMAP functions */ |
1863 | if ($subject == '') { |
1864 | return _("(no subject)"); |
1865 | } |
1866 | |
3fc1a95f |
1867 | global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */ |
1868 | $trim_at = $truncate_subject; |
eaa4f45f |
1869 | |
1870 | /* if this is threaded, subtract two chars per indentlevel */ |
1871 | if (($threadlevel > 0) && ($threadlevel <= 10)) |
1872 | $trim_at -= (2*$threadlevel); |
1873 | |
1874 | return truncateWithEntities($subject, $trim_at); |
1875 | } |
1876 | |
e9e5f0fa |
1877 | |
c7df3f1b |
1878 | /** |
62f7daa5 |
1879 | * Creates button |
1880 | * |
1881 | * @deprecated see form functions available in 1.5.1 and 1.4.3. |
1882 | * @param string $type |
1883 | * @param string $name |
1884 | * @param string $value |
1885 | * @param string $js |
1886 | * @param bool $enabled |
1887 | */ |
1a531551 |
1888 | function getButton($type, $name, $value, $js = '', $enabled = TRUE) { |
98a9cc03 |
1889 | $disabled = ( $enabled ? '' : 'disabled ' ); |
1a531551 |
1890 | $js = ( $js ? $js.' ' : '' ); |
c7df3f1b |
1891 | return '<input '.$disabled.$js. |
0fdc2fb6 |
1892 | 'type="'.$type. |
1893 | '" name="'.$name. |
c7df3f1b |
1894 | '" value="'.$value . |
1895 | '" style="padding: 0px; margin: 0px" />'; |
e9e5f0fa |
1896 | } |
1897 | |
c7df3f1b |
1898 | /** |
62f7daa5 |
1899 | * Puts string into cell, aligns it and adds <small> tag |
1900 | * |
1901 | * @param string $string string |
1902 | * @param string $align alignment |
1903 | */ |
e9e5f0fa |
1904 | function getSmallStringCell($string, $align) { |
6a622b59 |
1905 | return html_tag('td', |
1906 | '<small>' . $string . ': </small>', |
1907 | $align, |
1908 | '', |
1909 | 'nowrap' ); |
e9e5f0fa |
1910 | } |
1911 | |
c7df3f1b |
1912 | /** |
62f7daa5 |
1913 | * This should go in imap_mailbox.php |
1914 | * @param string $mailbox |
1915 | */ |
a3439b27 |
1916 | function handleAsSent($mailbox) { |
6a8e7cae |
1917 | global $handleAsSent_result; |
4669e892 |
1918 | |
6a622b59 |
1919 | /* First check if this is the sent or draft folder. */ |
6a8e7cae |
1920 | $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox); |
a3439b27 |
1921 | |
6a622b59 |
1922 | /* Then check the result of the handleAsSent hook. */ |
1923 | do_hook('check_handleAsSent_result', $mailbox); |
a3439b27 |
1924 | |
6a622b59 |
1925 | /* And return the result. */ |
6a8e7cae |
1926 | return $handleAsSent_result; |
6a622b59 |
1927 | } |
e842b215 |
1928 | |
324ac3c5 |
1929 | /** |
1930 | * Process messages list form and handle the cache gracefully. If $sButton and |
1931 | * $aUid are provided as argument then you can fake a message list submit and |
1932 | * use it i.e. in read_body.php for del move next and update the cache |
1933 | * |
1934 | * @param resource $imapConnection imap connection |
1935 | * @param array $aMailbox (reference) cached mailbox |
1936 | * @param string $sButton fake a submit button |
1937 | * @param array $aUid fake the $msg array |
1938 | * @return string $sError error string in case of an error |
1939 | * @author Marc Groot Koerkamp |
1940 | */ |
1941 | function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = array()) { |
1942 | |
1943 | /* incoming formdata */ |
1944 | $sButton = (sqgetGlobalVar('moveButton', $sTmp, SQ_POST)) ? 'move' : $sButton; |
1945 | $sButton = (sqgetGlobalVar('expungeButton', $sTmp, SQ_POST)) ? 'expunge' : $sButton; |
1946 | $sButton = (sqgetGlobalVar('attache', $sTmp, SQ_POST)) ? 'attache' : $sButton; |
1947 | $sButton = (sqgetGlobalVar('delete', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton; |
1948 | $sButton = (sqgetGlobalVar('undeleteButton', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton; |
1949 | $sButton = (sqgetGlobalVar('markRead', $sTmp, SQ_POST)) ? 'setSeen' : $sButton; |
1950 | $sButton = (sqgetGlobalVar('markUnread', $sTmp, SQ_POST)) ? 'unsetSeen' : $sButton; |
1951 | $sButton = (sqgetGlobalVar('markFlagged', $sTmp, SQ_POST)) ? 'setFlagged' : $sButton; |
1952 | $sButton = (sqgetGlobalVar('markUnflagged', $sTmp, SQ_POST)) ? 'unsetFlagged' : $sButton; |
1953 | sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST); |
1954 | sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST); |
1955 | sqgetGlobalVar('msg', $msg, SQ_POST); |
1956 | |
1957 | $sError = ''; |
1958 | $mailbox = $aMailbox['NAME']; |
1959 | |
1960 | /* retrieve the check boxes */ |
1961 | $aUid = (isset($msg) && is_array($msg)) ? array_values($msg) : $aUid; |
1962 | |
1963 | if (count($aUid) && $sButton != 'expunge') { |
1964 | $aUpdatedMsgs = false; |
1965 | $bExpunge = false; |
1966 | switch ($sButton) { |
1967 | case 'setDeleted': |
1968 | // check if id exists in case we come from read_body |
1969 | if (count($aUid) == 1 && is_array($aMailbox['UIDSET'][$aMailbox['SETINDEX']]) && |
1970 | !in_array($aUid[0],$aMailbox['UIDSET'][$aMailbox['SETINDEX']])) { |
1971 | break; |
1972 | } |
7c788b1c |
1973 | $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash); |
1974 | $bExpunge = true; |
324ac3c5 |
1975 | break; |
1976 | case 'unsetDeleted': |
1977 | case 'setSeen': |
1978 | case 'unsetSeen': |
1979 | case 'setFlagged': |
1980 | case 'unsetFlagged': |
1981 | // get flag |
1982 | $sFlag = (substr($sButton,0,3) == 'set') ? '\\'.substr($sButton,3) : '\\'.substr($sButton,5); |
1983 | $bSet = (substr($sButton,0,3) == 'set') ? true : false; |
1984 | $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true); |
1985 | break; |
1986 | case 'move': |
1987 | $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox); |
1988 | sqsession_register($targetMailbox,'lastTargetMailbox'); |
1989 | $bExpunge = true; |
1990 | break; |
1991 | case 'attache': |
1992 | $aMsgHeaders = array(); |
1993 | foreach ($aUid as $iUid) { |
1994 | $aMsgHeaders[$iUid] = $aMailbox['MSG_HEADERS'][$iUid]; |
1995 | } |
1996 | if (count($aMsgHeaders)) { |
1997 | $composesession = attachSelectedMessages($imapConnection,$aMsgHeaders); |
1998 | // dirty hack, add info to $aMailbox |
1999 | $aMailbox['FORWARD_SESSION'] = $composesession; |
2000 | } |
2001 | break; |
7c788b1c |
2002 | default: |
2003 | // Hook for plugin buttons |
2004 | do_hook_function('mailbox_display_button_action', $aUid); |
2005 | break; |
324ac3c5 |
2006 | } |
2007 | /** |
2008 | * Updates messages is an array containing the result of the untagged |
2009 | * fetch responses send by the imap server due to a flag change. That |
2010 | * response is parsed in a array with msg arrays by the parseFetch function |
2011 | */ |
2012 | if ($aUpdatedMsgs) { |
2013 | // Update the message headers cache |
2014 | $aDeleted = array(); |
2015 | foreach ($aUpdatedMsgs as $iUid => $aMsg) { |
2016 | if (isset($aMsg['FLAGS'])) { |
fd28fa79 |
2017 | /** |
ddd209f2 |
2018 | * Only update the cached headers if the header is |
fd28fa79 |
2019 | * cached. |
2020 | */ |
2021 | if (isset($aMailbox['MSG_HEADERS'][$iUid])) { |
2022 | $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS']; |
2023 | } |
324ac3c5 |
2024 | /** |
2025 | * Count the messages with the \Delete flag set so we can determine |
2026 | * if the number of expunged messages equals the number of flagged |
2027 | * messages for deletion. |
2028 | */ |
2029 | if (isset($aMsg['FLAGS']['\\deleted']) && $aMsg['FLAGS']['\\deleted']) { |
2030 | $aDeleted[] = $iUid; |
2031 | } |
2032 | } |
2033 | } |
2034 | if ($bExpunge && $aMailbox['AUTO_EXPUNGE'] && |
2035 | $iExpungedMessages = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true)) |
2036 | { |
2037 | if (count($aDeleted) != $iExpungedMessages) { |
2038 | // there are more messages deleted permanently then we expected |
2039 | // invalidate the cache |
2040 | $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = false; |
2041 | $aMailbox['MSG_HEADERS'] = false; |
2042 | } else { |
2043 | // remove expunged messages from cache |
2044 | $aUidSet = $aMailbox['UIDSET'][$aMailbox['SETINDEX']]; |
2045 | if (is_array($aUidSet)) { |
2046 | // create a UID => array index temp array |
2047 | $aUidSetDummy = array_flip($aUidSet); |
2048 | foreach ($aDeleted as $iUid) { |
2049 | // get the id as well in case of SQM_SORT_NONE |
2050 | if ($aMailbox['SORT'] == SQSORT_NONE) { |
2051 | $aMailbox['ID'] = false; |
2052 | //$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID']; |
2053 | //unset($aMailbox['ID'][$iId]); |
2054 | } |
2055 | // unset the UID and message header |
2056 | unset($aUidSetDummy[$iUid]); |
2057 | unset($aMailbox['MSG_HEADERS'][$iUid]); |
2058 | } |
2059 | $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy); |
324ac3c5 |
2060 | } |
2061 | } |
ddd209f2 |
2062 | // update EXISTS info |
2063 | if ($iExpungedMessages) { |
2064 | $aMailbox['EXISTS'] -= (int) $iExpungedMessages; |
2065 | } |
324ac3c5 |
2066 | // Change the startMessage number if the mailbox was changed |
4c284a74 |
2067 | if (($aMailbox['PAGEOFFSET']-1) >= $aMailbox['EXISTS']) { |
324ac3c5 |
2068 | $aMailbox['PAGEOFFSET'] = ($aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT']) ? |
2069 | $aMailbox['PAGEOFFSET'] - $aMailbox['LIMIT'] : 1; |
91e0dccc |
2070 | $aMailbox['OFFSET'] = $aMailbox['PAGEOFFSET'] - 1 ; |
324ac3c5 |
2071 | } |
2072 | } |
2073 | } |
2074 | } else { |
2075 | if ($sButton == 'expunge') { |
2076 | /** |
2077 | * on expunge we do not know which messages will be deleted |
2078 | * so it's useless to try to sync the cache |
2079 | |
2080 | * Close the mailbox so we do not need to parse the untagged expunge |
2081 | * responses which do not contain uid info. |
2082 | * NB: Closing a mailbox is faster then expunge because the imap |
2083 | * server does not need to generate the untagged expunge responses |
2084 | */ |
2085 | sqimap_run_command($imapConnection,'CLOSE',false,$result,$message); |
2086 | $aMbxResponse = sqimap_mailbox_select($imapConnection,$aMailbox['NAME']); |
2087 | // update the $aMailbox array |
2088 | $aMailbox['EXISTS'] = $aMbxResponse['EXISTS']; |
2089 | $aMailbox['UIDSET'] = false; |
2090 | } else { |
2091 | if ($sButton) { |
2092 | $sError = _("No messages were selected."); |
2093 | } |
2094 | } |
2095 | } |
2096 | return $sError; |
2097 | } |
2098 | |
2099 | function attachSelectedMessages($imapConnection,$aMsgHeaders) { |
2100 | global $username, $attachment_dir, |
2101 | $data_dir, $composesession, |
2102 | $compose_messages; |
2103 | |
2104 | if (!isset($compose_messages)) { |
2105 | $compose_messages = array(); |
2106 | sqsession_register($compose_messages,'compose_messages'); |
2107 | } |
2108 | |
2109 | if (!$composesession) { |
2110 | $composesession = 1; |
2111 | sqsession_register($composesession,'composesession'); |
2112 | } else { |
2113 | $composesession++; |
2114 | sqsession_register($composesession,'composesession'); |
2115 | } |
2116 | |
2117 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
2118 | |
2119 | $composeMessage = new Message(); |
2120 | $rfc822_header = new Rfc822Header(); |
2121 | $composeMessage->rfc822_header = $rfc822_header; |
2122 | $composeMessage->reply_rfc822_header = ''; |
2123 | |
2124 | foreach($aMsgHeaders as $iUid => $aMsgHeader) { |
2125 | /** |
2126 | * Retrieve the full message |
2127 | */ |
2128 | $body_a = sqimap_run_command($imapConnection, "FETCH $iUid RFC822", true, $response, $readmessage, TRUE); |
2129 | |
2130 | if ($response == 'OK') { |
2131 | $subject = (isset($aMsgHeader['SUBJECT'])) ? $aMsgHeader['SUBJECT'] : $iUid; |
2132 | |
2133 | array_shift($body_a); |
2134 | array_pop($body_a); |
2135 | $body = implode('', $body_a); |
2136 | $body .= "\r\n"; |
2137 | |
2138 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
2139 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
2140 | |
2141 | $fp = fopen( $full_localfilename, 'wb'); |
2142 | fwrite ($fp, $body); |
2143 | fclose($fp); |
2144 | $composeMessage->initAttachment('message/rfc822',$subject.'.msg', |
2145 | $full_localfilename); |
2146 | } |
2147 | } |
2148 | |
2149 | $compose_messages[$composesession] = $composeMessage; |
2150 | sqsession_register($compose_messages,'compose_messages'); |
2151 | return $composesession; |
2152 | } |
2153 | |
043f9c14 |
2154 | // vim: et ts=4 |
d3b3a524 |
2155 | ?> |