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