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