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