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