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