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