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