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