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