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