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