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