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