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