7cb5e4e12381f47f4bfb9bf8773503733f638026
[squirrelmail.git] / functions / mailbox_display.php
1 <?php
2
3 /**
4 * mailbox_display.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
11 *
12 * $Id$
13 */
14
15 require_once('../functions/strings.php');
16 require_once('../functions/imap_utf7_decode_local.php');
17 require_once('../functions/html.php');
18
19 /* Default value for page_selector_max. */
20 define('PG_SEL_MAX', 10);
21
22 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
23 $start_msg, $where, $what){
24 global $checkall,
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];
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 /*
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 }
65 }
66
67 if( $mailbox == 'None' ) {
68 $boxes = sqimap_mailbox_list($imapConnection);
69 $mailbox = $boxes[0]['unformatted'];
70 unset( $boxes );
71 }
72 $urlMailbox = urlencode($mailbox);
73 $subject = processSubject($msg['SUBJECT']);
74 echo "<TR>\n";
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 = '';
82 }
83 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
84 $bold = '<b>';
85 $bold_end = '</b>';
86 } else {
87 $bold = '';
88 $bold_end = '';
89 }
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 = '';
142 }
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,
159 'left',
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"]
179 . "&amp;startMessage=$start_msg&amp;show_more=0$search_stuff\"";
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";
189 echo html_tag( 'td', $td_str, 'left', $hlt_color );
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 }
237 }
238 echo "</tr>\n";
239 }
240
241 /*
242 * This function loops through a group of messages in the mailbox
243 * and shows them to the user.
244 */
245 function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
246 $start_msg, $sort, $color, $show_num,
247 $use_cache) {
248 global $msgs, $msort,
249 $sent_folder, $draft_folder,
250 $message_highlight_list,
251 $auto_expunge, $thread_sort_messages, $allow_server_sort,
252 $data_dir, $username, $server_sort_order;
253
254 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
255 * in the last page. We need to re-adjust the start_msg
256 */
257
258 if($start_msg > $num_msgs) {
259 $start_msg -= $show_num;
260 if($start_msg < 1) {
261 $start_msg = 1;
262 }
263 }
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 }
289 }
290
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 }
312 }
313
314 /* If autoexpunge is turned on, then do it now. */
315 if ($auto_expunge == true) {
316 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
317 }
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 }
339
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');
505 }
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');
512 }
513
514 /* Generic function to convert the msgs array into an HTML table. */
515 function 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
525 /* If cache isn't already set, do it now. */
526 if (!session_is_registered('msgs')) {
527 session_register('msgs');
528 }
529 if (!session_is_registered('msort')) {
530 session_register('msort');
531 }
532
533 if ($start_msg + ($show_num - 1) < $num_msgs){
534 $end_msg = $start_msg + ($show_num - 1);
535 } else {
536 $end_msg = $num_msgs;
537 }
538
539 if ($end_msg < $start_msg) {
540 $start_msg = $start_msg - $show_num;
541 if ($start_msg < 1) {
542 $start_msg = 1;
543 }
544 }
545
546 $urlMailbox = urlencode($mailbox);
547
548 do_hook('mailbox_index_before');
549
550 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
551 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg,
552 $num_msgs, $show_num, $sort);
553
554 if (!isset($msg)) {
555 $msg = '';
556 }
557
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"
563 . "&amp;startMessage=$start_msg";
564 mail_message_listing_beginning($imapConnection, $fstring,
565 $mailbox, $sort, $msg_cnt_str,
566 $paginator_str, $start_msg);
567
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) {
572 $end_msg = $end_msg - $start_msg + 1;
573 $start_msg = 1;
574 } else if ($start_msg > $show_num) {
575 $end_msg = $show_num;
576 $start_msg = 1;
577 }
578 }
579 $endVar = $end_msg + 1;
580
581 /*
582 * Loop through and display the info for each message.
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 */
588 echo html_tag( 'tr',
589 html_tag( 'td',
590 "<BR><B>" . _("THIS FOLDER IS EMPTY") . "</B><BR>&nbsp;",
591 'center',
592 $color[4],
593 'COLSPAN="' . count($index_order) . '"'
594 )
595 );
596
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));
611 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort,
612 $real_startMessage, 0, 0);
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 {
623 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
624 $sort, $real_startMessage, 0, 0);
625 $key = key($msort);
626 $t++;
627 $i++;
628 next($msort);
629 } while ($i && $i < $endVar);
630 }
631
632 echo '</table>';
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' )
641 )
642 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
643 )
644 , '', $color[4] )
645 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
646
647 /* End of message-list table */
648
649 do_hook('mailbox_index_after');
650 echo "</TABLE></FORM>\n";
651 }
652
653 /*
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
664 function mail_message_listing_beginning ($imapConnection, $moveURL,
665 $mailbox = '', $sort = -1,
666 $msg_cnt_str = '',
667 $paginator = '&nbsp;',
668 $start_msg = 1) {
669 global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri,
670 $checkall, $sent_folder, $draft_folder, $thread_sort_messages,
671 $allow_thread_sort, $allow_server_sort, $server_sort_order,
672 $lastTargetMailbox;
673
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"
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] )
692 . '<TR>'
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',
697 '<SMALL>&nbsp;' . _("Move Selected To:") . '</SMALL>',
698 'left',
699 '',
700 'valign="middle" nowrap' ) .
701 html_tag( 'td',
702 '<SMALL>' . _("Transform Selected Messages") . ': &nbsp; </SMALL><BR>',
703 'right',
704 '',
705 'nowrap' )
706 )
707 . " <TR>\n"
708 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' )
709 . ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
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 }
719 if ($lastTargetMailbox == $box) {
720 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
721 }
722 else {
723 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
724 }
725 }
726 }
727 echo ' </SELECT></TT>&nbsp;'
728 . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '">&nbsp;'
729 . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward")
730 . "\">&nbsp;\n" . "</SMALL>\n";
731
732 echo " </TD>\n"
733 . " <TD ALIGN=\"RIGHT\" NOWRAP>";
734 if (!$auto_expunge) {
735 echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge")
736 . '">&nbsp;' . _("mailbox") . '&nbsp;';
737 }
738 echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">'
739 . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">'
740 . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '">&nbsp;'
741 . "</TD>\n"
742 . " </TR>\n";
743
744 /* draws thread sorting links */
745 if ($allow_thread_sort == TRUE) {
746 if ($thread_sort_messages == 1 ) {
747 $set_thread = 2;
748 $thread_name = _("Unthread View");
749 }
750 elseif ($thread_sort_messages == 0) {
751 $set_thread = 1;
752 $thread_name = _("Thread View");
753 }
754 echo html_tag( 'tr' ,
755 html_tag( 'td' ,
756 '&nbsp;<a href=' . "$base_uri" . 'src/right_main.php?sort='
757 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
758 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
759 . '</a></small>&nbsp;'
760 , '', '', '' )
761 , '', '', '' );
762 }
763
764 echo "</TABLE>\n";
765 do_hook('mailbox_form_before');
766 echo '</TD></TR><TR>'
767 . html_tag( 'td' ,'' , '', $color[0], '' );
768 if ($GLOBALS['alt_index_colors']){
769 $cellspacing = '0';
770 } else {
771 $cellspacing = '1';
772 }
773 echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' )
774 . "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
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 */
788 echo ' <TD WIDTH="1%"></TD>';
789 break;
790 case 2: /* from */
791 if (handleAsSent($mailbox)) {
792 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
793 . '<b>' . _("To") . '</b>';
794 } else {
795 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
796 . '<b>' . _("From") . '</b>';
797 }
798 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
799 ShowSortButton($sort, $mailbox, 2, 3);
800 }
801 echo "</TD>\n";
802 break;
803 case 3: /* date */
804 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
805 . '<b>' . _("Date") . '</b>';
806 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
807 ShowSortButton($sort, $mailbox, 0, 1);
808 }
809 echo "</td>\n";
810 break;
811 case 4: /* subject */
812 echo html_tag( 'td' ,'' , 'left', '', '' )
813 . '<b>' . _("Subject") . '</b>';
814 if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) {
815 ShowSortButton($sort, $mailbox, 4, 5);
816 }
817 echo "</TD>\n";
818 break;
819 case 6: /* size */
820 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
821 break;
822 }
823 }
824 /* if using server-sorting,
825 * send sort back to 6
826 */
827 if ($allow_server_sort == TRUE) {
828 $sort = 6;
829 }
830 echo "</TR>\n";
831 }
832
833 /*
834 * This function shows the sort button. Isn't this a good comment?
835 */
836 function ShowSortButton($sort, $mailbox, $Up, $Down) {
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
851 . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
852 . '"><IMG SRC="../images/' . $img
853 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
854 }
855
856 function get_selectall_link($start_msg, $sort) {
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";
876 } else {
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
903 $result .= "</A>\n";
904 }
905
906 /* Return our final result. */
907 return ($result);
908 }
909
910 /*
911 * This function computes the "Viewing Messages..." string.
912 */
913 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
914 /* Compute the $msg_cnt_str. */
915 $result = '';
916 if ($start_msg < $end_msg) {
917 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
918 $start_msg, $end_msg, $num_msgs);
919 } else if ($start_msg == $end_msg) {
920 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
921 } else {
922 $result = '<br>';
923 }
924
925 /* Return our result string. */
926 return ($result);
927 }
928
929 /*
930 * Generate a paginator link.
931 */
932 function get_paginator_link($box, $start_msg, $use, $text) {
933 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
934 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
935 . "TARGET=\"right\">$text</A>";
936 return ($result);
937 }
938
939 /*
940 * This function computes the paginator string.
941 */
942 function 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"));
982 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
983 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
984 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
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) {
1102 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1103 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1104 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1105 }
1106
1107 /* If necessary, compute the 'show all' string. */
1108 if (($prv_str != '') || ($nxt_str != '')) {
1109 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1110 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1111 . "TARGET=\"right\">" . _("Show All") . '</A>';
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);
1136 }
1137
1138 function processSubject($subject) {
1139 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1140 if ($subject == '')
1141 return _("(no subject)");
1142
1143 if (strlen($subject) <= 55)
1144 return $subject;
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) . '...';
1167 }
1168
1169 function handleAsSent($mailbox) {
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));
1175
1176 /* Then check the result of the handleAsSent hook. */
1177 do_hook('check_handleAsSent_result', $mailbox);
1178
1179 /* And return the result. */
1180 return ($handleAsSent_result);
1181 }
1182
1183 ?>