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