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