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