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