fixed comp_in_new handling
[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 global $folder_prefix, $sent_folder,
500 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
501 $index_order, $real_endMessage, $real_startMessage, $checkall,
502 $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order;
503
504 /* If cache isn't already set, do it now. */
505 if (!session_is_registered('msgs')) {
506 session_register('msgs');
507 }
508 if (!session_is_registered('msort')) {
509 session_register('msort');
510 }
511
512 if ($start_msg + ($show_num - 1) < $num_msgs){
513 $end_msg = $start_msg + ($show_num - 1);
514 } else {
515 $end_msg = $num_msgs;
516 }
517
518 if ($end_msg < $start_msg) {
519 $start_msg = $start_msg - $show_num;
520 if ($start_msg < 1) {
521 $start_msg = 1;
522 }
523 }
524
525 $urlMailbox = urlencode($mailbox);
526
527 do_hook('mailbox_index_before');
528
529 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
530 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
531 $num_msgs, $show_num, $sort);
532
533 if (!isset($msg)) {
534 $msg = '';
535 }
536
537 /* get indent level for subject display */
538 if ($thread_sort_messages == 1 ) {
539 $indent_array = get_parent_level($imapConnection);
540 }
541 $fstring = "move_messages.php?msg=$msg&amp;mailbox=$urlMailbox"
542 . "&amp;startMessage=$start_msg";
543 mail_message_listing_beginning($imapConnection, $fstring,
544 $mailbox, $sort, $msg_cnt_str,
545 $paginator_str, $start_msg);
546
547 $groupNum = $start_msg % ($show_num - 1);
548 $real_startMessage = $start_msg;
549 if ($sort == 6) {
550 if ($end_msg - $start_msg < $show_num - 1) {
551 $end_msg = $end_msg - $start_msg + 1;
552 $start_msg = 1;
553 } else if ($start_msg > $show_num) {
554 $end_msg = $show_num;
555 $start_msg = 1;
556 }
557 }
558 $endVar = $end_msg + 1;
559
560 /*
561 * Loop through and display the info for each message.
562 * ($t is used for the checkbox number)
563 */
564 $t = 0;
565 if ($num_msgs == 0) {
566 /* if there's no messages in this folder */
567 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN="
568 . count($index_order) . ">\n"
569 . " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY")
570 . "</B><BR>&nbsp;</CENTER>\n"
571 . "</TD></TR>";
572 } elseif ($start_msg == $end_msg) {
573 /* if there's only one message in the box, handle it differently. */
574 if ($sort != 6){
575 $i = $start_msg;
576 } else {
577 $i = 1;
578 }
579 reset($msort);
580 $k = 0;
581 do {
582 $key = key($msort);
583 next($msort);
584 $k++;
585 } while (isset ($key) && ($k < $i));
586 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
587 $real_startMessage, 0, 0);
588 } else {
589 $i = $start_msg;
590 reset($msort);
591 $k = 0;
592 do {
593 $key = key($msort);
594 next($msort);
595 $k++;
596 } while (isset ($key) && ($k < $i));
597 do {
598 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
599 $sort, $real_startMessage, 0, 0);
600 $key = key($msort);
601 $t++;
602 $i++;
603 next($msort);
604 } while ($i && $i < $endVar);
605 }
606
607 echo '</table>'
608 . "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 "
609 . "cellspacing=1><tr BGCOLOR=\"$color[4]\"><td>"
610 . "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 "
611 . "cellspacing=0><tr><td>$paginator_str</td>"
612 . "<td align=right>$msg_cnt_str</td></tr></table>"
613 . "</td></tr></table>";
614 /* End of message-list table */
615
616 do_hook('mailbox_index_after');
617 echo "</TABLE></FORM>\n";
618 }
619
620 /*
621 * Displays the standard message list header. To finish the table,
622 * you need to do a "</table></table>";
623 *
624 * $moveURL is the URL to submit the delete/move form to
625 * $mailbox is the current mailbox
626 * $sort is the current sorting method (-1 for no sorting available [searches])
627 * $Message is a message that is centered on top of the list
628 * $More is a second line that is left aligned
629 */
630
631 function mail_message_listing_beginning ($imapConnection, $moveURL,
632 $mailbox = '', $sort = -1,
633 $msg_cnt_str = '',
634 $paginator = '&nbsp;',
635 $start_msg = 1) {
636 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
637 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
638 $allow_thread_sort, $allow_server_sort, $server_sort_order,
639 $lastTargetMailbox;
640
641 $urlMailbox = urlencode($mailbox);
642
643 /*
644 * This is the beginning of the message list table.
645 * It wraps around all messages
646 */
647 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
648 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" "
649 . "CELLSPACING=\"0\">\n<TR BGCOLOR=\"$color[0]\"><TD>"
650 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" "
651 . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
652 . " <TD ALIGN=LEFT>$paginator\n";
653
654 echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
655 . " </TR></TABLE>\n"
656 . '</TD></TR>'
657 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
658 . "<TABLE BGCOLOR=\"$color[0]\" BORDER=0 cellpadding=0 "
659 . "cellspacing=0 width=\"100%\">\n"
660 . " <TR>\n"
661 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
662 . ' <SMALL>&nbsp;' . _("Move Selected To:") . "</SMALL>\n"
663 . " </TD>\n"
664 . " <TD ALIGN=RIGHT NOWRAP>\n"
665 . ' <SMALL>&nbsp;' . _("Transform Selected Messages")
666 . ": &nbsp; </SMALL><BR>\n"
667 . " </TD>\n"
668 . " </TR>\n"
669 . " <TR>\n"
670 . " <TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\" NOWRAP>\n"
671 . ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
672
673 $boxes = sqimap_mailbox_list($imapConnection);
674 foreach ($boxes as $boxes_part) {
675 if (!in_array('noselect', $boxes_part['flags'])) {
676 $box = $boxes_part['unformatted'];
677 $box2 = str_replace(' ', '&nbsp;', imap_utf7_decode_local($boxes_part['unformatted-disp']));
678 if( $box2 == 'INBOX' ) {
679 $box2 = _("INBOX");
680 }
681 if ($lastTargetMailbox == $box) {
682 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
683 }
684 else {
685 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
686 }
687 }
688 }
689 echo ' </SELECT></TT>&nbsp;'
690 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '">&nbsp;'
691 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
692 . "\">&nbsp;\n" . "</SMALL>\n";
693
694 echo " </TD>\n"
695 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
696 if (!$auto_expunge) {
697 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
698 . '">&nbsp;' . _("mailbox") . '&nbsp;';
699 }
700 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
701 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
702 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '">&nbsp;'
703 . "</TD>\n"
704 . " </TR>\n";
705
706 /* draws thread sorting links */
707 if ($allow_thread_sort == TRUE) {
708 if ($thread_sort_messages == 1 ) {
709 $set_thread = 2;
710 $thread_name = _("Unthread View");
711 }
712 elseif ($thread_sort_messages == 0) {
713 $set_thread = 1;
714 $thread_name = _("Thread View");
715 }
716 echo '<tr><td>&nbsp;<a href=' . "$base_uri" . 'src/right_main.php?sort='
717 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
718 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
719 . '</a></small>&nbsp;</td></tr>';
720 }
721
722 echo "</TABLE>\n";
723 do_hook('mailbox_form_before');
724 echo '</TD></TR>'
725 . "<TR><TD BGCOLOR=\"$color[0]\">"
726 . '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
727 if ($GLOBALS['alt_index_colors']){
728 echo '0';
729 } else {
730 echo '1';
731 }
732 echo " BGCOLOR=\"$color[0]\">"
733 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
734 /* if using server sort we highjack the
735 * the $sort var and use $server_sort_order
736 * instead. but here we reset sort for a bit
737 * since its easy
738 */
739 if ($allow_server_sort == TRUE) {
740 $sort = $server_sort_order;
741 }
742 /* Print the headers. */
743 for ($i=1; $i <= count($index_order); $i++) {
744 switch ($index_order[$i]) {
745 case 1: /* checkbox */
746 case 5: /* flags */
747 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
748 break;
749 case 2: /* from */
750 if (handleAsSent($mailbox)) {
751 echo ' <TD WIDTH="25%"><B>' . _("To") . '</B>';
752 } else {
753 echo ' <TD WIDTH="25%"><B>' . _("From") . '</B>';
754 }
755 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
756 ShowSortButton($sort, $mailbox, 2, 3);
757 }
758 echo "</TD>\n";
759 break;
760 case 3: /* date */
761 echo ' <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
762 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
763 ShowSortButton($sort, $mailbox, 0, 1);
764 }
765 echo "</TD>\n";
766 break;
767 case 4: /* subject */
768 echo ' <TD><B>' . _("Subject") . '</B> ';
769 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
770 ShowSortButton($sort, $mailbox, 4, 5);
771 }
772 echo "</TD>\n";
773 break;
774 case 6: /* size */
775 echo ' <TD WIDTH="5%"><b>' . _("Size") . "</b></TD>\n";
776 break;
777 }
778 }
779 /* if using server-sorting,
780 * send sort back to 6
781 */
782 if ($allow_server_sort == TRUE) {
783 $sort = 6;
784 }
785 echo "</TR>\n";
786 }
787
788 /*
789 * This function shows the sort button. Isn't this a good comment?
790 */
791 function ShowSortButton($sort, $mailbox, $Up, $Down) {
792 /* Figure out which image we want to use. */
793 if ($sort != $Up && $sort != $Down) {
794 $img = 'sort_none.png';
795 $which = $Up;
796 } elseif ($sort == $Up) {
797 $img = 'up_pointer.png';
798 $which = $Down;
799 } else {
800 $img = 'down_pointer.png';
801 $which = 6;
802 }
803
804 /* Now that we have everything figured out, show the actual button. */
805 echo ' <a href="right_main.php?newsort=' . $which
806 . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
807 . '"><IMG SRC="../images/' . $img
808 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
809 }
810
811 function get_selectall_link($start_msg, $sort) {
812 global $checkall, $what, $where, $mailbox, $javascript_on;
813 global $PHP_SELF, $PG_SHOWNUM;
814
815 $result = '';
816 if ($javascript_on) {
817 $result =
818 '<script language="JavaScript" type="text/javascript">'
819 . "\n<!-- \n"
820 . "function CheckAll() {\n"
821 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
822 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
823 . " document.messageList.elements[i].checked = "
824 . " !(document.messageList.elements[i].checked);\n"
825 . " }\n"
826 . " }\n"
827 . "}\n"
828 . "//-->\n"
829 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
830 . "</a>\n";
831 } else {
832 if (strpos($PHP_SELF, "?")) {
833 $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
834 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
835 } else {
836 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
837 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
838 }
839 if (isset($checkall) && $checkall == '1') {
840 $result .= '0';
841 } else {
842 $result .= '1';
843 }
844
845 if (isset($where) && isset($what)) {
846 $result .= '&amp;where=' . urlencode($where)
847 . '&amp;what=' . urlencode($what);
848 }
849
850 $result .= "\">";
851
852 if (isset($checkall) && ($checkall == '1')) {
853 $result .= _("Unselect All");
854 } else {
855 $result .= _("Select All");
856 }
857
858 $result .= "</A>\n";
859 }
860
861 /* Return our final result. */
862 return ($result);
863 }
864
865 /*
866 * This function computes the "Viewing Messages..." string.
867 */
868 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
869 /* Compute the $msg_cnt_str. */
870 $result = '';
871 if ($start_msg < $end_msg) {
872 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
873 $start_msg, $end_msg, $num_msgs);
874 } else if ($start_msg == $end_msg) {
875 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
876 } else {
877 $result = '<br>';
878 }
879
880 /* Return our result string. */
881 return ($result);
882 }
883
884 /*
885 * Generate a paginator link.
886 */
887 function get_paginator_link($box, $start_msg, $use, $text) {
888 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
889 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
890 . "TARGET=\"right\">$text</A>";
891 return ($result);
892 }
893
894 /*
895 * This function computes the paginator string.
896 */
897 function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
898 $show_num, $sort) {
899 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
900
901 /* Initialize paginator string chunks. */
902 $prv_str = '';
903 $nxt_str = '';
904 $pg_str = '';
905 $all_str = '';
906 $tgl_str = '';
907
908 /* Create simple strings that will be creating the paginator. */
909 $spc = '&nbsp;'; /* This will be used as a space. */
910 $sep = '|'; /* This will be used as a seperator. */
911
912 /* Get some paginator preference values. */
913 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
914 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
915
916 /* Make sure that our start message number is not too big. */
917 $start_msg = min($start_msg, $num_msgs);
918
919 /* Decide whether or not we will use the mailbox cache. */
920 /* Not sure why $use_mailbox_cache is even passed in. */
921 if ($sort == 6) {
922 $use = 0;
923 } else {
924 $use = 1;
925 }
926
927 /* Compute the starting message of the previous and next page group. */
928 $next_grp = $start_msg + $show_num;
929 $prev_grp = $start_msg - $show_num;
930
931 /* Compute the basic previous and next strings. */
932 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
933 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
934 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
935 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
936 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
937 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
938 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
939 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
940 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
941 }
942
943 /* Page selector block. Following code computes page links. */
944 if ($pg_sel && ($num_msgs > $show_num)) {
945 /* Most importantly, what is the current page!!! */
946 $cur_pg = intval($start_msg / $show_num) + 1;
947
948 /* Compute total # of pages and # of paginator page links. */
949 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
950 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
951
952 /* Compute the size of the four quarters of the page links. */
953
954 /* If we can, just show all the pages. */
955 if (($tot_pgs - 1) <= $pg_max) {
956 $q1_pgs = $cur_pg - 1;
957 $q2_pgs = $q3_pgs = 0;
958 $q4_pgs = $tot_pgs - $cur_pg;
959
960 /* Otherwise, compute some magic to choose the four quarters. */
961 } else {
962 /*
963 * Compute the magic base values. Added together,
964 * these values will always equal to the $pag_pgs.
965 * NOTE: These are DEFAULT values and do not take
966 * the current page into account. That is below.
967 */
968 $q1_pgs = floor($vis_pgs/4);
969 $q2_pgs = round($vis_pgs/4, 0);
970 $q3_pgs = ceil($vis_pgs/4);
971 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
972
973 /* Adjust if the first quarter contains the current page. */
974 if (($cur_pg - $q1_pgs) < 1) {
975 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
976 $q1_pgs = $cur_pg - 1;
977 $q2_pgs = 0;
978 $q3_pgs += ceil($extra_pgs / 2);
979 $q4_pgs += floor($extra_pgs / 2);
980
981 /* Adjust if the first and second quarters intersect. */
982 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
983 $extra_pgs = $q2_pgs;
984 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
985 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
986 $q3_pgs += ceil($extra_pgs / 2);
987 $q4_pgs += floor($extra_pgs / 2);
988
989 /* Adjust if the fourth quarter contains the current page. */
990 } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
991 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
992 $q3_pgs = 0;
993 $q4_pgs = $tot_pgs - $cur_pg;
994 $q1_pgs += floor($extra_pgs / 2);
995 $q2_pgs += ceil($extra_pgs / 2);
996
997 /* Adjust if the third and fourth quarter intersect. */
998 } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
999 $extra_pgs = $q3_pgs;
1000 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1001 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1002 $q1_pgs += floor($extra_pgs / 2);
1003 $q2_pgs += ceil($extra_pgs / 2);
1004 }
1005 }
1006
1007 /*
1008 * I am leaving this debug code here, commented out, because
1009 * it is a really nice way to see what the above code is doing.
1010 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1011 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1012 */
1013
1014 /* Print out the page links from the compute page quarters. */
1015
1016 /* Start with the first quarter. */
1017 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1018 $pg_str .= "...$spc";
1019 } else {
1020 for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
1021 $start = (($pg-1) * $show_num) + 1;
1022 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1023 }
1024 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1025 $pg_str .= "...$spc";
1026 }
1027 }
1028
1029 /* Continue with the second quarter. */
1030 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
1031 $start = (($pg-1) * $show_num) + 1;
1032 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1033 }
1034
1035 /* Now print the current page. */
1036 $pg_str .= $cur_pg . $spc;
1037
1038 /* Next comes the third quarter. */
1039 for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
1040 $start = (($pg-1) * $show_num) + 1;
1041 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1042 }
1043
1044 /* And last, print the forth quarter page links. */
1045 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1046 $pg_str .= "...$spc";
1047 } else {
1048 if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
1049 $pg_str .= "...$spc";
1050 }
1051 for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
1052 $start = (($pg-1) * $show_num) + 1;
1053 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1054 }
1055 }
1056 } else if ($PG_SHOWNUM == 999999) {
1057 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1058 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1059 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1060 }
1061
1062 /* If necessary, compute the 'show all' string. */
1063 if (($prv_str != '') || ($nxt_str != '')) {
1064 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1065 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1066 . "TARGET=\"right\">" . _("Show All") . '</A>';
1067 }
1068
1069 /* Last but not least, get the value for the toggle all link. */
1070 $tgl_str = get_selectall_link($start_msg, $sort);
1071
1072 /* Put all the pieces of the paginator string together. */
1073 /**
1074 * Hairy code... But let's leave it like it is since I am not certain
1075 * a different approach would be any easier to read. ;)
1076 */
1077 $result = '';
1078 $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
1079 $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
1080 $result .= ($pg_str != '' ? $pg_str : '');
1081 $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
1082 $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
1083
1084 /* If the resulting string is blank, return a non-breaking space. */
1085 if ($result == '') {
1086 $result = '&nbsp;';
1087 }
1088
1089 /* Return our final magical paginator string. */
1090 return ($result);
1091 }
1092
1093 function processSubject($subject) {
1094 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1095 if ($subject == '')
1096 return _("(no subject)");
1097
1098 if (strlen($subject) <= 55)
1099 return $subject;
1100
1101 $ent_strlen=strlen($subject);
1102 $trim_val=50;
1103 $ent_offset=0;
1104 /*
1105 * see if this is entities-encoded string
1106 * If so, Iterate through the whole string, find out
1107 * the real number of characters, and if more
1108 * than 55, substr with an updated trim value.
1109 */
1110 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1111 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1112 $trim_val += ($ent_loc_end-$ent_loc)+1;
1113 $ent_strlen -= $ent_loc_end-$ent_loc;
1114 $ent_offset = $ent_loc_end+1;
1115 }
1116
1117 if ($ent_strlen <= 55){
1118 return $subject;
1119 }
1120
1121 return substr($subject, 0, $trim_val) . '...';
1122 }
1123
1124 function handleAsSent($mailbox) {
1125 global $sent_folder, $draft_folder, $handleAsSent_result;
1126
1127 /* First check if this is the sent or draft folder. */
1128 $handleAsSent_result = (($mailbox == $sent_folder)
1129 || ($mailbox == $draft_folder));
1130
1131 /* Then check the result of the handleAsSent hook. */
1132 do_hook('check_handleAsSent_result', $mailbox);
1133
1134 /* And return the result. */
1135 return ($handleAsSent_result);
1136 }
1137
1138 ?>