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