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