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