allow_call_time_pass_reference = Off
[squirrelmail.git] / functions / mailbox_display.php
... / ...
CommitLineData
1<?php
2
3/**
4 * mailbox_display.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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 */
14
15require_once('../functions/strings.php');
16require_once('../functions/html.php');
17require_once('../class/html.class.php');
18require_once('../functions/imap_mailbox.php');
19
20/* Default value for page_selector_max. */
21define('PG_SEL_MAX', 10);
22
23function printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
24 $start_msg, $where, $what) {
25 global $checkall,
26 $color, $msgs, $msort,
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 */
36 $color_string = $color[4];
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 }
49 }
50 $msg = $msgs[$key];
51
52 if( $mailbox == 'None' ) {
53 $boxes = sqimap_mailbox_list($imapConnection);
54 $mailbox = $boxes[0]['unformatted'];
55 unset( $boxes );
56 }
57 $urlMailbox = urlencode($mailbox);
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
79 $subject = processSubject($msg['SUBJECT']);
80
81 echo html_tag( 'tr' ) . "\n";
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 = '';
89 }
90 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
91 $bold = '<b>';
92 $bold_end = '</b>';
93 } else {
94 $bold = '';
95 $bold_end = '';
96 }
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 if ($where && $what) {
113 $searchstr = '&amp;where='.$where.'&amp;what='.$what;
114 } else {
115 $searchstr = '';
116 }
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
146 $checked = ($checkall == 1) ? ' checked' : '';
147 $row = new html();
148 $row->tag = 'tr';
149 $row->class = 'm_r';
150 $row->id = 'mr'.$t;
151
152
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,
166 'left',
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("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg['ID']]);
182 }
183 }
184 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
185 .'&amp;passed_id='. $msg["ID"]
186 . '&amp;startMessage='.$start_msg.$searchstr.'"';
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";
196 echo html_tag( 'td', $td_str, 'left', $hlt_color );
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 .= '&nbsp;';
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 }
244 }
245 echo "</tr>\n";
246}
247
248function 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
272function 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
297function 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
335/*
336 * This function loops through a group of messages in the mailbox
337 * and shows them to the user.
338 */
339function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
340 $start_msg, $sort, $color, $show_num,
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 }
353
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 */
358
359 if($start_msg > $num_msgs) {
360 $start_msg -= $show_num;
361 if($start_msg < 1) {
362 $start_msg = 1;
363 }
364 }
365
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 */
371
372 if ($thread_sort_messages == 1) {
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>' .
388 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
389 '</center></small></b>';
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) {
406 echo '<b><small><center><font color=red>' .
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();
415 } else {
416 $sort = 6;
417 $msort = $msgs;
418 session_register('msort');
419 session_register('msgs');
420 }
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);
440
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);
447
448
449 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
450
451 displayMessageArray($imapConnection, $num_msgs, $start_msg,
452 $msort, $mailbox, $sort, $color, $show_num,0,0);
453
454 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
455
456 /**
457 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
458 */
459}
460
461function calc_msort($msgs, $sort) {
462
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 */
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 {
478 $msort = $msgs;
479 }
480 if ($sort < 6) {
481 if ($sort % 2) {
482 asort($msort);
483 } else {
484 arsort($msort);
485 }
486 }
487 return $msort;
488}
489
490function fillMessageArray($imapConnection,$id,$count) {
491 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
492 $messages = array();
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 }
520 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
521 $messages[$j]['DATE_STRING'] =
522 getDateString($messages[$j]['TIME_STAMP']);
523 $messages[$j]['ID'] = $unique_id[$j];
524 $messages[$j]['FROM'] = decodeHeader($from[$j]);
525 $messages[$j]['FROM-SORT'] =
526 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
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];
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",
550 $messages[$j]['SUBJECT-SORT'], $matches)){
551 $messages[$j]['SUBJECT-SORT'] = $matches[2];
552 }
553 $j++;
554 }
555 return $messages;
556}
557
558
559/* Generic function to convert the msgs array into an HTML table. */
560function displayMessageArray($imapConnection, $num_msgs, $start_msg,
561 $msort, $mailbox, $sort, $color,
562 $show_num, $where=0, $what=0) {
563 global $imapServerAddress, $use_mailbox_cache,
564 $index_order, $checkall,
565 $indent_array, $thread_sort_messages, $allow_server_sort,
566 $server_sort_order, $PHP_SELF;
567
568 $end_msg = getEndMessage(&$start_msg, $show_num, $num_msgs);
569
570 $urlMailbox = urlencode($mailbox);
571
572 /* get indent level for subject display */
573 if ($thread_sort_messages == 1 ) {
574 $indent_array = get_parent_level($imapConnection);
575 }
576
577
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;
586 }
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;
595
596 /* messages display */
597
598 if ($num_msgs == 0) {
599 /* if there's no messages in this folder */
600 echo html_tag( 'tr',
601 html_tag( 'td',
602 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR>&nbsp;",
603 'center',
604 $color[4],
605 'COLSPAN="' . count($index_order) . '"'
606 )
607 );
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;
612 } else {
613 $i = 1;
614 }
615 reset($msort);
616 $k = 0;
617 do {
618 $key = key($msort);
619 next($msort);
620 $k++;
621 } while (isset ($key) && ($k < $i));
622 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
623 $real_startMessage, $where, $what);
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,
635 $real_startMessage, $where, $what);
636 $key = key($msort);
637 $t++;
638 $i++;
639 next($msort);
640 } while ($i && $i < $endVar);
641 }
642 echo '</table>';
643}
644
645/*
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
656function mail_message_listing_beginning ($imapConnection,
657 $mailbox = '', $sort = -1,
658 $msg_cnt_str = '',
659 $paginator = '&nbsp;',
660 $start_msg = 1) {
661 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
662 $allow_thread_sort, $allow_server_sort, $server_sort_order,
663 $PHP_SELF;
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
673 if (!isset($msg)) {
674 $msg = '';
675 }
676 $moveURL = "move_messages.php?msg=$msg&amp;mailbox=$urlMailbox"
677 . "&amp;startMessage=$start_msg";
678
679 /*
680 * This is the beginning of the message list table.
681 * It wraps around all messages
682 */
683
684 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
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] )
696 . html_tag( 'tr' ) . "\n"
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',
700 getSmallStringCell(_("Move Selected To"), 'left') .
701 getSmallStringCell(_("Transform Selected Messages"), 'right')
702 )
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";
708
709 echo " </TD>\n"
710 . html_tag( 'td', '', 'right', '', 'nowrap' );
711
712 if (!$auto_expunge) {
713 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
714 .'&nbsp;' . _("mailbox") . "\n";
715 }
716
717 echo getButton('SUBMIT', 'markRead',_("Read"));
718 echo getButton('SUBMIT', 'markUnread',_("Unread"));
719 echo getButton('SUBMIT', 'delete',_("Delete")) ."&nbsp\n";
720 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$PHP_SELF.'">';
721 echo "</TD>\n"
722 . " </TR>\n";
723
724 /* draws thread sorting links */
725 if ($allow_thread_sort == TRUE) {
726 if ($thread_sort_messages == 1 ) {
727 $set_thread = 2;
728 $thread_name = _("Unthread View");
729 }
730 elseif ($thread_sort_messages == 0) {
731 $set_thread = 1;
732 $thread_name = _("Thread View");
733 }
734 echo html_tag( 'tr' ,
735 html_tag( 'td' ,
736 '&nbsp;<a href=' . $source_url . '?sort='
737 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
738 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
739 . '</a></small>&nbsp;'
740 , '', '', '' )
741 , '', '', '' );
742 }
743
744 echo "</TABLE>\n";
745
746 echo "</table>\n";
747
748 do_hook('mailbox_form_before');
749
750 echo '</td></tr>'
751 . html_tag( 'tr' )
752 . html_tag( 'td' ,'' , '', $color[0], '' );
753 if ($GLOBALS['alt_index_colors']){
754 $cellspacing = '0';
755 } else {
756 $cellspacing = '1';
757 }
758 echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' );
759
760 /* if using server sort we highjack the
761 * the $sort var and use $server_sort_order
762 * instead. but here we reset sort for a bit
763 * since its easy
764 */
765 if ($allow_server_sort == TRUE) {
766 $sort = $server_sort_order;
767 }
768}
769
770function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
771 if ($num_msgs) {
772 echo html_tag( 'table',
773 html_tag( 'tr',
774 html_tag( 'td',
775 html_tag( 'table',
776 html_tag( 'tr',
777 html_tag( 'td', $paginator_str ) .
778 html_tag( 'td', $msg_cnt_str, 'right' )
779 )
780 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
781 )
782 , '', $color[4] )
783 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
784
785 }
786 /* End of message-list table */
787
788 do_hook('mailbox_index_after');
789 echo "</FORM>\n";
790
791}
792
793function printHeader($mailbox, $sort, $color, $showsort=true) {
794 global $index_order;
795 echo html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="1"' );
796 echo html_tag( 'tr' ,'' , 'center', $color[5] );
797 for ($i=1; $i <= count($index_order); $i++) {
798 switch ($index_order[$i]) {
799 case 1: /* checkbox */
800 case 5: /* flags */
801 echo html_tag( 'td' ,'&nbsp;' , '', '', 'width="1%"' );
802 break;
803 case 2: /* from */
804 if (handleAsSent($mailbox)) {
805 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
806 . '<b>' . _("To") . '</b>';
807 } else {
808 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
809 . '<b>' . _("From") . '</b>';
810 }
811 if ($showsort) {
812 ShowSortButton($sort, $mailbox, 2, 3);
813 }
814 echo "</td>\n";
815 break;
816 case 3: /* date */
817 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
818 . '<b>' . _("Date") . '</b>';
819 if ($showsort) {
820 ShowSortButton($sort, $mailbox, 0, 1);
821 }
822 echo "</td>\n";
823 break;
824 case 4: /* subject */
825 echo html_tag( 'td' ,'' , 'left', '', '' )
826 . '<b>' . _("Subject") . '</b>';
827 if ($showsort) {
828 ShowSortButton($sort, $mailbox, 4, 5);
829 }
830 echo "</td>\n";
831 break;
832 case 6: /* size */
833 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
834 break;
835 }
836 }
837 echo "</tr>\n";
838}
839
840
841/*
842 * This function shows the sort button. Isn't this a good comment?
843 */
844function ShowSortButton($sort, $mailbox, $Up, $Down ) {
845 global $PHP_SELF;
846 /* Figure out which image we want to use. */
847 if ($sort != $Up && $sort != $Down) {
848 $img = 'sort_none.png';
849 $which = $Up;
850 } elseif ($sort == $Up) {
851 $img = 'up_pointer.png';
852 $which = $Down;
853 } else {
854 $img = 'down_pointer.png';
855 $which = 6;
856 }
857
858 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
859 $source_url = $regs[1];
860 } else {
861 $source_url = $PHP_SELF;
862 }
863
864 /* Now that we have everything figured out, show the actual button. */
865 echo ' <a href="' . $source_url .'?newsort=' . $which
866 . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
867 . '"><IMG SRC="../images/' . $img
868 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
869}
870
871function get_selectall_link($start_msg, $sort) {
872 global $checkall, $what, $where, $mailbox, $javascript_on;
873 global $PHP_SELF, $PG_SHOWNUM;
874
875 $result = '';
876 if ($javascript_on) {
877 $result =
878 '<script language="JavaScript" type="text/javascript">'
879 . "\n<!-- \n"
880 . "function CheckAll() {\n"
881 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
882 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
883 . " document.messageList.elements[i].checked = "
884 . " !(document.messageList.elements[i].checked);\n"
885 . " }\n"
886 . " }\n"
887 . "}\n"
888 . "//-->\n"
889 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
890 . "</a>\n";
891 } else {
892 if (strpos($PHP_SELF, "?")) {
893 $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
894 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
895 } else {
896 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
897 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
898 }
899 if (isset($checkall) && $checkall == '1') {
900 $result .= '0';
901 } else {
902 $result .= '1';
903 }
904
905 if (isset($where) && isset($what)) {
906 $result .= '&amp;where=' . urlencode($where)
907 . '&amp;what=' . urlencode($what);
908 }
909
910 $result .= "\">";
911
912 if (isset($checkall) && ($checkall == '1')) {
913 $result .= _("Unselect All");
914 } else {
915 $result .= _("Select All");
916 }
917
918 $result .= "</A>\n";
919 }
920
921 /* Return our final result. */
922 return ($result);
923}
924
925/*
926 * This function computes the "Viewing Messages..." string.
927 */
928function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
929 /* Compute the $msg_cnt_str. */
930 $result = '';
931 if ($start_msg < $end_msg) {
932 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
933 $start_msg, $end_msg, $num_msgs);
934 } else if ($start_msg == $end_msg) {
935 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
936 } else {
937 $result = '<br>';
938 }
939 /* Return our result string. */
940 return ($result);
941}
942
943/*
944 * Generate a paginator link.
945 */
946function get_paginator_link($box, $start_msg, $use, $text) {
947 global $PHP_SELF;
948
949 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
950 $source_url = $regs[1];
951 } else {
952 $source_url = $PHP_SELF;
953 }
954
955 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
956 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
957 . "TARGET=\"right\">$text</A>";
958 return ($result);
959}
960
961/*
962 * This function computes the paginator string.
963 */
964function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
965 $show_num, $sort) {
966 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
967
968 /* Initialize paginator string chunks. */
969 $prv_str = '';
970 $nxt_str = '';
971 $pg_str = '';
972 $all_str = '';
973 $tgl_str = '';
974
975 $box = urlencode($box);
976
977 /* Create simple strings that will be creating the paginator. */
978 $spc = '&nbsp;'; /* This will be used as a space. */
979 $sep = '|'; /* This will be used as a seperator. */
980
981 /* Get some paginator preference values. */
982 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
983 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
984
985 /* Make sure that our start message number is not too big. */
986 $start_msg = min($start_msg, $num_msgs);
987
988 /* Decide whether or not we will use the mailbox cache. */
989 /* Not sure why $use_mailbox_cache is even passed in. */
990 if ($sort == 6) {
991 $use = 0;
992 } else {
993 $use = 1;
994 }
995
996 /* Compute the starting message of the previous and next page group. */
997 $next_grp = $start_msg + $show_num;
998 $prev_grp = $start_msg - $show_num;
999
1000 /* Compute the basic previous and next strings. */
1001 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1002 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1003 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1004 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1005 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1006 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1007 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1008 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1009 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1010 }
1011
1012 /* Page selector block. Following code computes page links. */
1013 if ($pg_sel && ($num_msgs > $show_num)) {
1014 /* Most importantly, what is the current page!!! */
1015 $cur_pg = intval($start_msg / $show_num) + 1;
1016
1017 /* Compute total # of pages and # of paginator page links. */
1018 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1019 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1020
1021 /* Compute the size of the four quarters of the page links. */
1022
1023 /* If we can, just show all the pages. */
1024 if (($tot_pgs - 1) <= $pg_max) {
1025 $q1_pgs = $cur_pg - 1;
1026 $q2_pgs = $q3_pgs = 0;
1027 $q4_pgs = $tot_pgs - $cur_pg;
1028
1029 /* Otherwise, compute some magic to choose the four quarters. */
1030 } else {
1031 /*
1032 * Compute the magic base values. Added together,
1033 * these values will always equal to the $pag_pgs.
1034 * NOTE: These are DEFAULT values and do not take
1035 * the current page into account. That is below.
1036 */
1037 $q1_pgs = floor($vis_pgs/4);
1038 $q2_pgs = round($vis_pgs/4, 0);
1039 $q3_pgs = ceil($vis_pgs/4);
1040 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1041
1042 /* Adjust if the first quarter contains the current page. */
1043 if (($cur_pg - $q1_pgs) < 1) {
1044 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
1045 $q1_pgs = $cur_pg - 1;
1046 $q2_pgs = 0;
1047 $q3_pgs += ceil($extra_pgs / 2);
1048 $q4_pgs += floor($extra_pgs / 2);
1049
1050 /* Adjust if the first and second quarters intersect. */
1051 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1052 $extra_pgs = $q2_pgs;
1053 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1054 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1055 $q3_pgs += ceil($extra_pgs / 2);
1056 $q4_pgs += floor($extra_pgs / 2);
1057
1058 /* Adjust if the fourth quarter contains the current page. */
1059 } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
1060 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
1061 $q3_pgs = 0;
1062 $q4_pgs = $tot_pgs - $cur_pg;
1063 $q1_pgs += floor($extra_pgs / 2);
1064 $q2_pgs += ceil($extra_pgs / 2);
1065
1066 /* Adjust if the third and fourth quarter intersect. */
1067 } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
1068 $extra_pgs = $q3_pgs;
1069 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1070 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1071 $q1_pgs += floor($extra_pgs / 2);
1072 $q2_pgs += ceil($extra_pgs / 2);
1073 }
1074 }
1075
1076 /*
1077 * I am leaving this debug code here, commented out, because
1078 * it is a really nice way to see what the above code is doing.
1079 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1080 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1081 */
1082
1083 /* Print out the page links from the compute page quarters. */
1084
1085 /* Start with the first quarter. */
1086 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1087 $pg_str .= "...$spc";
1088 } else {
1089 for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
1090 $start = (($pg-1) * $show_num) + 1;
1091 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1092 }
1093 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1094 $pg_str .= "...$spc";
1095 }
1096 }
1097
1098 /* Continue with the second quarter. */
1099 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
1100 $start = (($pg-1) * $show_num) + 1;
1101 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1102 }
1103
1104 /* Now print the current page. */
1105 $pg_str .= $cur_pg . $spc;
1106
1107 /* Next comes the third quarter. */
1108 for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
1109 $start = (($pg-1) * $show_num) + 1;
1110 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1111 }
1112
1113 /* And last, print the forth quarter page links. */
1114 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1115 $pg_str .= "...$spc";
1116 } else {
1117 if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
1118 $pg_str .= "...$spc";
1119 }
1120 for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
1121 $start = (($pg-1) * $show_num) + 1;
1122 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1123 }
1124 }
1125 } else if ($PG_SHOWNUM == 999999) {
1126 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1127 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1128 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1129 }
1130
1131 /* If necessary, compute the 'show all' string. */
1132 if (($prv_str != '') || ($nxt_str != '')) {
1133 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1134 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1135 . "TARGET=\"right\">" . _("Show All") . '</A>';
1136 }
1137
1138 /* Last but not least, get the value for the toggle all link. */
1139 $tgl_str = get_selectall_link($start_msg, $sort);
1140
1141 /* Put all the pieces of the paginator string together. */
1142 /**
1143 * Hairy code... But let's leave it like it is since I am not certain
1144 * a different approach would be any easier to read. ;)
1145 */
1146 $result = '';
1147 $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
1148 $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
1149 $result .= ($pg_str != '' ? $pg_str : '');
1150 $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
1151 $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
1152
1153 /* If the resulting string is blank, return a non-breaking space. */
1154 if ($result == '') {
1155 $result = '&nbsp;';
1156 }
1157
1158 /* Return our final magical paginator string. */
1159 return ($result);
1160}
1161
1162function processSubject($subject) {
1163 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1164 if ($subject == '')
1165 return _("(no subject)");
1166
1167 if (strlen($subject) <= 55)
1168 return $subject;
1169
1170 $ent_strlen=strlen($subject);
1171 $trim_val=50;
1172 $ent_offset=0;
1173 /*
1174 * see if this is entities-encoded string
1175 * If so, Iterate through the whole string, find out
1176 * the real number of characters, and if more
1177 * than 55, substr with an updated trim value.
1178 */
1179 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1180 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1181 $trim_val += ($ent_loc_end-$ent_loc)+1;
1182 $ent_strlen -= $ent_loc_end-$ent_loc;
1183 $ent_offset = $ent_loc_end+1;
1184 }
1185
1186 if ($ent_strlen <= 55){
1187 return $subject;
1188 }
1189
1190 return substr($subject, 0, $trim_val) . '...';
1191}
1192
1193function getMbxList($imapConnection) {
1194 global $lastTargetMailbox;
1195 echo ' <small>&nbsp;<tt><select name="targetMailbox">';
1196 $boxes = sqimap_mailbox_list($imapConnection);
1197 foreach ($boxes as $boxes_part) {
1198 if (!in_array('noselect', $boxes_part['flags'])) {
1199 $box = $boxes_part['unformatted'];
1200 $box2 = str_replace(' ', '&nbsp;', imap_utf7_decode_local($boxes_part['unformatted-disp']));
1201 if( $box2 == 'INBOX' ) {
1202 $box2 = _("INBOX");
1203 }
1204 if ($lastTargetMailbox == $box) {
1205 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
1206 }
1207 else {
1208 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
1209 }
1210 }
1211 }
1212 echo ' </SELECT></TT>&nbsp;';
1213}
1214
1215function getButton($type, $name, $value) {
1216return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1217}
1218
1219function getSmallStringCell($string, $align) {
1220 return html_tag( 'td',
1221 '<small>' . $string . ':&nbsp; </small>',
1222 $align,
1223 '',
1224 'nowrap' );
1225}
1226
1227function getEndMessage($start_msg, $show_num, $num_msgs) {
1228 if ($start_msg + ($show_num - 1) < $num_msgs){
1229 $end_msg = $start_msg + ($show_num - 1);
1230 } else {
1231 $end_msg = $num_msgs;
1232 }
1233
1234 if ($end_msg < $start_msg) {
1235 $start_msg = $start_msg - $show_num;
1236 if ($start_msg < 1) {
1237 $start_msg = 1;
1238 }
1239 }
1240 return $end_msg;
1241}
1242
1243function handleAsSent($mailbox) {
1244 global $sent_folder, $draft_folder, $handleAsSent_result;
1245
1246 /* First check if this is the sent or draft folder. */
1247 $handleAsSent_result = (($mailbox == $sent_folder)
1248 || ($mailbox == $draft_folder));
1249
1250 /* Then check the result of the handleAsSent hook. */
1251 do_hook('check_handleAsSent_result', $mailbox);
1252
1253 /* And return the result. */
1254 return ($handleAsSent_result);
1255}
1256
1257?>