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