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