Some small HTML fixes/improvements
[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" title="'
882 . _("Click here to change the sorting of the message list") .'"></a>';
883 }
884
885 function get_selectall_link($start_msg, $sort) {
886 global $checkall, $what, $where, $mailbox, $javascript_on;
887 global $PHP_SELF, $PG_SHOWNUM;
888
889 $result = '';
890 if ($javascript_on) {
891 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
892 $func_name = "CheckAll" . $safe_name;
893 $form_name = "FormMsgs" . $safe_name;
894 $result = '<script language="JavaScript" type="text/javascript">'
895 . "\n<!-- \n"
896 . "function " . $func_name . "() {\n"
897 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
898 . " if(document." . $form_name . ".elements[i].type == 'checkbox'){\n"
899 . " document." . $form_name . ".elements[i].checked = "
900 . " !(document." . $form_name . ".elements[i].checked);\n"
901 . " }\n"
902 . " }\n"
903 . "}\n"
904 . "//-->\n"
905 . '</script><a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
906 /* . '</script><a href="javascript:' . $func_name . '()">' . _("Toggle All")*/
907 . "</a>\n";
908 } else {
909 if (strpos($PHP_SELF, "?")) {
910 $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
911 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
912 } else {
913 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
914 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
915 }
916 if (isset($checkall) && $checkall == '1') {
917 $result .= '0';
918 } else {
919 $result .= '1';
920 }
921
922 if (isset($where) && isset($what)) {
923 $result .= '&amp;where=' . urlencode($where)
924 . '&amp;what=' . urlencode($what);
925 }
926 $result .= "\">";
927
928 if (isset($checkall) && ($checkall == '1')) {
929 $result .= _("Unselect All");
930 } else {
931 $result .= _("Select All");
932 }
933 $result .= "</A>\n";
934 }
935
936 /* Return our final result. */
937 return ($result);
938 }
939
940 /*
941 * This function computes the "Viewing Messages..." string.
942 */
943 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
944 /* Compute the $msg_cnt_str. */
945 $result = '';
946 if ($start_msg < $end_msg) {
947 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
948 $start_msg, $end_msg, $num_msgs);
949 } else if ($start_msg == $end_msg) {
950 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
951 } else {
952 $result = '<br>';
953 }
954 /* Return our result string. */
955 return ($result);
956 }
957
958 /*
959 * Generate a paginator link.
960 */
961 function get_paginator_link($box, $start_msg, $use, $text) {
962 global $PHP_SELF;
963
964 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
965 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
966 . "TARGET=\"right\">$text</A>";
967 return ($result);
968 /*
969 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
970 $source_url = $regs[1];
971 } else {
972 $source_url = $PHP_SELF;
973 }
974
975 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
976 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
977 . "TARGET=\"right\">$text</A>";
978 return ($result);
979 */
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 $box = urlencode($box);
997
998 /* Create simple strings that will be creating the paginator. */
999 $spc = '&nbsp;'; /* This will be used as a space. */
1000 $sep = '|'; /* This will be used as a seperator. */
1001
1002 /* Get some paginator preference values. */
1003 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
1004 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
1005
1006 /* Make sure that our start message number is not too big. */
1007 $start_msg = min($start_msg, $num_msgs);
1008
1009 /* Decide whether or not we will use the mailbox cache. */
1010 /* Not sure why $use_mailbox_cache is even passed in. */
1011 if ($sort == 6) {
1012 $use = 0;
1013 } else {
1014 $use = 1;
1015 }
1016
1017 /* Compute the starting message of the previous and next page group. */
1018 $next_grp = $start_msg + $show_num;
1019 $prev_grp = $start_msg - $show_num;
1020
1021 /* Compute the basic previous and next strings. */
1022 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1023 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1024 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1025 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1026 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1027 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1028 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1029 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1030 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1031 }
1032
1033 /* Page selector block. Following code computes page links. */
1034 if ($pg_sel && ($num_msgs > $show_num)) {
1035 /* Most importantly, what is the current page!!! */
1036 $cur_pg = intval($start_msg / $show_num) + 1;
1037
1038 /* Compute total # of pages and # of paginator page links. */
1039 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1040 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1041
1042 /* Compute the size of the four quarters of the page links. */
1043
1044 /* If we can, just show all the pages. */
1045 if (($tot_pgs - 1) <= $pg_max) {
1046 $q1_pgs = $cur_pg - 1;
1047 $q2_pgs = $q3_pgs = 0;
1048 $q4_pgs = $tot_pgs - $cur_pg;
1049
1050 /* Otherwise, compute some magic to choose the four quarters. */
1051 } else {
1052 /*
1053 * Compute the magic base values. Added together,
1054 * these values will always equal to the $pag_pgs.
1055 * NOTE: These are DEFAULT values and do not take
1056 * the current page into account. That is below.
1057 */
1058 $q1_pgs = floor($vis_pgs/4);
1059 $q2_pgs = round($vis_pgs/4, 0);
1060 $q3_pgs = ceil($vis_pgs/4);
1061 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1062
1063 /* Adjust if the first quarter contains the current page. */
1064 if (($cur_pg - $q1_pgs) < 1) {
1065 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
1066 $q1_pgs = $cur_pg - 1;
1067 $q2_pgs = 0;
1068 $q3_pgs += ceil($extra_pgs / 2);
1069 $q4_pgs += floor($extra_pgs / 2);
1070
1071 /* Adjust if the first and second quarters intersect. */
1072 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1073 $extra_pgs = $q2_pgs;
1074 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1075 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1076 $q3_pgs += ceil($extra_pgs / 2);
1077 $q4_pgs += floor($extra_pgs / 2);
1078
1079 /* Adjust if the fourth quarter contains the current page. */
1080 } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
1081 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
1082 $q3_pgs = 0;
1083 $q4_pgs = $tot_pgs - $cur_pg;
1084 $q1_pgs += floor($extra_pgs / 2);
1085 $q2_pgs += ceil($extra_pgs / 2);
1086
1087 /* Adjust if the third and fourth quarter intersect. */
1088 } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
1089 $extra_pgs = $q3_pgs;
1090 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1091 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1092 $q1_pgs += floor($extra_pgs / 2);
1093 $q2_pgs += ceil($extra_pgs / 2);
1094 }
1095 }
1096
1097 /*
1098 * I am leaving this debug code here, commented out, because
1099 * it is a really nice way to see what the above code is doing.
1100 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1101 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1102 */
1103
1104 /* Print out the page links from the compute page quarters. */
1105
1106 /* Start with the first quarter. */
1107 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1108 $pg_str .= "...$spc";
1109 } else {
1110 for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
1111 $start = (($pg-1) * $show_num) + 1;
1112 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1113 }
1114 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1115 $pg_str .= "...$spc";
1116 }
1117 }
1118
1119 /* Continue with the second quarter. */
1120 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
1121 $start = (($pg-1) * $show_num) + 1;
1122 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1123 }
1124
1125 /* Now print the current page. */
1126 $pg_str .= $cur_pg . $spc;
1127
1128 /* Next comes the third quarter. */
1129 for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
1130 $start = (($pg-1) * $show_num) + 1;
1131 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1132 }
1133
1134 /* And last, print the forth quarter page links. */
1135 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1136 $pg_str .= "...$spc";
1137 } else {
1138 if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
1139 $pg_str .= "...$spc";
1140 }
1141 for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
1142 $start = (($pg-1) * $show_num) + 1;
1143 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1144 }
1145 }
1146 } else if ($PG_SHOWNUM == 999999) {
1147 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1148 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1149 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1150 }
1151
1152 /* If necessary, compute the 'show all' string. */
1153 if (($prv_str != '') || ($nxt_str != '')) {
1154 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1155 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1156 . "TARGET=\"right\">" . _("Show All") . '</A>';
1157 }
1158
1159 /* Last but not least, get the value for the toggle all link. */
1160 $tgl_str = get_selectall_link($start_msg, $sort);
1161
1162 /* Put all the pieces of the paginator string together. */
1163 /**
1164 * Hairy code... But let's leave it like it is since I am not certain
1165 * a different approach would be any easier to read. ;)
1166 */
1167 $result = '';
1168 $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
1169 $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
1170 $result .= ($pg_str != '' ? $pg_str : '');
1171 $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
1172 $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
1173
1174 /* If the resulting string is blank, return a non-breaking space. */
1175 if ($result == '') {
1176 $result = '&nbsp;';
1177 }
1178
1179 /* Return our final magical paginator string. */
1180 return ($result);
1181 }
1182
1183 function processSubject($subject, $threadlevel = 0) {
1184 global $languages, $squirrelmail_language;
1185 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1186 if ($subject == '') {
1187 return _("(no subject)");
1188 }
1189
1190 $trim_at = SUBJ_TRIM_AT;
1191
1192 /* if this is threaded, subtract two chars per indentlevel */
1193 if($threadlevel > 0 && $threadlevel <= 10) {
1194 $trim_at -= (2*$threadlevel);
1195 }
1196
1197 if (strlen($subject) <= $trim_at) {
1198 return $subject;
1199 }
1200
1201 $ent_strlen = $orig_len = strlen($subject);
1202 $trim_val = $trim_at - 5;
1203 $ent_offset = 0;
1204 /*
1205 * see if this is entities-encoded string
1206 * If so, Iterate through the whole string, find out
1207 * the real number of characters, and if more
1208 * than 55, substr with an updated trim value.
1209 */
1210 $step = $ent_loc = 0;
1211 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1212 (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) {
1213 $trim_val += ($ent_loc_end-$ent_loc);
1214 $ent_offset = $ent_loc_end+1;
1215 ++$step;
1216 }
1217
1218 if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +6))) {
1219 $i = strpos($subject,';',$trim_val);
1220 if ($i) {
1221 $trim_val = strpos($subject,';',$trim_val);
1222 }
1223 }
1224 if ($ent_strlen <= $trim_at){
1225 return $subject;
1226 }
1227
1228 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1229 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1230 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1231 }
1232
1233 // only print '...' when we're actually dropping part of the subject
1234 if(strlen($subject) <= $trim_val) {
1235 return $subject;
1236 } else {
1237 return substr($subject, 0, $trim_val) . '...';
1238 }
1239 }
1240
1241 function getMbxList($imapConnection) {
1242 global $lastTargetMailbox;
1243 echo ' <small>&nbsp;<tt><select name="targetMailbox">';
1244 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
1245 echo ' </SELECT></TT>&nbsp;';
1246 }
1247
1248 function getButton($type, $name, $value) {
1249 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
1250 }
1251
1252 function getSmallStringCell($string, $align) {
1253 return html_tag('td',
1254 '<small>' . $string . ':&nbsp; </small>',
1255 $align,
1256 '',
1257 'nowrap' );
1258 }
1259
1260 function getEndMessage($start_msg, $show_num, $num_msgs) {
1261 if ($start_msg + ($show_num - 1) < $num_msgs){
1262 $end_msg = $start_msg + ($show_num - 1);
1263 } else {
1264 $end_msg = $num_msgs;
1265 }
1266
1267 if ($end_msg < $start_msg) {
1268 $start_msg = $start_msg - $show_num;
1269 if ($start_msg < 1) {
1270 $start_msg = 1;
1271 }
1272 }
1273 return (array($start_msg,$end_msg));
1274 }
1275
1276 function handleAsSent($mailbox) {
1277 global $handleAsSent_result;
1278
1279 /* First check if this is the sent or draft folder. */
1280 $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
1281
1282 /* Then check the result of the handleAsSent hook. */
1283 do_hook('check_handleAsSent_result', $mailbox);
1284
1285 /* And return the result. */
1286 return $handleAsSent_result;
1287 }
1288
1289 ?>