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