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