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