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