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