59177427 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
4 | * mailbox_display.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
35586184 |
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 | * $Id$ |
13 | */ |
a4c2cd49 |
14 | |
b68edc75 |
15 | require_once(SM_PATH . 'functions/strings.php'); |
16 | require_once(SM_PATH . 'functions/html.php'); |
17 | require_once(SM_PATH . 'class/html.class.php'); |
18 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
43fdb2a4 |
19 | |
6c930ade |
20 | /* Default value for page_selector_max. */ |
21 | define('PG_SEL_MAX', 10); |
22 | |
098ea084 |
23 | function elapsed($start) |
24 | { |
25 | $end = microtime(); |
26 | list($start2, $start1) = explode(" ", $start); |
27 | list($end2, $end1) = explode(" ", $end); |
28 | $diff1 = $end1 - $start1; |
29 | $diff2 = $end2 - $start2; |
30 | if( $diff2 < 0 ){ |
31 | $diff1 -= 1; |
32 | $diff2 += 1.0; |
33 | } |
34 | return $diff2 + $diff1; |
35 | } |
36 | |
7b887886 |
37 | function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox, |
d215ca7d |
38 | $start_msg, $where, $what) { |
8008456a |
39 | global $checkall, |
5bba30b5 |
40 | $color, $msgs, $msort, $td_str, $msg, |
c1c17724 |
41 | $default_use_priority, |
42 | $message_highlight_list, |
43 | $index_order, |
44 | $indent_array, /* indent subject by */ |
45 | $pos, /* Search postion (if any) */ |
46 | $thread_sort_messages, /* thread sorting on/off */ |
47 | $server_sort_order, /* sort value when using server-sorting */ |
48 | $row_count, |
49 | $allow_server_sort; /* enable/disable server-side sorting */ |
e9e5f0fa |
50 | $color_string = $color[4]; |
8008456a |
51 | |
52 | if ($GLOBALS['alt_index_colors']) { |
53 | if (!isset($row_count)) { |
54 | $row_count = 0; |
55 | } |
56 | $row_count++; |
57 | if ($row_count % 2) { |
58 | if (!isset($color[12])) { |
59 | $color[12] = '#EAEAEA'; |
60 | } |
61 | $color_string = $color[12]; |
62 | } |
bdfb67f8 |
63 | } |
8008456a |
64 | $msg = $msgs[$key]; |
65 | |
6a622b59 |
66 | if($mailbox == 'None') { |
67 | $boxes = sqimap_mailbox_list($imapConnection); |
8008456a |
68 | $mailbox = $boxes[0]['unformatted']; |
6a622b59 |
69 | unset($boxes); |
bdfb67f8 |
70 | } |
8008456a |
71 | $urlMailbox = urlencode($mailbox); |
e9e5f0fa |
72 | |
73 | if (handleAsSent($mailbox)) { |
74 | $msg['FROM'] = $msg['TO']; |
098ea084 |
75 | } |
e9e5f0fa |
76 | /* |
77 | * This is done in case you're looking into Sent folders, |
78 | * because you can have multiple receivers. |
79 | */ |
937c81fa |
80 | |
098ea084 |
81 | $senderNames = $msg['FROM']; |
82 | $senderName = ''; |
83 | if (sizeof($senderNames)){ |
84 | foreach ($senderNames as $senderNames_part) { |
e9e5f0fa |
85 | if ($senderName != '') { |
86 | $senderName .= ', '; |
87 | } |
098ea084 |
88 | if ($senderNames_part[1]) { |
89 | $senderName .= decodeHeader($senderNames_part[1]); |
90 | } else { |
91 | $senderName .= htmlspecialchars($senderNames_part[0]); |
92 | } |
93 | } |
937c81fa |
94 | } |
95 | |
c96c32f4 |
96 | $subject_full = decodeHeader($msg['SUBJECT']); |
97 | $subject = processSubject($subject_full, $indent_array[$msg['ID']]); |
a966982b |
98 | |
5786ef5a |
99 | echo html_tag( 'tr','','','','VALIGN="top"') . "\n"; |
8008456a |
100 | |
101 | if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) { |
102 | $flag = "<font color=\"$color[2]\">"; |
103 | $flag_end = '</font>'; |
104 | } else { |
105 | $flag = ''; |
106 | $flag_end = ''; |
bdfb67f8 |
107 | } |
8008456a |
108 | if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) { |
109 | $bold = '<b>'; |
110 | $bold_end = '</b>'; |
111 | } else { |
112 | $bold = ''; |
113 | $bold_end = ''; |
bdfb67f8 |
114 | } |
8008456a |
115 | if (handleAsSent($mailbox)) { |
116 | $italic = '<i>'; |
117 | $italic_end = '</i>'; |
118 | } else { |
119 | $italic = ''; |
120 | $italic_end = ''; |
121 | } |
122 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
123 | $fontstr = "<font color=\"$color[9]\">"; |
124 | $fontstr_end = '</font>'; |
125 | } else { |
126 | $fontstr = ''; |
127 | $fontstr_end = ''; |
128 | } |
129 | |
d215ca7d |
130 | if ($where && $what) { |
131 | $searchstr = '&where='.$where.'&what='.$what; |
132 | } else { |
133 | $searchstr = ''; |
6a622b59 |
134 | } |
8008456a |
135 | /** |
136 | * AAAAH! Make my eyes stop bleeding! |
137 | * Who wrote this?! |
138 | */ |
937c81fa |
139 | if (is_array($message_highlight_list) && count($message_highlight_list)) { |
8008456a |
140 | foreach ($message_highlight_list as $message_highlight_list_part) { |
141 | if (trim($message_highlight_list_part['value']) != '') { |
c0d04f97 |
142 | $high_val = strtolower($message_highlight_list_part['value']); |
143 | $match_type = strtoupper($message_highlight_list_part['match_type']); |
937c81fa |
144 | switch($match_type) { |
145 | case('TO'): |
146 | case('TO_CC'): |
147 | foreach ($msg['TO'] as $address) { |
148 | if (strstr('^^' . strtolower($address[0]), $high_val) || |
149 | strstr('^^' . strtolower($address[1]), $high_val)) { |
150 | $hlt_color = $message_highlight_list_part['color']; |
151 | continue; |
152 | } |
098ea084 |
153 | } |
937c81fa |
154 | if($match_type != 'TO_CC') { |
155 | break; |
156 | } |
157 | case('CC'): |
158 | foreach ($msg['CC'] as $address) { |
159 | if( strstr('^^' . strtolower($address[0]), $high_val) || |
160 | strstr('^^' . strtolower($address[1]), $high_val)) { |
161 | $hlt_color = $message_highlight_list_part['color']; |
162 | continue; |
163 | } |
164 | } |
165 | break; |
166 | case('FROM'): |
167 | foreach ($msg['FROM'] as $address) { |
168 | if( strstr('^^' . strtolower($address[0]), $high_val) || |
169 | strstr('^^' . strtolower($address[1]), $high_val)) { |
170 | $hlt_color = $message_highlight_list_part['color']; |
171 | continue; |
172 | } |
173 | } |
174 | break; |
175 | default: |
176 | if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) { |
098ea084 |
177 | $hlt_color = $message_highlight_list_part['color']; |
178 | continue; |
179 | } |
937c81fa |
180 | break; |
8008456a |
181 | } |
182 | } |
183 | } |
184 | } |
185 | |
186 | if (!isset($hlt_color)) { |
187 | $hlt_color = $color_string; |
188 | } |
59352d08 |
189 | $checked = ($checkall == 1) ? ' CHECKED' : ''; |
5e0efebf |
190 | $col = 0; |
6a622b59 |
191 | if (sizeof($index_order)) { |
8008456a |
192 | foreach ($index_order as $index_order_part) { |
193 | switch ($index_order_part) { |
194 | case 1: /* checkbox */ |
195 | echo html_tag( 'td', |
196 | "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>", |
6a622b59 |
197 | 'center', |
8008456a |
198 | $hlt_color ); |
199 | break; |
200 | case 2: /* from */ |
201 | echo html_tag( 'td', |
098ea084 |
202 | $italic . $bold . $flag . $fontstr . $senderName . |
8008456a |
203 | $fontstr_end . $flag_end . $bold_end . $italic_end, |
c1c17724 |
204 | 'left', |
8008456a |
205 | $hlt_color ); |
206 | break; |
207 | case 3: /* date */ |
53d9fbc5 |
208 | $date_string = $msg['DATE_STRING'] . ''; |
209 | if ($date_string == '') { |
210 | $date_string = _("Unknown date"); |
211 | } |
8008456a |
212 | echo html_tag( 'td', |
53d9fbc5 |
213 | $bold . $flag . $fontstr . $date_string . |
8008456a |
214 | $fontstr_end . $flag_end . $bold_end, |
215 | 'center', |
216 | $hlt_color, |
217 | 'nowrap' ); |
218 | break; |
219 | case 4: /* subject */ |
220 | $td_str = $bold; |
221 | if ($thread_sort_messages == 1) { |
6903c7bd |
222 | if (isset($indent_array[$msg['ID']])) { |
8008456a |
223 | $td_str .= str_repeat(" ",$indent_array[$msg['ID']]); |
224 | } |
225 | } |
e9e5f0fa |
226 | $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox |
6a622b59 |
227 | . '&passed_id='. $msg["ID"] |
228 | . '&startMessage='.$start_msg.$searchstr.'"'; |
e17d0c83 |
229 | $td_str .= ' ' .concat_hook_function('subject_link'); |
c96c32f4 |
230 | if ($subject != $subject_full) { |
8008456a |
231 | $title = get_html_translation_table(HTML_SPECIALCHARS); |
232 | $title = array_flip($title); |
c96c32f4 |
233 | $title = strtr($subject_full, $title); |
8008456a |
234 | $title = str_replace('"', "''", $title); |
235 | $td_str .= " title=\"$title\""; |
236 | } |
237 | $td_str .= ">$flag$subject$flag_end</a>$bold_end"; |
c1c17724 |
238 | echo html_tag( 'td', $td_str, 'left', $hlt_color ); |
8008456a |
239 | break; |
240 | case 5: /* flags */ |
241 | $stuff = false; |
242 | $td_str = "<b><small>"; |
6a622b59 |
243 | |
8008456a |
244 | if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) { |
245 | $td_str .= _("A"); |
246 | $stuff = true; |
247 | } |
248 | if ($msg['TYPE0'] == 'multipart') { |
249 | $td_str .= '+'; |
250 | $stuff = true; |
251 | } |
252 | if ($default_use_priority) { |
253 | if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) { |
254 | $td_str .= "<font color=\"$color[1]\">!</font>"; |
255 | $stuff = true; |
256 | } |
257 | if ($msg['PRIORITY'] == 5) { |
258 | $td_str .= "<font color=\"$color[8]\">?</font>"; |
259 | $stuff = true; |
260 | } |
261 | } |
262 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) { |
263 | $td_str .= "<font color=\"$color[1]\">D</font>"; |
264 | $stuff = true; |
265 | } |
266 | if (!$stuff) { |
267 | $td_str .= ' '; |
268 | } |
2bd00b7b |
269 | do_hook("msg_envelope"); |
8008456a |
270 | $td_str .= '</small></b>'; |
271 | echo html_tag( 'td', |
272 | $td_str, |
273 | 'center', |
274 | $hlt_color, |
275 | 'nowrap' ); |
276 | break; |
277 | case 6: /* size */ |
8008456a |
278 | echo html_tag( 'td', |
6a622b59 |
279 | $bold . $fontstr . show_readable_size($msg['SIZE']) . |
8008456a |
280 | $fontstr_end . $bold_end, |
281 | 'right', |
282 | $hlt_color ); |
283 | break; |
284 | } |
ed230bc3 |
285 | ++$col; |
8008456a |
286 | } |
bdfb67f8 |
287 | } |
7b887886 |
288 | if ($not_last) { |
ed230bc3 |
289 | echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' . |
290 | $color[0] . '" HEIGHT="1"></td></tr>' . "\n"; |
6a622b59 |
291 | } else { |
7b887886 |
292 | echo '</tr>'."\n"; |
6a622b59 |
293 | } |
e9e5f0fa |
294 | } |
295 | |
ed230bc3 |
296 | function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) { |
297 | if ($id != 'no') { |
098ea084 |
298 | $id = array_slice($id, ($start_msg-1), $show_num); |
ed230bc3 |
299 | $end = $start_msg + $show_num - 1; |
300 | if ($num_msgs < $show_num) { |
301 | $end_loop = $num_msgs; |
302 | } else if ($end > $num_msgs) { |
303 | $end_loop = $num_msgs - $start_msg + 1; |
304 | } else { |
305 | $end_loop = $show_num; |
306 | } |
307 | return fillMessageArray($imapConnection,$id,$end_loop); |
308 | } else { |
309 | return false; |
310 | } |
311 | } |
312 | |
313 | function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) { |
314 | $id = get_thread_sort($imapConnection); |
315 | return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); |
316 | } |
317 | |
6a622b59 |
318 | function getServerSortMessages($imapConnection, $start_msg, $show_num, |
ed230bc3 |
319 | $num_msgs, $server_sort_order, $mbxresponse) { |
320 | $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse); |
321 | return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); |
e9e5f0fa |
322 | } |
323 | |
6a622b59 |
324 | function getSelfSortMessages($imapConnection, $start_msg, $show_num, |
e9e5f0fa |
325 | $num_msgs, $sort, $mbxresponse) { |
ed230bc3 |
326 | $msgs = array(); |
327 | if ($num_msgs >= 1) { |
328 | $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse); |
329 | if ($sort < 6 ) { |
330 | $end = $num_msgs; |
331 | $end_loop = $end; |
332 | } else { |
333 | /* if it's not sorted */ |
334 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
335 | $end_msg = $start_msg + ($show_num - 1); |
336 | } else { |
337 | $end_msg = $num_msgs; |
338 | } |
339 | if ($end_msg < $start_msg) { |
340 | $start_msg = $start_msg - $show_num; |
341 | if ($start_msg < 1) { |
342 | $start_msg = 1; |
343 | } |
344 | } |
098ea084 |
345 | $id = array_slice(array_reverse($id), ($start_msg-1), $show_num); |
ed230bc3 |
346 | $end = $start_msg + $show_num - 1; |
347 | if ($num_msgs < $show_num) { |
348 | $end_loop = $num_msgs; |
349 | } else if ($end > $num_msgs) { |
350 | $end_loop = $num_msgs - $start_msg + 1; |
351 | } else { |
352 | $end_loop = $show_num; |
353 | } |
354 | } |
36ac3582 |
355 | $msgs = fillMessageArray($imapConnection,$id,$end_loop); |
e9e5f0fa |
356 | } |
ed230bc3 |
357 | return $msgs; |
e9e5f0fa |
358 | } |
359 | |
360 | |
361 | |
6c930ade |
362 | /* |
e35045b7 |
363 | * This function loops through a group of messages in the mailbox |
364 | * and shows them to the user. |
365 | */ |
6a622b59 |
366 | function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, |
367 | $start_msg, $sort, $color, $show_num, |
368 | $use_cache, $mode='') { |
fcba142a |
369 | global $msgs, $msort, $auto_expunge, $thread_sort_messages, |
6a622b59 |
370 | $allow_server_sort, $server_sort_order; |
371 | |
167d7428 |
372 | /* |
373 | * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc |
374 | * so setting it to an empty array beforehand seems to clean up the issue, and stopping the |
375 | * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error |
376 | */ |
377 | |
378 | if (!isset($msort)) { |
379 | $msort = array(); |
380 | } |
381 | |
49ae9d34 |
382 | if (!isset($msgs)) { |
383 | $msgs = array(); |
384 | } |
385 | |
098ea084 |
386 | $start = microtime(); |
6a622b59 |
387 | /* If autoexpunge is turned on, then do it now. */ |
388 | $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox); |
389 | $srt = $sort; |
390 | /* If autoexpunge is turned on, then do it now. */ |
391 | if ($auto_expunge == true) { |
392 | $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, ''); |
393 | $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt; |
394 | $num_msgs = $mbxresponse['EXISTS']; |
395 | } |
e35045b7 |
396 | |
6a622b59 |
397 | if ($mbxresponse['EXISTS'] > 0) { |
398 | /* if $start_msg is lower than $num_msgs, we probably deleted all messages |
399 | * in the last page. We need to re-adjust the start_msg |
400 | */ |
aa0da530 |
401 | |
6a622b59 |
402 | if($start_msg > $num_msgs) { |
403 | $start_msg -= $show_num; |
404 | if($start_msg < 1) { |
405 | $start_msg = 1; |
406 | } |
e9e5f0fa |
407 | } |
4e9f35e4 |
408 | |
6a622b59 |
409 | /* This code and the next if() block check for |
410 | * server-side sorting methods. The $id array is |
411 | * formatted and $sort is set to 6 to disable |
412 | * SM internal sorting |
413 | */ |
414 | |
415 | if ($thread_sort_messages == 1) { |
416 | $mode = 'thread'; |
417 | } elseif ($allow_server_sort == 1) { |
418 | $mode = 'serversort'; |
419 | } else { |
420 | $mode = ''; |
421 | } |
8008456a |
422 | |
ed230bc3 |
423 | sqsession_unregister('msort'); |
424 | sqsession_unregister('msgs'); |
6a622b59 |
425 | switch ($mode) { |
426 | case 'thread': |
ed230bc3 |
427 | $id = get_thread_sort($imapConnection); |
428 | $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); |
6a622b59 |
429 | if ($msgs === false) { |
430 | echo '<b><small><center><font color=red>' . |
431 | _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator."). |
432 | '</center></small></b>'; |
433 | $thread_sort_messages = 0; |
434 | $msort = $msgs = array(); |
6a622b59 |
435 | } else { |
436 | $msort= $msgs; |
437 | $sort = 6; |
6a622b59 |
438 | } |
439 | break; |
440 | case 'serversort': |
ed230bc3 |
441 | $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse); |
442 | $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id); |
6a622b59 |
443 | if ($msgs === false) { |
444 | echo '<b><small><center><font color=red>' . |
445 | _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator."). |
446 | '</center></small></b>'; |
447 | $sort = $server_sort_order; |
448 | $allow_server_sort = FALSE; |
449 | $msort = $msgs = array(); |
6a622b59 |
450 | $id = array(); |
451 | } else { |
6a622b59 |
452 | $msort = $msgs; |
ed230bc3 |
453 | $sort = 6; |
6a622b59 |
454 | } |
455 | break; |
456 | default: |
457 | if (!$use_cache) { |
6a622b59 |
458 | $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num, |
459 | $num_msgs, $sort, $mbxresponse); |
460 | $msort = calc_msort($msgs, $sort); |
6a622b59 |
461 | } /* !use cache */ |
462 | break; |
463 | } // switch |
ed230bc3 |
464 | sqsession_register($msort, 'msort'); |
465 | sqsession_register($msgs, 'msgs'); |
6a622b59 |
466 | } /* if exists > 0 */ |
467 | |
468 | $res = getEndMessage($start_msg, $show_num, $num_msgs); |
469 | $start_msg = $res[0]; |
470 | $end_msg = $res[1]; |
471 | |
472 | $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg, |
473 | $num_msgs, $show_num, $sort); |
474 | |
475 | $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); |
476 | |
477 | do_hook('mailbox_index_before'); |
fcba142a |
478 | echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">'; |
22642690 |
479 | echo '<tr><td>'; |
480 | |
481 | mail_message_listing_beginning($imapConnection, $mailbox, $sort, |
482 | $msg_cnt_str, $paginator_str, $start_msg); |
483 | echo '</td></tr>'; |
484 | /* line between the button area and the list */ |
485 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
486 | |
487 | echo '<tr><td>'; |
488 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
489 | echo ' <tr><td>'; |
490 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">'; |
491 | echo '<tr><td>'; |
6a622b59 |
492 | printHeader($mailbox, $srt, $color, !$thread_sort_messages); |
493 | |
22642690 |
494 | displayMessageArray($imapConnection, $num_msgs, $start_msg, |
495 | $msort, $mailbox, $sort, $color, $show_num,0,0); |
496 | echo '</td></tr></table></td></tr></table>'; |
6a622b59 |
497 | |
22642690 |
498 | mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color); |
6a622b59 |
499 | echo '</td></tr></table>'; |
098ea084 |
500 | $t = elapsed($start); |
46a49f65 |
501 | //echo("elapsed time = $t seconds\n"); |
6c930ade |
502 | } |
bdfb67f8 |
503 | |
e9e5f0fa |
504 | function calc_msort($msgs, $sort) { |
8008456a |
505 | |
e35045b7 |
506 | /* |
507 | * 0 = Date (up) |
508 | * 1 = Date (dn) |
509 | * 2 = Name (up) |
510 | * 3 = Name (dn) |
511 | * 4 = Subject (up) |
512 | * 5 = Subject (dn) |
513 | */ |
625c8b78 |
514 | |
6a622b59 |
515 | if (($sort == 0) || ($sort == 1)) { |
625c8b78 |
516 | foreach ($msgs as $item) { |
517 | $msort[] = $item['TIME_STAMP']; |
518 | } |
6a622b59 |
519 | } elseif (($sort == 2) || ($sort == 3)) { |
625c8b78 |
520 | foreach ($msgs as $item) { |
521 | $msort[] = $item['FROM-SORT']; |
522 | } |
6a622b59 |
523 | } elseif (($sort == 4) || ($sort == 5)) { |
625c8b78 |
524 | foreach ($msgs as $item) { |
525 | $msort[] = $item['SUBJECT-SORT']; |
526 | } |
6a622b59 |
527 | } else { |
528 | $msort = $msgs; |
529 | } |
530 | if ($sort < 6) { |
531 | if ($sort % 2) { |
532 | asort($msort); |
533 | } else { |
534 | arsort($msort); |
535 | } |
536 | } |
537 | return $msort; |
538 | } |
539 | |
540 | function fillMessageArray($imapConnection, $id, $count) { |
cef054e4 |
541 | return sqimap_get_small_header_list($imapConnection, $id); |
e35045b7 |
542 | } |
8008456a |
543 | |
e9e5f0fa |
544 | |
e35045b7 |
545 | /* Generic function to convert the msgs array into an HTML table. */ |
6a622b59 |
546 | function displayMessageArray($imapConnection, $num_msgs, $start_msg, |
547 | $msort, $mailbox, $sort, $color, |
548 | $show_num, $where=0, $what=0) { |
59352d08 |
549 | global $imapServerAddress, $use_mailbox_cache, $index_order, |
6a622b59 |
550 | $indent_array, $thread_sort_messages, $allow_server_sort, |
551 | $server_sort_order, $PHP_SELF; |
552 | |
553 | $res = getEndMessage($start_msg, $show_num, $num_msgs); |
554 | $start_msg = $res[0]; |
555 | $end_msg = $res[1]; |
a966982b |
556 | |
6a622b59 |
557 | $urlMailbox = urlencode($mailbox); |
e9e5f0fa |
558 | |
6a622b59 |
559 | /* get indent level for subject display */ |
540c4435 |
560 | if ($thread_sort_messages == 1 && $num_msgs) { |
6a622b59 |
561 | $indent_array = get_parent_level($imapConnection); |
94ac35c6 |
562 | } |
a966982b |
563 | |
6a622b59 |
564 | $real_startMessage = $start_msg; |
565 | if ($sort == 6) { |
566 | if ($end_msg - $start_msg < $show_num - 1) { |
567 | $end_msg = $end_msg - $start_msg + 1; |
568 | $start_msg = 1; |
569 | } else if ($start_msg > $show_num) { |
570 | $end_msg = $show_num; |
571 | $start_msg = 1; |
572 | } |
573 | } |
574 | $endVar = $end_msg + 1; |
575 | |
576 | /* |
577 | * Loop through and display the info for each message. |
578 | * ($t is used for the checkbox number) |
579 | */ |
580 | $t = 0; |
581 | |
582 | /* messages display */ |
583 | |
540c4435 |
584 | if (!$num_msgs) { |
e35045b7 |
585 | /* if there's no messages in this folder */ |
8008456a |
586 | echo html_tag( 'tr', |
13cf639b |
587 | html_tag( 'td', |
6b4bd11f |
588 | "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ", |
13cf639b |
589 | 'center', |
590 | $color[4], |
591 | 'COLSPAN="' . count($index_order) . '"' |
592 | ) |
6a622b59 |
593 | ); |
594 | } elseif ($start_msg == $end_msg) { |
e35045b7 |
595 | /* if there's only one message in the box, handle it differently. */ |
6a622b59 |
596 | if ($sort != 6) { |
597 | $i = $start_msg; |
598 | } else { |
599 | $i = 1; |
600 | } |
601 | reset($msort); |
602 | $k = 0; |
603 | do { |
604 | $key = key($msort); |
605 | next($msort); |
606 | $k++; |
607 | } while (isset ($key) && ($k < $i)); |
7b887886 |
608 | printMessageInfo($imapConnection, $t, true, $key, $mailbox, |
ed230bc3 |
609 | $real_startMessage, $where, $what); |
94ac35c6 |
610 | } else { |
6a622b59 |
611 | $i = $start_msg; |
612 | reset($msort); |
613 | $k = 0; |
614 | do { |
615 | $key = key($msort); |
616 | next($msort); |
617 | $k++; |
618 | } while (isset ($key) && ($k < $i)); |
ed230bc3 |
619 | $not_last = true; |
6a622b59 |
620 | do { |
ed230bc3 |
621 | if (!$i || $i == $endVar-1) $not_last = false; |
622 | printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox, |
623 | $real_startMessage, $where, $what); |
6a622b59 |
624 | $key = key($msort); |
625 | $t++; |
626 | $i++; |
627 | next($msort); |
628 | } while ($i && $i < $endVar); |
94ac35c6 |
629 | } |
bdfb67f8 |
630 | } |
631 | |
6c930ade |
632 | /* |
e35045b7 |
633 | * Displays the standard message list header. To finish the table, |
634 | * you need to do a "</table></table>"; |
635 | * |
636 | * $moveURL is the URL to submit the delete/move form to |
637 | * $mailbox is the current mailbox |
638 | * $sort is the current sorting method (-1 for no sorting available [searches]) |
639 | * $Message is a message that is centered on top of the list |
640 | * $More is a second line that is left aligned |
641 | */ |
e35045b7 |
642 | |
6a622b59 |
643 | function mail_message_listing_beginning ($imapConnection, |
644 | $mailbox = '', $sort = -1, |
645 | $msg_cnt_str = '', |
646 | $paginator = ' ', |
647 | $start_msg = 1) { |
648 | global $color, $auto_expunge, $base_uri, $thread_sort_messages, |
649 | $allow_thread_sort, $allow_server_sort, $server_sort_order, |
650 | $PHP_SELF; |
651 | |
652 | $php_self = $PHP_SELF; |
653 | /* fix for incorrect $PHP_SELF */ |
654 | if (strpos($php_self, 'move_messages.php')) { |
655 | $php_self = str_replace('move_messages.php', 'right_main.php', $php_self); |
656 | } |
657 | $urlMailbox = urlencode($mailbox); |
e35045b7 |
658 | |
6a622b59 |
659 | if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) { |
660 | $source_url = $regs[1]; |
661 | } else { |
662 | $source_url = $php_self; |
663 | } |
664 | |
665 | if (!isset($msg)) { |
666 | $msg = ''; |
667 | } |
8fe969f6 |
668 | $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' . |
669 | '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' . |
670 | '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">'; |
671 | |
672 | // $moveURL = "move_messages.php?msg=$msg&mailbox=$urlMailbox" |
673 | // . "&startMessage=$start_msg"; |
6a622b59 |
674 | /* |
675 | * This is the beginning of the message list table. |
676 | * It wraps around all messages |
677 | */ |
8fe969f6 |
678 | echo '<form name="messageList" method="post" action="move_messages.php">' ."\n" |
679 | . $moveFields |
22642690 |
680 | . html_tag( 'table' , |
c1c17724 |
681 | html_tag( 'tr', |
682 | html_tag( 'td' , |
683 | html_tag( 'table' , |
684 | html_tag( 'tr', |
685 | html_tag( 'td', $paginator, 'left' ) . |
22642690 |
686 | html_tag( 'td', $msg_cnt_str, 'right' ) |
c1c17724 |
687 | ) |
22642690 |
688 | , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) |
c1c17724 |
689 | , 'left', '', '' ) |
690 | , '', $color[0] ) |
22642690 |
691 | , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ); |
4b920601 |
692 | /* line between header and button area */ |
22642690 |
693 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>'; |
22642690 |
694 | |
4b920601 |
695 | echo '<tr><td>'; |
22642690 |
696 | echo html_tag( 'tr' ) . "\n" |
697 | . html_tag( 'td' ,'' , 'left', '', '' ) |
698 | . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) |
699 | . '<tr><td>' |
700 | . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) |
c1c17724 |
701 | . html_tag( 'tr', |
22642690 |
702 | getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') . |
703 | getSmallStringCell(_("Transform Selected Messages"), 'right') |
c1c17724 |
704 | ) |
e9e5f0fa |
705 | . html_tag( 'tr' ) ."\n" |
706 | . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' ); |
22642690 |
707 | getMbxList($imapConnection); |
708 | echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n"; |
709 | echo getButton('SUBMIT', 'attache',_("Forward")) . "\n"; |
6c930ade |
710 | |
22642690 |
711 | echo " </TD>\n" |
6a622b59 |
712 | . html_tag( 'td', '', 'right', '', 'nowrap' ); |
e35045b7 |
713 | |
22642690 |
714 | |
715 | |
6a622b59 |
716 | if (!$auto_expunge) { |
717 | echo getButton('SUBMIT', 'expungeButton',_("Expunge")) |
718 | .' ' . _("mailbox") . "\n"; |
719 | } |
e35045b7 |
720 | |
6a622b59 |
721 | echo getButton('SUBMIT', 'markRead',_("Read")); |
722 | echo getButton('SUBMIT', 'markUnread',_("Unread")); |
8e724112 |
723 | echo getButton('SUBMIT', 'delete',_("Delete")) ." \n"; |
6a622b59 |
724 | if (!strpos($php_self,'mailbox')) { |
725 | $location = $php_self.'?mailbox=INBOX&startMessage=1'; |
726 | } else { |
727 | $location = $php_self; |
8008456a |
728 | } |
6a622b59 |
729 | echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">'; |
730 | echo "</TD>\n" |
731 | . " </TR>\n"; |
732 | |
733 | /* draws thread sorting links */ |
734 | if ($allow_thread_sort == TRUE) { |
735 | if ($thread_sort_messages == 1 ) { |
736 | $set_thread = 2; |
737 | $thread_name = _("Unthread View"); |
738 | } elseif ($thread_sort_messages == 0) { |
739 | $set_thread = 1; |
740 | $thread_name = _("Thread View"); |
741 | } |
c1c17724 |
742 | echo html_tag( 'tr' , |
743 | html_tag( 'td' , |
e35045b7 |
744 | ' <a href=' . $source_url . '?sort=' |
c1c17724 |
745 | . "$sort" . '&start_messages=1&set_thread=' . "$set_thread" |
746 | . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name |
747 | . '</a></small> ' |
748 | , '', '', '' ) |
749 | , '', '', '' ); |
6a622b59 |
750 | } |
a966982b |
751 | |
22642690 |
752 | echo "</TABLE></td></tr></table></td></tr>\n"; |
a966982b |
753 | |
1b91be0c |
754 | do_hook('mailbox_form_before'); |
6c766fd5 |
755 | |
8008456a |
756 | /* if using server sort we highjack the |
6a622b59 |
757 | * the $sort var and use $server_sort_order |
758 | * instead. but here we reset sort for a bit |
759 | * since its easy |
760 | */ |
8008456a |
761 | if ($allow_server_sort == TRUE) { |
762 | $sort = $server_sort_order; |
763 | } |
e9e5f0fa |
764 | } |
a966982b |
765 | |
e9e5f0fa |
766 | function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) { |
22642690 |
767 | if ($num_msgs) { |
4b920601 |
768 | /* space between list and footer */ |
22642690 |
769 | echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">'; |
4b920601 |
770 | |
22642690 |
771 | echo '</td></tr><tr><td>'; |
772 | echo html_tag( 'table', |
e9e5f0fa |
773 | html_tag( 'tr', |
774 | html_tag( 'td', |
775 | html_tag( 'table', |
776 | html_tag( 'tr', |
777 | html_tag( 'td', $paginator_str ) . |
778 | html_tag( 'td', $msg_cnt_str, 'right' ) |
779 | ) |
22642690 |
780 | , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' ) |
e9e5f0fa |
781 | ) |
22642690 |
782 | ) |
783 | , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' ); |
784 | echo '</td></tr>'; |
785 | } |
6a622b59 |
786 | /* End of message-list table */ |
a966982b |
787 | |
6a622b59 |
788 | do_hook('mailbox_index_after'); |
789 | echo "</FORM>\n"; |
a966982b |
790 | } |
791 | |
e9e5f0fa |
792 | function printHeader($mailbox, $sort, $color, $showsort=true) { |
6a622b59 |
793 | global $index_order; |
1b91be0c |
794 | echo html_tag( 'tr' ,'' , 'center', $color[5] ); |
e4b5f9d1 |
795 | |
796 | /* calculate the width of the subject column based on the |
797 | * widths of the other columns */ |
798 | $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5); |
799 | $subjectwidth = 100; |
800 | foreach($index_order as $item) { |
801 | $subjectwidth -= $widths[$item]; |
802 | } |
803 | |
804 | foreach ($index_order as $item) { |
805 | switch ($item) { |
8008456a |
806 | case 1: /* checkbox */ |
807 | case 5: /* flags */ |
1b91be0c |
808 | echo html_tag( 'td' ,' ' , '', '', 'width="1%"' ); |
8008456a |
809 | break; |
810 | case 2: /* from */ |
811 | if (handleAsSent($mailbox)) { |
1b91be0c |
812 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
6a622b59 |
813 | . '<b>' . _("To") . '</b>'; |
8008456a |
814 | } else { |
1b91be0c |
815 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
6a622b59 |
816 | . '<b>' . _("From") . '</b>'; |
8008456a |
817 | } |
a966982b |
818 | if ($showsort) { |
1b91be0c |
819 | ShowSortButton($sort, $mailbox, 2, 3); |
8008456a |
820 | } |
1b91be0c |
821 | echo "</td>\n"; |
8008456a |
822 | break; |
823 | case 3: /* date */ |
1b91be0c |
824 | echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' ) |
6a622b59 |
825 | . '<b>' . _("Date") . '</b>'; |
a966982b |
826 | if ($showsort) { |
1b91be0c |
827 | ShowSortButton($sort, $mailbox, 0, 1); |
8008456a |
828 | } |
1b91be0c |
829 | echo "</td>\n"; |
8008456a |
830 | break; |
a966982b |
831 | case 4: /* subject */ |
e4b5f9d1 |
832 | echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' ) |
6a622b59 |
833 | . '<b>' . _("Subject") . '</b>'; |
a966982b |
834 | if ($showsort) { |
1b91be0c |
835 | ShowSortButton($sort, $mailbox, 4, 5); |
8008456a |
836 | } |
1b91be0c |
837 | echo "</td>\n"; |
8008456a |
838 | break; |
839 | case 6: /* size */ |
e842b215 |
840 | echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' ); |
8008456a |
841 | break; |
842 | } |
bdfb67f8 |
843 | } |
1b91be0c |
844 | echo "</tr>\n"; |
bdfb67f8 |
845 | } |
846 | |
e9e5f0fa |
847 | |
bdfb67f8 |
848 | /* |
e35045b7 |
849 | * This function shows the sort button. Isn't this a good comment? |
850 | */ |
851 | function ShowSortButton($sort, $mailbox, $Up, $Down ) { |
6a622b59 |
852 | global $PHP_SELF; |
853 | /* Figure out which image we want to use. */ |
854 | if ($sort != $Up && $sort != $Down) { |
855 | $img = 'sort_none.png'; |
856 | $which = $Up; |
857 | } elseif ($sort == $Up) { |
858 | $img = 'up_pointer.png'; |
859 | $which = $Down; |
6c930ade |
860 | } else { |
6a622b59 |
861 | $img = 'down_pointer.png'; |
862 | $which = 6; |
e35045b7 |
863 | } |
6a622b59 |
864 | |
865 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
866 | $source_url = $regs[1]; |
e35045b7 |
867 | } else { |
6a622b59 |
868 | $source_url = $PHP_SELF; |
6c930ade |
869 | } |
6a622b59 |
870 | |
871 | /* Now that we have everything figured out, show the actual button. */ |
872 | echo ' <a href="' . $source_url .'?newsort=' . $which |
873 | . '&startMessage=1&mailbox=' . urlencode($mailbox) |
874 | . '"><IMG SRC="../images/' . $img |
875 | . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>'; |
876 | } |
877 | |
878 | function get_selectall_link($start_msg, $sort) { |
879 | global $checkall, $what, $where, $mailbox, $javascript_on; |
880 | global $PHP_SELF, $PG_SHOWNUM; |
881 | |
882 | $result = ''; |
883 | if ($javascript_on) { |
884 | $result = '<script language="JavaScript" type="text/javascript">' |
885 | . "\n<!-- \n" |
886 | . "function CheckAll() {\n" |
887 | . " for (var i = 0; i < document.messageList.elements.length; i++) {\n" |
888 | . " if(document.messageList.elements[i].type == 'checkbox'){\n" |
889 | . " document.messageList.elements[i].checked = " |
890 | . " !(document.messageList.elements[i].checked);\n" |
891 | . " }\n" |
892 | . " }\n" |
893 | . "}\n" |
894 | . "//-->\n" |
895 | . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") |
896 | . "</a>\n"; |
e35045b7 |
897 | } else { |
6a622b59 |
898 | if (strpos($PHP_SELF, "?")) { |
899 | $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox) |
900 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
901 | } else { |
902 | $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) |
903 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
904 | } |
905 | if (isset($checkall) && $checkall == '1') { |
906 | $result .= '0'; |
907 | } else { |
908 | $result .= '1'; |
909 | } |
910 | |
911 | if (isset($where) && isset($what)) { |
912 | $result .= '&where=' . urlencode($where) |
913 | . '&what=' . urlencode($what); |
914 | } |
915 | $result .= "\">"; |
916 | |
917 | if (isset($checkall) && ($checkall == '1')) { |
918 | $result .= _("Unselect All"); |
919 | } else { |
920 | $result .= _("Select All"); |
921 | } |
922 | $result .= "</A>\n"; |
e35045b7 |
923 | } |
23d6bd09 |
924 | |
6a622b59 |
925 | /* Return our final result. */ |
926 | return ($result); |
bdfb67f8 |
927 | } |
1a0e0983 |
928 | |
6c930ade |
929 | /* |
e35045b7 |
930 | * This function computes the "Viewing Messages..." string. |
931 | */ |
bdfb67f8 |
932 | function get_msgcnt_str($start_msg, $end_msg, $num_msgs) { |
6a622b59 |
933 | /* Compute the $msg_cnt_str. */ |
934 | $result = ''; |
935 | if ($start_msg < $end_msg) { |
936 | $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), |
937 | $start_msg, $end_msg, $num_msgs); |
938 | } else if ($start_msg == $end_msg) { |
939 | $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg); |
940 | } else { |
941 | $result = '<br>'; |
942 | } |
943 | /* Return our result string. */ |
944 | return ($result); |
bdfb67f8 |
945 | } |
946 | |
6c930ade |
947 | /* |
e35045b7 |
948 | * Generate a paginator link. |
949 | */ |
6c930ade |
950 | function get_paginator_link($box, $start_msg, $use, $text) { |
6a622b59 |
951 | global $PHP_SELF; |
e35045b7 |
952 | |
6a622b59 |
953 | $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use" |
954 | . "&startMessage=$start_msg&mailbox=$box\" " |
955 | . "TARGET=\"right\">$text</A>"; |
956 | return ($result); |
756d0680 |
957 | /* |
6a622b59 |
958 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
959 | $source_url = $regs[1]; |
960 | } else { |
961 | $source_url = $PHP_SELF; |
962 | } |
963 | |
964 | $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use" |
965 | . "&startMessage=$start_msg&mailbox=$box\" " |
966 | . "TARGET=\"right\">$text</A>"; |
967 | return ($result); |
968 | */ |
7b294953 |
969 | } |
970 | |
6c930ade |
971 | /* |
e35045b7 |
972 | * This function computes the paginator string. |
973 | */ |
6a622b59 |
974 | function get_paginator_str($box, $start_msg, $end_msg, $num_msgs, |
975 | $show_num, $sort) { |
976 | global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM; |
977 | |
978 | /* Initialize paginator string chunks. */ |
979 | $prv_str = ''; |
980 | $nxt_str = ''; |
981 | $pg_str = ''; |
982 | $all_str = ''; |
983 | $tgl_str = ''; |
984 | |
985 | $box = urlencode($box); |
986 | |
987 | /* Create simple strings that will be creating the paginator. */ |
988 | $spc = ' '; /* This will be used as a space. */ |
989 | $sep = '|'; /* This will be used as a seperator. */ |
990 | |
991 | /* Get some paginator preference values. */ |
992 | $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON); |
993 | $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX); |
994 | |
995 | /* Make sure that our start message number is not too big. */ |
996 | $start_msg = min($start_msg, $num_msgs); |
997 | |
998 | /* Decide whether or not we will use the mailbox cache. */ |
999 | /* Not sure why $use_mailbox_cache is even passed in. */ |
1000 | if ($sort == 6) { |
1001 | $use = 0; |
1002 | } else { |
1003 | $use = 1; |
1004 | } |
1005 | |
1006 | /* Compute the starting message of the previous and next page group. */ |
1007 | $next_grp = $start_msg + $show_num; |
1008 | $prev_grp = $start_msg - $show_num; |
1009 | |
1010 | /* Compute the basic previous and next strings. */ |
1011 | if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) { |
1012 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
1013 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
1014 | } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) { |
1015 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
1016 | $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n"; |
1017 | } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) { |
1018 | $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>'; |
1019 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
1020 | } |
1021 | |
1022 | /* Page selector block. Following code computes page links. */ |
1023 | if ($pg_sel && ($num_msgs > $show_num)) { |
1024 | /* Most importantly, what is the current page!!! */ |
1025 | $cur_pg = intval($start_msg / $show_num) + 1; |
1026 | |
1027 | /* Compute total # of pages and # of paginator page links. */ |
1028 | $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */ |
1029 | $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */ |
1030 | |
1031 | /* Compute the size of the four quarters of the page links. */ |
1032 | |
1033 | /* If we can, just show all the pages. */ |
1034 | if (($tot_pgs - 1) <= $pg_max) { |
1035 | $q1_pgs = $cur_pg - 1; |
1036 | $q2_pgs = $q3_pgs = 0; |
1037 | $q4_pgs = $tot_pgs - $cur_pg; |
1038 | |
e35045b7 |
1039 | /* Otherwise, compute some magic to choose the four quarters. */ |
6a622b59 |
1040 | } else { |
1041 | /* |
1042 | * Compute the magic base values. Added together, |
1043 | * these values will always equal to the $pag_pgs. |
1044 | * NOTE: These are DEFAULT values and do not take |
1045 | * the current page into account. That is below. |
1046 | */ |
1047 | $q1_pgs = floor($vis_pgs/4); |
1048 | $q2_pgs = round($vis_pgs/4, 0); |
1049 | $q3_pgs = ceil($vis_pgs/4); |
1050 | $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0); |
1051 | |
1052 | /* Adjust if the first quarter contains the current page. */ |
1053 | if (($cur_pg - $q1_pgs) < 1) { |
1054 | $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs; |
1055 | $q1_pgs = $cur_pg - 1; |
1056 | $q2_pgs = 0; |
1057 | $q3_pgs += ceil($extra_pgs / 2); |
1058 | $q4_pgs += floor($extra_pgs / 2); |
1059 | |
1060 | /* Adjust if the first and second quarters intersect. */ |
1061 | } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) { |
1062 | $extra_pgs = $q2_pgs; |
1063 | $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
1064 | $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
1065 | $q3_pgs += ceil($extra_pgs / 2); |
1066 | $q4_pgs += floor($extra_pgs / 2); |
1067 | |
1068 | /* Adjust if the fourth quarter contains the current page. */ |
1069 | } else if (($cur_pg + $q4_pgs) >= $tot_pgs) { |
1070 | $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs; |
1071 | $q3_pgs = 0; |
1072 | $q4_pgs = $tot_pgs - $cur_pg; |
1073 | $q1_pgs += floor($extra_pgs / 2); |
1074 | $q2_pgs += ceil($extra_pgs / 2); |
1075 | |
1076 | /* Adjust if the third and fourth quarter intersect. */ |
1077 | } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) { |
1078 | $extra_pgs = $q3_pgs; |
1079 | $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
1080 | $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
1081 | $q1_pgs += floor($extra_pgs / 2); |
1082 | $q2_pgs += ceil($extra_pgs / 2); |
1083 | } |
1084 | } |
e35045b7 |
1085 | |
6a622b59 |
1086 | /* |
1087 | * I am leaving this debug code here, commented out, because |
1088 | * it is a really nice way to see what the above code is doing. |
1089 | * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " |
1090 | * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; |
1091 | */ |
1092 | |
1093 | /* Print out the page links from the compute page quarters. */ |
1094 | |
1095 | /* Start with the first quarter. */ |
1096 | if (($q1_pgs == 0) && ($cur_pg > 1)) { |
1097 | $pg_str .= "...$spc"; |
1098 | } else { |
1099 | for ($pg = 1; $pg <= $q1_pgs; ++$pg) { |
1100 | $start = (($pg-1) * $show_num) + 1; |
1101 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1102 | } |
1103 | if ($cur_pg - $q2_pgs - $q1_pgs > 1) { |
1104 | $pg_str .= "...$spc"; |
1105 | } |
1106 | } |
1107 | |
1108 | /* Continue with the second quarter. */ |
1109 | for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) { |
1110 | $start = (($pg-1) * $show_num) + 1; |
1111 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1112 | } |
1113 | |
1114 | /* Now print the current page. */ |
1115 | $pg_str .= $cur_pg . $spc; |
1116 | |
1117 | /* Next comes the third quarter. */ |
1118 | for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) { |
1119 | $start = (($pg-1) * $show_num) + 1; |
1120 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1121 | } |
1122 | |
1123 | /* And last, print the forth quarter page links. */ |
1124 | if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) { |
1125 | $pg_str .= "...$spc"; |
1126 | } else { |
1127 | if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) { |
1128 | $pg_str .= "...$spc"; |
1129 | } |
1130 | for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) { |
1131 | $start = (($pg-1) * $show_num) + 1; |
1132 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1133 | } |
1134 | } |
1135 | } else if ($PG_SHOWNUM == 999999) { |
1136 | $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0" |
1137 | . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" " |
1138 | . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc; |
1139 | } |
1140 | |
1141 | /* If necessary, compute the 'show all' string. */ |
1142 | if (($prv_str != '') || ($nxt_str != '')) { |
1143 | $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1" |
1144 | . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" " |
1145 | . "TARGET=\"right\">" . _("Show All") . '</A>'; |
1146 | } |
1147 | |
1148 | /* Last but not least, get the value for the toggle all link. */ |
1149 | $tgl_str = get_selectall_link($start_msg, $sort); |
1150 | |
1151 | /* Put all the pieces of the paginator string together. */ |
1152 | /** |
1153 | * Hairy code... But let's leave it like it is since I am not certain |
1154 | * a different approach would be any easier to read. ;) |
1155 | */ |
1156 | $result = ''; |
1157 | $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : ''); |
1158 | $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : ''); |
1159 | $result .= ($pg_str != '' ? $pg_str : ''); |
1160 | $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : ''); |
1161 | $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str); |
1162 | |
1163 | /* If the resulting string is blank, return a non-breaking space. */ |
1164 | if ($result == '') { |
1165 | $result = ' '; |
1166 | } |
e35045b7 |
1167 | |
6a622b59 |
1168 | /* Return our final magical paginator string. */ |
1169 | return ($result); |
bdfb67f8 |
1170 | } |
1171 | |
6903c7bd |
1172 | function processSubject($subject, $threadlevel = 0) { |
6fbd125b |
1173 | global $languages, $squirrelmail_language; |
6a622b59 |
1174 | /* Shouldn't ever happen -- caught too many times in the IMAP functions */ |
1175 | if ($subject == '') |
1176 | return _("(no subject)"); |
e35045b7 |
1177 | |
6903c7bd |
1178 | $trim_at = 55; |
1179 | |
c2f88417 |
1180 | /* if this is threaded, subtract two chars per indentlevel */ |
6903c7bd |
1181 | if($threadlevel > 0 && $threadlevel <= 10) |
1182 | $trim_at -= (2*$threadlevel); |
1183 | |
1184 | if (strlen($subject) <= $trim_at) |
6a622b59 |
1185 | return $subject; |
1186 | |
46a49f65 |
1187 | $ent_strlen = $orig_len = strlen($subject); |
6903c7bd |
1188 | $trim_val = $trim_at - 5; |
1189 | $ent_offset = 0; |
6a622b59 |
1190 | /* |
1191 | * see if this is entities-encoded string |
1192 | * If so, Iterate through the whole string, find out |
1193 | * the real number of characters, and if more |
46a49f65 |
1194 | * than 55, substr with an updated trim value. |
6a622b59 |
1195 | */ |
a1440f89 |
1196 | $step = $ent_loc = 0; |
1197 | while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) && |
1198 | (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) { |
1199 | $trim_val += ($ent_loc_end-$ent_loc); |
6a622b59 |
1200 | $ent_offset = $ent_loc_end+1; |
a1440f89 |
1201 | ++$step; |
6a622b59 |
1202 | } |
a1440f89 |
1203 | |
1204 | if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +6))) { |
1205 | $i = strpos($subject,';',$trim_val); |
1206 | if ($i) { |
1207 | $trim_val = strpos($subject,';',$trim_val); |
1208 | } |
46a49f65 |
1209 | } |
6903c7bd |
1210 | if ($ent_strlen <= $trim_at){ |
6a622b59 |
1211 | return $subject; |
1212 | } |
1213 | |
1214 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
1215 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
1216 | return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val); |
1217 | } |
6a622b59 |
1218 | return substr($subject, 0, $trim_val) . '...'; |
bdfb67f8 |
1219 | } |
f93c93b9 |
1220 | |
6a622b59 |
1221 | function getMbxList($imapConnection) { |
1222 | global $lastTargetMailbox; |
1223 | echo ' <small> <tt><select name="targetMailbox">'; |
be2d5495 |
1224 | echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) ); |
6a622b59 |
1225 | echo ' </SELECT></TT> '; |
e9e5f0fa |
1226 | } |
1227 | |
1228 | function getButton($type, $name, $value) { |
6a622b59 |
1229 | return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">'; |
e9e5f0fa |
1230 | } |
1231 | |
1232 | function getSmallStringCell($string, $align) { |
6a622b59 |
1233 | return html_tag('td', |
1234 | '<small>' . $string . ': </small>', |
1235 | $align, |
1236 | '', |
1237 | 'nowrap' ); |
e9e5f0fa |
1238 | } |
1239 | |
1240 | function getEndMessage($start_msg, $show_num, $num_msgs) { |
6a622b59 |
1241 | if ($start_msg + ($show_num - 1) < $num_msgs){ |
1242 | $end_msg = $start_msg + ($show_num - 1); |
1243 | } else { |
1244 | $end_msg = $num_msgs; |
1245 | } |
e9e5f0fa |
1246 | |
6a622b59 |
1247 | if ($end_msg < $start_msg) { |
1248 | $start_msg = $start_msg - $show_num; |
1249 | if ($start_msg < 1) { |
1250 | $start_msg = 1; |
1251 | } |
e9e5f0fa |
1252 | } |
6a622b59 |
1253 | return (array($start_msg,$end_msg)); |
e9e5f0fa |
1254 | } |
1255 | |
a3439b27 |
1256 | function handleAsSent($mailbox) { |
6a8e7cae |
1257 | global $handleAsSent_result; |
1258 | |
6a622b59 |
1259 | /* First check if this is the sent or draft folder. */ |
6a8e7cae |
1260 | $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox); |
a3439b27 |
1261 | |
6a622b59 |
1262 | /* Then check the result of the handleAsSent hook. */ |
1263 | do_hook('check_handleAsSent_result', $mailbox); |
a3439b27 |
1264 | |
6a622b59 |
1265 | /* And return the result. */ |
6a8e7cae |
1266 | return $handleAsSent_result; |
6a622b59 |
1267 | } |
e842b215 |
1268 | |
937c81fa |
1269 | ?> |