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