Move away the sqimap_get_flags_list call because now
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
2ba13803 2
35586184 3/**
4 * mailbox_display.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 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 */
a4c2cd49 14
46d38f78 15require_once('../functions/strings.php');
43fdb2a4 16
6c930ade 17/* Default value for page_selector_max. */
18define('PG_SEL_MAX', 10);
19
20function 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 */
aa0da530 31 $server_sort_order, /* sort value when using server-sorting */
32 $row_count,
33 $allow_server_sort; /* enable/disable server-side sorting */
6c930ade 34 $color_string = $color[4];
35
36 if ($GLOBALS['alt_index_colors']) {
37 if (!isset($row_count)) {
38 $row_count = 0;
bdfb67f8 39 }
6c930ade 40 $row_count++;
41 if ($row_count % 2) {
42 if (!isset($color[12])) {
43 $color[12] = '#EAEAEA';
44 }
45 $color_string = $color[12];
bdfb67f8 46 }
6c930ade 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);
bdfb67f8 62 }
6c930ade 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 }
bdfb67f8 125 }
6c930ade 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';
bdfb67f8 135 }
6c930ade 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) {
2728fa19 164 if (isset($indent_array[$msg["ID"]])) {
165 echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg["ID"]]);
166 }
167 }
6c930ade 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'][0] == 1) || ($msg['PRIORITY'][0] == 2) ) {
194 echo "<font color=\"$color[1]\">!</font>\n";
195 $stuff = true;
196 }
197 if ($msg['PRIORITY'][0] == 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 }
bdfb67f8 216 }
6c930ade 217 }
218 echo "</tr>\n";
bdfb67f8 219}
220
6c930ade 221/*
bdfb67f8 222 * This function loops through a group of messages in the mailbox
223 * and shows them to the user.
224 */
6c930ade 225function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
226 $start_msg, $sort, $color, $show_num,
227 $use_cache) {
228 global $msgs, $msort,
229 $sent_folder, $draft_folder,
aa0da530 230 $message_highlight_list,
231 $auto_expunge, $thread_sort_messages, $allow_server_sort,
232 $data_dir, $username, $server_sort_order;
233
4e9f35e4 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
aa0da530 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 */
6c930ade 250 if ($thread_sort_messages == 1) {
251 $id = get_thread_sort($imapConnection);
26eca02e 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'.
f24c898b 255 ' to the system administrator.</center></small></b>';
0c46707d 256 $thread_sort_messages = 0;
26eca02e 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 }
aa0da530 269 }
270
794d59c0 271 if ($allow_server_sort == TRUE && $thread_sort_messages != 1) {
aa0da530 272 $server_sort_order = $sort;
273 $id = sqimap_get_sort_order($imapConnection, $server_sort_order);
26eca02e 274 if ($id == 'no') {
f24c898b 275 echo '<b><small><center><font color=red>Server-side sorting'.
276 ' is not supported by your IMAP server.<br>Please report this'.
26eca02e 277 ' to the system administrator.</center></small></b>';
278 $sort = $server_sort_order;
794d59c0 279 $allow_server_sort = FALSE;
26eca02e 280 $id = array();
281 }
aa0da530 282 else {
26eca02e 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 }
6c930ade 292 }
aa0da530 293
294 /* If autoexpunge is turned on, then do it now. */
6c930ade 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 }
794d59c0 306 elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) {
6c930ade 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 }
340 }
bdfb67f8 341 }
6c930ade 342 $j = 0;
343 if ($sort == 6) {
344 $end = $start_msg + $show_num - 1;
345 if ($num_msgs < $show_num) {
346 $end_loop = $num_msgs;
347 } else if ($end > $num_msgs) {
348 $end_loop = $num_msgs - $start_msg + 1;
349 } else {
350 $end_loop = $show_num;
351 }
352 } else {
353 $end = $num_msgs;
354 $end_loop = $end;
7c612fdd 355 }
6c930ade 356 while ($j < $end_loop) {
357 if (isset($date[$j])) {
358 $date[$j] = str_replace(' ', ' ', $date[$j]);
359 $tmpdate = explode(' ', trim($date[$j]));
360 } else {
361 $tmpdate = $date = array('', '', '', '', '', '');
362 }
363
364 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
365 $messages[$j]['DATE_STRING'] =
366 getDateString($messages[$j]['TIME_STAMP']);
367 $messages[$j]['ID'] = $id[$j];
368 $messages[$j]['FROM'] = decodeHeader($from[$j]);
369 $messages[$j]['FROM-SORT'] =
370 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
371 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
372 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
373 $messages[$j]['TO'] = decodeHeader($to[$j]);
374 $messages[$j]['PRIORITY'] = $priority[$j];
375 $messages[$j]['CC'] = $cc[$j];
376 $messages[$j]['SIZE'] = $size[$j];
377 $messages[$j]['TYPE0'] = $type[$j];
378
379 /*
380 * fix SUBJECT-SORT to remove Re:
381 * vedr|sv (Danish)
382 * re|aw (English)
383 *
384 * TODO: i18n should be incorporated here. E.g. we catch the ones
385 * we know about, but also define in i18n what the localized
386 * "Re: " is for this or that locale.
387 */
388 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
389 $messages[$j]['SUBJECT-SORT'], $matches)){
390 $messages[$j]['SUBJECT-SORT'] = $matches[2];
391 }
392
393 $num = 0;
394 while ($num < count($flags[$j])) {
395 if ($flags[$j][$num] == 'Deleted') {
396 $messages[$j]['FLAG_DELETED'] = true;
397 } else if ($flags[$j][$num] == 'Answered') {
398 $messages[$j]['FLAG_ANSWERED'] = true;
399 } else if ($flags[$j][$num] == 'Seen') {
400 $messages[$j]['FLAG_SEEN'] = true;
401 } else if ($flags[$j][$num] == 'Flagged') {
402 $messages[$j]['FLAG_FLAGGED'] = true;
403 }
404 $num++;
405 }
406 $j++;
bdfb67f8 407 }
bdfb67f8 408
6c930ade 409 /*
410 * Only ignore messages flagged as deleted if we are
411 * using a trash folder or auto_expunge
412 */
413 if (((isset($move_to_trash) && $move_to_trash)
414 || (isset($auto_expunge) && $auto_expunge))
415 && $sort != 6) {
416
417 /* Find and remove the ones that are deleted */
418 $i = 0;
419 $j = 0;
420
421 while ($j < $num_msgs) {
422 if (isset($messages[$j]['FLAG_DELETED'])
423 && $messages[$j]['FLAG_DELETED'] == true) {
424 $j++;
425 continue;
426 }
427 $msgs[$i] = $messages[$j];
428
429 $i++;
430 $j++;
431 }
432 $num_msgs = $i;
bdfb67f8 433 } else {
6c930ade 434 if (!isset($messages)) {
435 $messages = array();
436 }
437 $msgs = $messages;
bdfb67f8 438 }
6c930ade 439 }
bdfb67f8 440
6c930ade 441 /* There's gotta be messages in the array for it to sort them. */
442 if (($num_msgs > 0) && (!$use_cache)) {
443 /*
444 * 0 = Date (up)
445 * 1 = Date (dn)
446 * 2 = Name (up)
447 * 3 = Name (dn)
448 * 4 = Subject (up)
449 * 5 = Subject (dn)
450 */
451 session_unregister('msgs');
452 if (($sort == 0) || ($sort == 1)) {
453 $msort = array_cleave ($msgs, 'TIME_STAMP');
454 } elseif (($sort == 2) || ($sort == 3)) {
455 $msort = array_cleave ($msgs, 'FROM-SORT');
456 } elseif (($sort == 4) || ($sort == 5)) {
457 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
458 } else {
459 $msort = $msgs;
bdfb67f8 460 }
6c930ade 461
462 if ($sort < 6) {
463 if ($sort % 2) {
464 asort($msort);
465 } else {
466 arsort($msort);
467 }
468 }
469 session_register('msort');
794d59c0 470 } elseif ($thread_sort_messages == 1 || $allow_server_sort == TRUE) {
6c930ade 471 $msort = $msgs;
472 session_unregister('msgs');
473 session_register('msort');
474 }
475 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs,
476 $msort, $mailbox, $sort, $color,$show_num);
477 /**
478 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
479 */
480 session_register('msgs');
481}
bdfb67f8 482
6c930ade 483/* Generic function to convert the msgs array into an HTML table. */
484function displayMessageArray($imapConnection, $num_msgs, $start_msg,
485 &$msgs, $msort, $mailbox, $sort, $color,
486 $show_num) {
487 global $folder_prefix, $sent_folder,
488 $imapServerAddress, $data_dir, $username, $use_mailbox_cache,
489 $index_order, $real_endMessage, $real_startMessage, $checkall,
aa0da530 490 $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order;
6c930ade 491
492 /* If cache isn't already set, do it now. */
493 if (!session_is_registered('msgs')) {
494 session_register('msgs');
495 }
496 if (!session_is_registered('msort')) {
497 session_register('msort');
498 }
499
500 if ($start_msg + ($show_num - 1) < $num_msgs){
501 $end_msg = $start_msg + ($show_num - 1);
502 } else {
503 $end_msg = $num_msgs;
504 }
505
506 if ($end_msg < $start_msg) {
507 $start_msg = $start_msg - $show_num;
508 if ($start_msg < 1) {
509 $start_msg = 1;
bdfb67f8 510 }
6c930ade 511 }
512
513 $urlMailbox = urlencode($mailbox);
514
515 do_hook('mailbox_index_before');
516
517 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
518 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
519 $num_msgs, $show_num, $sort);
520
521 if (!isset($msg)) {
522 $msg = '';
523 }
524
525 /* get indent level for subject display */
526 if ($thread_sort_messages == 1 ) {
527 $indent_array = get_parent_level($imapConnection);
528 }
529 $fstring = "move_messages.php?msg=$msg&amp;mailbox=$urlMailbox"
530 . "&amp;startMessage=$start_msg";
531 mail_message_listing_beginning($imapConnection, $fstring,
532 $mailbox, $sort, $msg_cnt_str,
533 $paginator_str, $start_msg);
534
535 $groupNum = $start_msg % ($show_num - 1);
536 $real_startMessage = $start_msg;
537 if ($sort == 6) {
538 if ($end_msg - $start_msg < $show_num - 1) {
539 $end_msg = $end_msg - $start_msg + 1;
540 $start_msg = 1;
541 } else if ($start_msg > $show_num) {
542 $end_msg = $show_num;
543 $start_msg = 1;
7c612fdd 544 }
6c930ade 545 }
546 $endVar = $end_msg + 1;
547
548 /*
549 * Loop through and display the info for each message.
550 * ($t is used for the checkbox number)
551 */
552 $t = 0;
553 if ($num_msgs == 0) {
554 /* if there's no messages in this folder */
555 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN="
556 . count($index_order) . ">\n"
557 . " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY")
558 . "</B><BR>&nbsp;</CENTER>\n"
559 . "</TD></TR>";
560 } elseif ($start_msg == $end_msg) {
561 /* if there's only one message in the box, handle it differently. */
562 if ($sort != 6){
563 $i = $start_msg;
bdfb67f8 564 } else {
6c930ade 565 $i = 1;
bdfb67f8 566 }
6c930ade 567 reset($msort);
568 $k = 0;
569 do {
570 $key = key($msort);
571 next($msort);
572 $k++;
573 } while (isset ($key) && ($k < $i));
574 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
575 $real_startMessage, 0, 0);
576 } else {
577 $i = $start_msg;
578 reset($msort);
579 $k = 0;
580 do {
581 $key = key($msort);
582 next($msort);
583 $k++;
584 } while (isset ($key) && ($k < $i));
585 do {
586 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
587 $sort, $real_startMessage, 0, 0);
588 $key = key($msort);
589 $t++;
590 $i++;
591 next($msort);
592 } while ($i && $i < $endVar);
593 }
594
595 echo '</table>'
596 . "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 "
597 . "cellspacing=1><tr BGCOLOR=\"$color[4]\"><td>"
598 . "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 "
599 . "cellspacing=0><tr><td>$paginator_str</td>"
600 . "<td align=right>$msg_cnt_str</td></tr></table>"
601 . "</td></tr></table>";
602 /* End of message-list table */
603
604 do_hook('mailbox_index_after');
605 echo "</TABLE></FORM>\n";
bdfb67f8 606}
607
6c930ade 608/*
bdfb67f8 609 * Displays the standard message list header. To finish the table,
610 * you need to do a "</table></table>";
611 *
612 * $moveURL is the URL to submit the delete/move form to
613 * $mailbox is the current mailbox
614 * $sort is the current sorting method (-1 for no sorting available [searches])
615 * $Message is a message that is centered on top of the list
616 * $More is a second line that is left aligned
617 */
6c930ade 618function mail_message_listing_beginning ($imapConnection, $moveURL,
619 $mailbox = '', $sort = -1,
620 $msg_cnt_str = '',
621 $paginator = '&nbsp;',
622 $start_msg = 1) {
623 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
624 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
aa0da530 625 $allow_thread_sort, $allow_server_sort, $server_sort_order;
6c930ade 626 $urlMailbox = urlencode($mailbox);
627
628 /*
629 * This is the beginning of the message list table.
630 * It wraps around all messages
631 */
632 echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
633 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" "
634 . "CELLSPACING=\"0\">\n<TR BGCOLOR=\"$color[0]\"><TD>"
635 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" "
636 . "CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
637 . " <TD ALIGN=LEFT>$paginator\n";
638
6c930ade 639 echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
640 . " </TR></TABLE>\n"
641 . '</TD></TR>'
642 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
643 . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0"
644 . "cellspacing=0 width=\"100%\">\n"
645 . " <TR>\n"
646 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
647 . ' <SMALL>&nbsp;' . _("Move Selected To:") . "</SMALL>\n"
648 . " </TD>\n"
649 . " <TD ALIGN=RIGHT NOWRAP>\n"
650 . ' <SMALL>&nbsp;' . _("Transform Selected Messages")
651 . ": &nbsp; </SMALL><BR>\n"
652 . " </TD>\n"
653 . " </TR>\n"
654 . " <TR>\n"
655 . " <TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\" NOWRAP>\n"
656 . ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
657
658 $boxes = sqimap_mailbox_list($imapConnection);
659 foreach ($boxes as $boxes_part) {
660 if (!in_array('noselect', $boxes_part['flags'])) {
661 $box = $boxes_part['unformatted'];
662 $box2 = str_replace(' ', '&nbsp;', $boxes_part['unformatted-disp']);
663 if( $box2 == 'INBOX' ) {
664 $box2 = _("INBOX");
665 }
666 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
bdfb67f8 667 }
6c930ade 668 }
669 echo ' </SELECT></TT>&nbsp;'
670 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '">&nbsp;'
671 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
672 . "\">&nbsp;\n" . "</SMALL>\n";
673
674 echo " </TD>\n"
675 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
676 if (!$auto_expunge) {
677 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
678 . '">&nbsp;' . _("mailbox") . '&nbsp;';
679 }
680 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
681 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
682 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '">&nbsp;'
683 . "</TD>\n"
aa0da530 684 . " </TR>\n";
685
3baefe86 686 /* draws thread sorting links */
794d59c0 687 if ($allow_thread_sort == TRUE) {
aa0da530 688 if ($thread_sort_messages == 1 ) {
689 $set_thread = 2;
690 $thread_name = 'Unthread View';
691 }
692 elseif ($thread_sort_messages == 0) {
693 $set_thread = 1;
694 $thread_name = 'Thread View';
695 }
696 echo '<tr><td>&nbsp;<a href=' . "$base_uri" . 'src/right_main.php?sort='
697 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
698 . '&mailbox=' . urlencode($mailbox) . '><small>' . _("$thread_name")
699 . '</a></small>&nbsp;</td></tr>';
700 }
701
702 echo "</TABLE>\n";
6c930ade 703 do_hook('mailbox_form_before');
704 echo '</TD></TR>'
705 . "<TR><TD BGCOLOR=\"$color[0]\">"
706 . '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
707 if ($GLOBALS['alt_index_colors']){
708 echo '0';
709 } else {
710 echo '1';
711 }
712 echo " BGCOLOR=\"$color[0]\">"
713 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
aa0da530 714 /* if using server sort we highjack the
715 * the $sort var and use $server_sort_order
716 * instead. but here we reset sort for a bit
717 * since its easy
718 */
794d59c0 719 if ($allow_server_sort == TRUE) {
aa0da530 720 $sort = $server_sort_order;
721 }
6c930ade 722 /* Print the headers. */
723 for ($i=1; $i <= count($index_order); $i++) {
724 switch ($index_order[$i]) {
725 case 1: /* checkbox */
726 case 5: /* flags */
727 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
728 break;
729 case 2: /* from */
730 if (handleAsSent($mailbox)) {
731 echo ' <TD WIDTH="25%"><B>' . _("To") . '</B>';
732 } else {
733 echo ' <TD WIDTH="25%"><B>' . _("From") . '</B>';
734 }
794d59c0 735 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
6c930ade 736 ShowSortButton($sort, $mailbox, 2, 3);
737 }
738 echo "</TD>\n";
739 break;
740 case 3: /* date */
741 echo ' <TD NOWRAP WIDTH="5%"><B>' . _("Date") . '</B>';
794d59c0 742 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
6c930ade 743 ShowSortButton($sort, $mailbox, 0, 1);
744 }
745 echo "</TD>\n";
746 break;
747 case 4: /* subject */
748 echo ' <TD><B>' . _("Subject") . '</B> ';
794d59c0 749 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
6c930ade 750 ShowSortButton($sort, $mailbox, 4, 5);
751 }
752 echo "</TD>\n";
753 break;
754 case 6: /* size */
755 echo ' <TD WIDTH="5%"><b>' . _("Size") . "</b></TD>\n";
756 break;
bdfb67f8 757 }
6c930ade 758 }
aa0da530 759 /* if using server-sorting,
760 * send sort back to 6
761 */
794d59c0 762 if ($allow_server_sort == TRUE) {
aa0da530 763 $sort = 6;
764 }
6c930ade 765 echo "</TR>\n";
bdfb67f8 766}
767
768/*
769 * This function shows the sort button. Isn't this a good comment?
770 */
771function ShowSortButton($sort, $mailbox, $Up, $Down) {
6c930ade 772 /* Figure out which image we want to use. */
773 if ($sort != $Up && $sort != $Down) {
774 $img = 'sort_none.png';
775 $which = $Up;
776 } elseif ($sort == $Up) {
777 $img = 'up_pointer.png';
778 $which = $Down;
779 } else {
780 $img = 'down_pointer.png';
781 $which = 6;
782 }
783
784 /* Now that we have everything figured out, show the actual button. */
785 echo ' <a href="right_main.php?newsort=' . $which
786 . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
787 . '"><IMG SRC="../images/' . $img
788 . '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
bdfb67f8 789}
790
791function get_selectall_link($start_msg, $sort) {
6c930ade 792 global $checkall, $what, $where, $mailbox, $javascript_on;
793 global $PHP_SELF, $PG_SHOWNUM;
794
795 $result = '';
796 if ($javascript_on) {
797 $result =
798 '<script language="JavaScript" type="text/javascript">'
799 . "\n<!-- \n"
800 . "function CheckAll() {\n"
801 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
802 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
803 . " document.messageList.elements[i].checked = "
804 . " !(document.messageList.elements[i].checked);\n"
805 . " }\n"
806 . " }\n"
807 . "}\n"
808 . "//-->\n"
809 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
810 . "</a>\n";
811 } else {
812 if (strpos($PHP_SELF, "?")) {
813 $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
814 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
815 } else {
816 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
817 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
818 }
819 if (isset($checkall) && $checkall == '1') {
820 $result .= '0';
bdfb67f8 821 } else {
6c930ade 822 $result .= '1';
23d6bd09 823 }
6c930ade 824
825 if (isset($where) && isset($what)) {
826 $result .= '&amp;where=' . urlencode($where)
827 . '&amp;what=' . urlencode($what);
828 }
829
6c930ade 830 $result .= "\">";
831
832 if (isset($checkall) && ($checkall == '1')) {
833 $result .= _("Unselect All");
834 } else {
835 $result .= _("Select All");
836 }
837
838 $result .= "</A>\n";
839 }
23d6bd09 840
6c930ade 841 /* Return our final result. */
842 return ($result);
bdfb67f8 843}
1a0e0983 844
6c930ade 845/*
846 * This function computes the "Viewing Messages..." string.
847 */
bdfb67f8 848function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
6c930ade 849 /* Compute the $msg_cnt_str. */
850 $result = '';
851 if ($start_msg < $end_msg) {
852 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
853 $start_msg, $end_msg, $num_msgs);
854 } else if ($start_msg == $end_msg) {
855 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
856 } else {
857 $result = '<br>';
858 }
859
860 /* Return our result string. */
861 return ($result);
bdfb67f8 862}
863
6c930ade 864/*
7b294953 865 * Generate a paginator link.
866 */
6c930ade 867function get_paginator_link($box, $start_msg, $use, $text) {
868 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
869 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
870 . "TARGET=\"right\">$text</A>";
871 return ($result);
7b294953 872}
873
6c930ade 874/*
7b294953 875 * This function computes the paginator string.
876 */
6c930ade 877function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
878 $show_num, $sort) {
879 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
880
881 /* Initialize paginator string chunks. */
882 $prv_str = '';
883 $nxt_str = '';
884 $pg_str = '';
885 $all_str = '';
886 $tgl_str = '';
887
888 /* Create simple strings that will be creating the paginator. */
889 $spc = '&nbsp;'; /* This will be used as a space. */
890 $sep = '|'; /* This will be used as a seperator. */
891
892 /* Get some paginator preference values. */
893 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
894 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
895
896 /* Make sure that our start message number is not too big. */
897 $start_msg = min($start_msg, $num_msgs);
898
899 /* Decide whether or not we will use the mailbox cache. */
900 /* Not sure why $use_mailbox_cache is even passed in. */
901 if ($sort == 6) {
902 $use = 0;
903 } else {
904 $use = 1;
905 }
906
907 /* Compute the starting message of the previous and next page group. */
908 $next_grp = $start_msg + $show_num;
909 $prev_grp = $start_msg - $show_num;
910
911 /* Compute the basic previous and next strings. */
912 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
913 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
914 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
915 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
916 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
917 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
918 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
919 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
920 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
921 }
922
923 /* Page selector block. Following code computes page links. */
924 if ($pg_sel && ($num_msgs > $show_num)) {
925 /* Most importantly, what is the current page!!! */
926 $cur_pg = intval($start_msg / $show_num) + 1;
927
928 /* Compute total # of pages and # of paginator page links. */
929 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
930 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
931
932 /* Compute the size of the four quarters of the page links. */
933
934 /* If we can, just show all the pages. */
935 if (($tot_pgs - 1) <= $pg_max) {
936 $q1_pgs = $cur_pg - 1;
937 $q2_pgs = $q3_pgs = 0;
938 $q4_pgs = $tot_pgs - $cur_pg;
939
7b294953 940 /* Otherwise, compute some magic to choose the four quarters. */
6c930ade 941 } else {
942 /*
943 * Compute the magic base values. Added together,
944 * these values will always equal to the $pag_pgs.
945 * NOTE: These are DEFAULT values and do not take
946 * the current page into account. That is below.
947 */
948 $q1_pgs = floor($vis_pgs/4);
949 $q2_pgs = round($vis_pgs/4, 0);
950 $q3_pgs = ceil($vis_pgs/4);
951 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
7b294953 952
6c930ade 953 /* Adjust if the first quarter contains the current page. */
954 if (($cur_pg - $q1_pgs) < 1) {
955 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
956 $q1_pgs = $cur_pg - 1;
957 $q2_pgs = 0;
958 $q3_pgs += ceil($extra_pgs / 2);
959 $q4_pgs += floor($extra_pgs / 2);
960
961 /* Adjust if the first and second quarters intersect. */
962 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
963 $extra_pgs = $q2_pgs;
964 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
965 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
966 $q3_pgs += ceil($extra_pgs / 2);
967 $q4_pgs += floor($extra_pgs / 2);
968
969 /* Adjust if the fourth quarter contains the current page. */
970 } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
971 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
972 $q3_pgs = 0;
973 $q4_pgs = $tot_pgs - $cur_pg;
974 $q1_pgs += floor($extra_pgs / 2);
975 $q2_pgs += ceil($extra_pgs / 2);
976
977 /* Adjust if the third and fourth quarter intersect. */
978 } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
979 $extra_pgs = $q3_pgs;
980 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
981 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
982 $q1_pgs += floor($extra_pgs / 2);
983 $q2_pgs += ceil($extra_pgs / 2);
984 }
985 }
986
987 /*
988 * I am leaving this debug code here, commented out, because
989 * it is a really nice way to see what the above code is doing.
990 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
991 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
992 */
993
994 /* Print out the page links from the compute page quarters. */
995
996 /* Start with the first quarter. */
997 if (($q1_pgs == 0) && ($cur_pg > 1)) {
998 $pg_str .= "...$spc";
999 } else {
1000 for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
1001 $start = (($pg-1) * $show_num) + 1;
1002 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1003 }
1004 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1005 $pg_str .= "...$spc";
1006 }
1007 }
1008
1009 /* Continue with the second quarter. */
1010 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
1011 $start = (($pg-1) * $show_num) + 1;
1012 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1013 }
1014
1015 /* Now print the current page. */
1016 $pg_str .= $cur_pg . $spc;
1017
1018 /* Next comes the third quarter. */
1019 for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
1020 $start = (($pg-1) * $show_num) + 1;
1021 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1022 }
1023
1024 /* And last, print the forth quarter page links. */
1025 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1026 $pg_str .= "...$spc";
1027 } else {
1028 if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
1029 $pg_str .= "...$spc";
1030 }
1031 for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
1032 $start = (($pg-1) * $show_num) + 1;
1033 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1034 }
1035 }
1036 } else if ($PG_SHOWNUM == 999999) {
cf710efe 1037 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1038 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1039 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
6c930ade 1040 }
1041
1042 /* If necessary, compute the 'show all' string. */
1043 if (($prv_str != '') || ($nxt_str != '')) {
cf710efe 1044 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
6c930ade 1045 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1046 . "TARGET=\"right\">" . _("Show All") . '</A>';
1047 }
1048
1049 /* Last but not least, get the value for the toggle all link. */
1050 $tgl_str = get_selectall_link($start_msg, $sort);
1051
1052 /* Put all the pieces of the paginator string together. */
1053 /**
1054 * Hairy code... But let's leave it like it is since I am not certain
1055 * a different approach would be any easier to read. ;)
1056 */
1057 $result = '';
1058 $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
1059 $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
1060 $result .= ($pg_str != '' ? $pg_str : '');
1061 $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
1062 $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
1063
1064 /* If the resulting string is blank, return a non-breaking space. */
1065 if ($result == '') {
1066 $result = '&nbsp;';
1067 }
1068
1069 /* Return our final magical paginator string. */
1070 return ($result);
bdfb67f8 1071}
1072
1073function processSubject($subject) {
6c930ade 1074 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1075 if ($subject == '')
1076 return _("(no subject)");
1077
1078 if (strlen($subject) <= 55)
1079 return $subject;
1080
1081 $ent_strlen=strlen($subject);
1082 $trim_val=50;
1083 $ent_offset=0;
1084 /*
1085 * see if this is entities-encoded string
1086 * If so, Iterate through the whole string, find out
1087 * the real number of characters, and if more
1088 * than 55, substr with an updated trim value.
1089 */
1090 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1091 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
bdfb67f8 1092 $trim_val += ($ent_loc_end-$ent_loc)+1;
1093 $ent_strlen -= $ent_loc_end-$ent_loc;
1094 $ent_offset = $ent_loc_end+1;
6c930ade 1095 }
bdfb67f8 1096
6c930ade 1097 if ($ent_strlen <= 55){
1098 return $subject;
1099 }
1100
1101 return substr($subject, 0, $trim_val) . '...';
bdfb67f8 1102}
f93c93b9 1103
a3439b27 1104function handleAsSent($mailbox) {
6c930ade 1105 global $sent_folder, $draft_folder, $handleAsSent_result;
a3439b27 1106
6c930ade 1107 /* First check if this is the sent or draft folder. */
1108 $handleAsSent_result = (($mailbox == $sent_folder)
1109 || ($mailbox == $draft_folder));
1110
1111 /* Then check the result of the handleAsSent hook. */
1112 do_hook('check_handleAsSent_result', $mailbox);
a3439b27 1113
6c930ade 1114 /* And return the result. */
1115 return ($handleAsSent_result);
a3439b27 1116}
1117
7d89b19d 1118?>