Changeset 89 in subversion
- Timestamp:
- Dec 11, 2005 5:56:46 PM (7 years ago)
- Location:
- trunk/roundcubemail/program
- Files:
-
- 4 edited
-
include/bugs.inc (modified) (1 diff)
-
include/rcube_imap.inc (modified) (25 diffs)
-
lib/imap.inc (modified) (1 diff)
-
steps/mail/func.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/include/bugs.inc
r83 r89 98 98 if ($CONFIG['debug_level'] & 4) 99 99 { 100 print "<b>$program Error in $arg_arr[file] ($arg_arr[line]):</b> "; 100 print "<b>$program Error"; 101 102 if (!empty($arg_arr['file']) && !empty($arg_arr['line'])) 103 print " in $arg_arr[file] ($arg_arr[line])"; 104 105 print ":</b> "; 101 106 print nl2br($arg_arr['message']); 102 107 print '<br />'; -
trunk/roundcubemail/program/include/rcube_imap.inc
r88 r89 36 36 var $list_page = 1; 37 37 var $page_size = 10; 38 var $sort_field = 'date'; 39 var $sort_order = 'DESC'; 38 40 var $delimiter = NULL; 39 41 var $caching_enabled = FALSE; … … 280 282 // return cached value 281 283 if (!$force && is_array($a_mailbox_cache[$mailbox]) && isset($a_mailbox_cache[$mailbox][$mode])) 282 return $a_mailbox_cache[$mailbox][$mode]; 284 return $a_mailbox_cache[$mailbox][$mode]; 285 286 $search_str = "ALL UNDELETED"; 283 287 284 288 // get message count and store in cache 285 289 if ($mode == 'UNSEEN') 286 $count = iil_C_CountUnseen($this->conn, $mailbox); 287 else 288 $count = iil_C_CountMessages($this->conn, $mailbox); 290 $search_str .= " UNSEEN"; 291 292 // get message count using SEARCH 293 // not very performant but more precise (using UNDELETED) 294 $count = 0; 295 $index = $this->_search_index($mailbox, $search_str); 296 if (is_array($index)) 297 { 298 $str = implode(",", $index); 299 if (!empty($str)) 300 $count = count($index); 301 } 289 302 290 303 if (is_array($a_mailbox_cache[$mailbox])) … … 292 305 293 306 $a_mailbox_cache[$mailbox][$mode] = (int)$count; 294 307 295 308 // write back to cache 296 309 $this->update_cache('messagecount', $a_mailbox_cache); … … 302 315 // public method for listing headers 303 316 // convert mailbox name with root dir first 304 function list_headers($mbox='', $page=NULL, $sort_field= 'date', $sort_order='DESC')317 function list_headers($mbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL) 305 318 { 306 319 $mailbox = $mbox ? $this->_mod_mailbox($mbox) : $this->mailbox; … … 310 323 311 324 // private method for listing message header 312 function _list_headers($mailbox='', $page=NULL, $sort_field= 'date', $sort_order='DESC')325 function _list_headers($mailbox='', $page=NULL, $sort_field=NULL, $sort_order=NULL, $recursive=FALSE) 313 326 { 314 327 if (!strlen($mailbox)) 315 328 return array(); 329 330 if ($sort_field!=NULL) 331 $this->sort_field = $sort_field; 332 if ($sort_order!=NULL) 333 $this->sort_order = strtoupper($sort_order); 316 334 317 335 $max = $this->_messagecount($mailbox); … … 323 341 $end = $max; 324 342 } 325 else if ($ sort_order=='DESC')343 else if ($this->sort_order=='DESC') 326 344 { 327 345 $begin = $max - $this->page_size - $start_msg; … … 349 367 if ($cache_status>0) 350 368 { 351 $a_msg_headers = $this->get_message_cache($cache_key, $start_msg, $start_msg+$this->page_size, $ sort_field, $sort_order);369 $a_msg_headers = $this->get_message_cache($cache_key, $start_msg, $start_msg+$this->page_size, $this->sort_field, $this->sort_order); 352 370 $headers_sorted = TRUE; 353 371 } … … 355 373 { 356 374 // retrieve headers from IMAP 357 if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $ sort_field)))375 if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field))) 358 376 { 359 377 //console("$mailbox: ".count($msg_index)); … … 362 380 for ($i=$begin; $i < $end; $i++) 363 381 { 364 if ($ sort_order == 'DESC')382 if ($this->sort_order == 'DESC') 365 383 $msgs = $msg_index[$i].','.$msgs; 366 384 else … … 378 396 379 397 // cache is dirty, sync it 380 if ($this->caching_enabled && $cache_status==-1 )398 if ($this->caching_enabled && $cache_status==-1 && !$recursive) 381 399 { 382 400 $this->sync_header_index($mailbox); 383 return $this->_list_headers($mailbox, $page, $ sort_field, $sort_order);401 return $this->_list_headers($mailbox, $page, $this->sort_field, $this->sort_order, TRUE); 384 402 } 385 403 … … 391 409 $a_header_index = iil_C_FetchHeaders($this->conn, $mailbox, $msgs); 392 410 $a_msg_headers = array(); 393 411 $deleted_count = 0; 394 412 395 413 if (!empty($a_header_index)) … … 403 421 $this->remove_message_cache($cache_key, $headers->id); 404 422 423 $deleted_count++; 405 424 continue; 406 425 } … … 418 437 419 438 439 // fetch more headers of there were any deleted messages 440 // ... 441 420 442 // kick child process to sync cache 443 // ... 421 444 422 445 } … … 430 453 // if not already sorted 431 454 if (!$headers_sorted) 432 $a_msg_headers = iil_SortHeaders($a_msg_headers, $ sort_field, $sort_order);455 $a_msg_headers = iil_SortHeaders($a_msg_headers, $this->sort_field, $this->sort_order); 433 456 434 457 return array_values($a_msg_headers); … … 437 460 438 461 // return sorted array of message UIDs 439 function message_index($mbox='', $sort_field='date', $sort_order='DESC') 440 { 462 function message_index($mbox='', $sort_field=NULL, $sort_order=NULL) 463 { 464 if ($sort_field!=NULL) 465 $this->sort_field = $sort_field; 466 if ($sort_order!=NULL) 467 $this->sort_order = strtoupper($sort_order); 468 441 469 $mailbox = $mbox ? $this->_mod_mailbox($mbox) : $this->mailbox; 442 $a_out = array(); 443 444 // get array of message headers 445 $a_headers = $this->_list_headers($mailbox, 'all', $sort_field, $sort_order); 446 447 if (is_array($a_headers)) 448 foreach ($a_headers as $header) 449 $a_out[] = $header->uid; 450 451 return $a_out; 470 $key = "$mbox:".$this->sort_field.":".$this->sort_order.".msgi"; 471 472 // have stored it in RAM 473 if (isset($this->cache[$key])) 474 return $this->cache[$key]; 475 476 // check local cache 477 $cache_key = $mailbox.'.msg'; 478 $cache_status = $this->check_cache_status($mailbox, $cache_key); 479 480 // cache is OK 481 if ($cache_status>0) 482 { 483 $a_index = get_message_cache_index($cache_key, FALSE, $this->sort_field); 484 return array_values($a_index); 485 } 486 487 488 // fetch complete message index 489 $msg_count = $this->_messagecount($mailbox); 490 if ($this->get_capability('sort') && ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field))) 491 { 492 $a_uids = iil_C_FetchUIDs($this->conn, $mailbox); 493 494 if ($this->sort_order == 'DESC') 495 $a_index = array_reverse($a_index); 496 497 $i = 0; 498 $this->cache[$key] = array(); 499 foreach ($a_index as $index => $value) 500 $this->cache[$key][$i++] = $a_uids[$value]; 501 } 502 else 503 { 504 $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:$msg_count", $this->sort_field); 505 $a_uids = iil_C_FetchUIDs($this->conn, $mailbox); 506 507 if ($this->sort_order=="ASC") 508 asort($a_index); 509 else if ($this->sort_order=="DESC") 510 arsort($a_index); 511 512 $i = 0; 513 $this->cache[$key] = array(); 514 foreach ($a_index as $index => $value) 515 $this->cache[$key][$i++] = $a_uids[$index]; 516 } 517 518 return $this->cache[$key]; 452 519 } 453 520 … … 507 574 { 508 575 $mailbox = $mbox ? $this->_mod_mailbox($mbox) : $this->mailbox; 576 return $this->_search_index($mailbox, $criteria); 577 } 578 579 580 function _search_index($mailbox, $criteria='ALL') 581 { 509 582 $a_messages = iil_C_Search($this->conn, $mailbox, $criteria); 510 583 return $a_messages; … … 571 644 572 645 foreach ($uids as $uid) 573 $msg_ids[ ] = $this->_uid2id($uid);646 $msg_ids[$uid] = $this->_uid2id($uid); 574 647 575 648 if ($flag=='UNSEEN') 576 $result = iil_C_Unseen($this->conn, $this->mailbox, join(',', $msg_ids));649 $result = iil_C_Unseen($this->conn, $this->mailbox, join(',', array_values($msg_ids))); 577 650 else 578 $result = iil_C_Flag($this->conn, $this->mailbox, join(',', $msg_ids), $flag);651 $result = iil_C_Flag($this->conn, $this->mailbox, join(',', array_values($msg_ids)), $flag); 579 652 580 653 // reload message headers if cached … … 582 655 if ($this->caching_enabled) 583 656 { 584 foreach ($msg_ids as $ id)585 { 586 if ($cached_headers = $this->get_cached_message($cache_key, $ id))657 foreach ($msg_ids as $uid => $id) 658 { 659 if ($cached_headers = $this->get_cached_message($cache_key, $uid)) 587 660 { 588 661 $this->remove_message_cache($cache_key, $id); … … 597 670 598 671 // set nr of messages that were flaged 599 $count = sizeof($msg_ids);672 $count = count($msg_ids); 600 673 601 674 // clear message count cache … … 1161 1234 1162 1235 1163 function get_message_cache_index($key, $force=FALSE )1236 function get_message_cache_index($key, $force=FALSE, $sort_col='idx') 1164 1237 { 1165 1238 static $sa_message_index = array(); … … 1174 1247 WHERE user_id=? 1175 1248 AND cache_key=? 1176 ORDER BY idxASC",1249 ORDER BY ".$sort_col." ASC", 1177 1250 $_SESSION['user_id'], 1178 1251 $key); … … 1187 1260 function add_message_cache($key, $index, $headers) 1188 1261 { 1262 if (!is_object($headers) || empty($headers->uid)) 1263 return; 1264 1189 1265 $this->db->query( 1190 1266 "INSERT INTO ".get_table_name('messages')." … … 1199 1275 $this->decode_header($headers->to, TRUE), 1200 1276 $this->decode_header($headers->cc, TRUE), 1201 $headers->size,1277 (int)$headers->size, 1202 1278 serialize($headers)); 1203 1279 } … … 1269 1345 function decode_header($input, $remove_quotes=FALSE) 1270 1346 { 1271 $str = $this->decode_mime_string( $input);1347 $str = $this->decode_mime_string((string)$input); 1272 1348 if ($str{0}=='"' && $remove_quotes) 1273 1349 { … … 1519 1595 // add incremental value to messagecount 1520 1596 $a_mailbox_cache[$mailbox][$mode] += $increment; 1597 1598 // there's something wrong, delete from cache 1599 if ($a_mailbox_cache[$mailbox][$mode] < 0) 1600 unset($a_mailbox_cache[$mailbox][$mode]); 1521 1601 1522 1602 // write back to cache -
trunk/roundcubemail/program/lib/imap.inc
r62 r89 619 619 620 620 $fp = $conn->fp; 621 $command = 's SORT ('.$field.') US-ASCII ALL '."\r\n";621 $command = 's SORT ('.$field.') US-ASCII ALL UNDELETED'."\r\n"; 622 622 $line = $data = ''; 623 623 -
trunk/roundcubemail/program/steps/mail/func.inc
r88 r89 529 529 if (isset($MESSAGE['index'])) 530 530 { 531 $a_msg_index = $IMAP->message_index();532 531 return rcube_label(array('name' => 'messagenrof', 533 532 'vars' => array('nr' => $MESSAGE['index']+1, 534 'count' => sizeof($a_msg_index))));535 } 536 533 'count' => $IMAP->messagecount()))); 534 } 535 537 536 $start_msg = ($IMAP->list_page-1) * $IMAP->page_size + 1; 538 537 $max = $IMAP->messagecount();
Note: See TracChangeset
for help on using the changeset viewer.
