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