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