Changeset 2dd7ee3 in github


Ignore:
Timestamp:
Jun 10, 2009 8:07:55 AM (4 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
d9c83e7
Parents:
737f0da3
Message:
  • Fixed many 'skip_deleted' issues (#1485634)
  • Fixed messages list sorting on servers without SORT capability
  • some preformance improvements
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    ra54242c r2dd7ee3  
    22=========================== 
    33 
     4- Fixed many 'skip_deleted' issues (#1485634) 
     5- Fixed messages list sorting on servers without SORT capability 
    46- Colorized signatures in plain text messages 
    57- Reviewed/fixed skip_deleted/read_when_deleted/flag_for_deletion options handling in UI 
  • program/include/rcube_imap.php

    r384d83a r2dd7ee3  
    507507      // get message count using SEARCH 
    508508      // not very performant but more precise (using UNDELETED) 
    509       $count = 0; 
    510509      $index = $this->_search_index($mailbox, $search_str); 
    511       if (is_array($index)) 
    512         { 
    513         $str = implode(",", $index); 
    514         if (!empty($str)) 
    515           $count = count($index); 
    516         } 
     510      $count = is_array($index) ? count($index) : 0; 
    517511      } 
    518512    else 
     
    571565    $this->_set_sort_order($sort_field, $sort_order); 
    572566 
    573     $max = $this->_messagecount($mailbox); 
    574     $start_msg = ($this->list_page-1) * $this->page_size; 
    575  
    576     list($begin, $end) = $this->_get_message_range($max, $page); 
    577  
    578     // mailbox is empty 
    579     if ($begin >= $end) 
    580       return array(); 
    581        
    582     $headers_sorted = FALSE; 
     567    $page = $page ? $page : $this->list_page; 
    583568    $cache_key = $mailbox.'.msg'; 
    584569    $cache_status = $this->check_cache_status($mailbox, $cache_key); 
     
    587572    if ($cache_status>0) 
    588573      { 
     574      $start_msg = ($page-1) * $this->page_size; 
    589575      $a_msg_headers = $this->get_message_cache($cache_key, $start_msg, $start_msg+$this->page_size, $this->sort_field, $this->sort_order); 
    590       $headers_sorted = TRUE; 
     576      return array_values($a_msg_headers); 
    591577      } 
    592578    // cache is dirty, sync it 
     
    596582      return $this->_list_headers($mailbox, $page, $this->sort_field, $this->sort_order, TRUE); 
    597583      } 
     584 
     585    // retrieve headers from IMAP 
     586    $a_msg_headers = array(); 
     587 
     588    if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 
     589      { 
     590      list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 
     591      $max = max($msg_index); 
     592      $msg_index = array_slice($msg_index, $begin, $end-$begin); 
     593 
     594      // fetch reqested headers from server 
     595      $this->_fetch_headers($mailbox, join(',', $msg_index), $a_msg_headers, $cache_key); 
     596      } 
    598597    else 
    599598      { 
    600       // retrieve headers from IMAP 
    601       if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 
    602         { 
    603         $mymsgidx = array_slice ($msg_index, $begin, $end-$begin); 
    604         $msgs = join(",", $mymsgidx); 
    605         } 
    606       else 
    607         { 
    608         $msgs = sprintf("%d:%d", $begin+1, $end); 
    609         $msg_index = range($begin, $end); 
    610         } 
    611  
    612  
    613       // fetch reuested headers from server 
    614       $a_msg_headers = array(); 
    615       $deleted_count = $this->_fetch_headers($mailbox, $msgs, $a_msg_headers, $cache_key); 
    616  
    617       // delete cached messages with a higher index than $max+1 
    618       // Changed $max to $max+1 to fix this bug : #1484295 
    619       $this->clear_message_cache($cache_key, $max + 1); 
    620  
    621       // kick child process to sync cache 
    622       // ... 
    623       } 
     599      $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", $this->sort_field, $this->skip_deleted); 
     600     
     601      if (empty($a_index)) 
     602        return array(); 
     603 
     604      asort($a_index); // ASC 
     605      $msg_index = array_keys($a_index); 
     606      $max = max($msg_index); 
     607      list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 
     608      $msg_index = array_slice($msg_index, $begin, $end-$begin); 
     609 
     610      // fetch reqested headers from server 
     611      $this->_fetch_headers($mailbox, join(",", $msg_index), $a_msg_headers, $cache_key); 
     612      } 
     613 
     614    // delete cached messages with a higher index than $max+1 
     615    // Changed $max to $max+1 to fix this bug : #1484295 
     616    $this->clear_message_cache($cache_key, $max + 1); 
     617 
     618    // kick child process to sync cache 
     619    // ... 
    624620 
    625621    // return empty array if no messages found 
    626     if (!is_array($a_msg_headers) || empty($a_msg_headers)) { 
     622    if (!is_array($a_msg_headers) || empty($a_msg_headers)) 
    627623      return array(); 
    628     } 
    629  
    630     // if not already sorted 
    631     if (!$headers_sorted) 
    632       { 
    633       // use this class for message sorting 
    634       $sorter = new rcube_header_sorter(); 
    635       $sorter->set_sequence_numbers($msg_index); 
    636       $sorter->sort_headers($a_msg_headers); 
    637  
    638       if ($this->sort_order == 'DESC') 
    639         $a_msg_headers = array_reverse($a_msg_headers); 
    640       } 
     624     
     625    // use this class for message sorting 
     626    $sorter = new rcube_header_sorter(); 
     627    $sorter->set_sequence_numbers($msg_index); 
     628    $sorter->sort_headers($a_msg_headers); 
     629 
     630    if ($this->sort_order == 'DESC') 
     631      $a_msg_headers = array_reverse($a_msg_headers);        
    641632 
    642633    return array_values($a_msg_headers); 
     
    662653    $msgs = $this->search_set; 
    663654    $a_msg_headers = array(); 
    664     $start_msg = ($this->list_page-1) * $this->page_size; 
     655    $page = $page ? $page : $this->list_page; 
     656    $start_msg = ($page-1) * $this->page_size; 
    665657 
    666658    $this->_set_sort_order($sort_field, $sort_order); 
     
    742734  function _get_message_range($max, $page) 
    743735    { 
    744     $start_msg = ($this->list_page-1) * $this->page_size; 
     736    $start_msg = ($page-1) * $this->page_size; 
    745737     
    746738    if ($page=='all') 
     
    766758    return array($begin, $end); 
    767759    } 
    768      
    769760     
    770761 
     
    777768   * @param  array   Reference to message headers array 
    778769   * @param  array   Array with cache index 
    779    * @return int     Number of deleted messages 
     770   * @return int     Messages count 
    780771   * @access private 
    781772   */ 
     
    785776    $cache_index = $this->get_message_cache_index($cache_key); 
    786777     
    787     // fetch reuested headers from server 
     778    // fetch reqested headers from server 
    788779    $a_header_index = iil_C_FetchHeaders($this->conn, $mailbox, $msgs, false, $this->fetch_add_headers); 
    789     $deleted_count = 0; 
    790780     
    791781    if (!empty($a_header_index)) 
    792782      { 
    793783      foreach ($a_header_index as $i => $headers) 
    794         { 
     784        {  
     785/* 
    795786        if ($headers->deleted && $this->skip_deleted) 
    796787          { 
     
    799790            $this->remove_message_cache($cache_key, $headers->uid); 
    800791 
    801           $deleted_count++; 
    802792          continue; 
    803793          } 
    804  
     794*/ 
    805795        // add message to cache 
    806796        if ($this->caching_enabled && $cache_index[$headers->id] != $headers->uid) 
     
    811801      } 
    812802         
    813     return $deleted_count; 
     803    return count($a_msg_headers); 
    814804    } 
    815805     
     
    847837      else 
    848838        { 
    849         $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, join(',', $this->search_set), $this->sort_field, false); 
     839        $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, join(',', $this->search_set), $this->sort_field, $this->skip_deleted); 
    850840 
    851841        if ($this->sort_order=="ASC") 
     
    875865    // fetch complete message index 
    876866    $msg_count = $this->_messagecount($mailbox); 
    877     if ($this->get_capability('sort') && ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, ''))) 
     867    if ($this->get_capability('sort') && ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 
    878868      { 
    879869      if ($this->sort_order == 'DESC') 
     
    884874    else 
    885875      { 
    886       $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:$msg_count", $this->sort_field); 
     876      $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:$msg_count", $this->sort_field, $this->skip_deleted); 
    887877 
    888878      if ($this->sort_order=="ASC") 
     
    905895    $cache_key = $mailbox.'.msg'; 
    906896    $cache_index = $this->get_message_cache_index($cache_key); 
    907     $msg_count = $this->_messagecount($mailbox); 
    908897 
    909898    // fetch complete message index 
    910     $a_message_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:$msg_count", 'UID'); 
     899    $a_message_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", 'UID', $this->skip_deleted); 
     900     
     901    if ($a_message_index === false) 
     902      return false; 
    911903         
    912904    foreach ($a_message_index as $id => $uid) 
     
    932924        } 
    933925         
    934  
    935       // fetch complete headers and add to cache 
    936       $headers = iil_C_FetchHeader($this->conn, $mailbox, $id, false, $this->fetch_add_headers); 
    937       $this->add_message_cache($cache_key, $headers->id, $headers); 
    938       } 
    939  
     926        $toupdate[] = $id; 
     927      } 
     928 
     929    // fetch complete headers and add to cache 
     930    if (!empty($toupdate)) { 
     931      if ($headers = iil_C_FetchHeader($this->conn, $mailbox, join(',', $toupdate), false, $this->fetch_add_headers)) 
     932        foreach ($headers as $header) 
     933          $this->add_message_cache($cache_key, $header->id, $header); 
     934      } 
     935     
    940936    // those ids that are still in cache_index have been deleted       
    941937    if (!empty($cache_index)) 
     
    10071003  function _search_index($mailbox, $criteria='ALL', $charset=NULL, $sort_field=NULL) 
    10081004    { 
     1005    $orig_criteria = $criteria; 
     1006 
    10091007    if ($this->skip_deleted && !preg_match('/UNDELETED/', $criteria)) 
    10101008      $criteria = 'UNDELETED '.$criteria; 
     
    10251023          unset($a_messages[$i]); 
    10261024      } 
     1025     
     1026    // update messagecount cache ? 
     1027//    $a_mailbox_cache = get_cache('messagecount'); 
     1028//    $a_mailbox_cache[$mailbox][$criteria] = sizeof($a_messages); 
     1029//    $this->update_cache('messagecount', $a_mailbox_cache); 
    10271030         
    10281031    return $a_messages; 
     
    22202223   */ 
    22212224  function check_cache_status($mailbox, $cache_key) 
    2222     { 
     2225  { 
    22232226    if (!$this->caching_enabled) 
    22242227      return -3; 
     
    22302233    // console("Cache check: $msg_count !== ".count($cache_index)); 
    22312234 
    2232     if ($cache_count==$msg_count) 
    2233       { 
    2234       // get highest index 
    2235       $header = iil_C_FetchHeader($this->conn, $mailbox, "$msg_count", false, $this->fetch_add_headers); 
    2236       $cache_uid = array_pop($cache_index); 
     2235    if ($cache_count==$msg_count) { 
     2236      if ($this->skip_deleted) { 
     2237        $h_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", 'UID', $this->skip_deleted); 
     2238 
     2239        if (sizeof($h_index) == $cache_count) { 
     2240          $cache_index = array_flip($cache_index); 
     2241          foreach ($h_index as $idx => $uid) 
     2242            unset($cache_index[$uid]); 
     2243 
     2244          if (empty($cache_index)) 
     2245            return 1; 
     2246        } 
     2247        return -2; 
     2248      } else { 
     2249        // get highest index 
     2250        $header = iil_C_FetchHeader($this->conn, $mailbox, "$msg_count"); 
     2251        $cache_uid = array_pop($cache_index); 
    22372252       
    2238       // uids of highest message matches -> cache seems OK 
    2239       if ($cache_uid == $header->uid) 
    2240         return 1; 
    2241  
     2253        // uids of highest message matches -> cache seems OK 
     2254        if ($cache_uid == $header->uid) 
     2255          return 1; 
     2256      } 
    22422257      // cache is dirty 
    22432258      return -1; 
    2244       } 
     2259    } 
    22452260    // if cache count differs less than 10% report as dirty 
    22462261    else if (abs($msg_count - $cache_count) < $msg_count/10) 
     
    22482263    else 
    22492264      return -2; 
    2250     } 
     2265  } 
    22512266 
    22522267  /** 
  • program/lib/imap.inc

    r07f0b94 r2dd7ee3  
    8585                - added UID EXPUNGE support 
    8686                - fixed problem with double quotes and spaces in folder names in LIST and LSUB  
     87                - rewritten iil_C_FetchHeaderIndex() 
    8788 
    8889********************************************************/ 
     
    936937} 
    937938 
    938 function iil_C_FetchHeaderIndex(&$conn, $mailbox, $message_set, $index_field, 
    939     $normalize=true) { 
    940         global $IMAP_USE_INTERNAL_DATE; 
    941          
    942         $c=0; 
    943         $result=array(); 
    944         $fp = $conn->fp; 
    945                  
    946         if (empty($index_field)) { 
    947             $index_field = 'DATE'; 
    948         } 
    949         $index_field = strtoupper($index_field); 
    950          
     939function iil_C_FetchHeaderIndex(&$conn, $mailbox, $message_set, $index_field='', $skip_deleted=true) { 
     940 
    951941        list($from_idx, $to_idx) = explode(':', $message_set); 
    952         if (empty($message_set) || (isset($to_idx) 
    953             && (int)$from_idx > (int)$to_idx)) { 
     942        if (empty($message_set) || 
     943                (isset($to_idx) && $to_idx != '*' && (int)$from_idx > (int)$to_idx)) { 
    954944                return false; 
    955945        } 
    956          
    957         //$fields_a['DATE'] = ($IMAP_USE_INTERNAL_DATE?6:1); 
     946 
     947        $index_field = empty($index_field) ? 'DATE' : strtoupper($index_field); 
     948         
    958949        $fields_a['DATE']         = 1; 
    959         $fields_a['INTERNALDATE'] = 6; 
     950        $fields_a['INTERNALDATE'] = 4; 
    960951        $fields_a['FROM']         = 1; 
    961952        $fields_a['REPLY-TO']     = 1; 
     
    966957        $fields_a['SIZE']         = 2; 
    967958        $fields_a['SEEN']         = 3; 
    968         $fields_a['RECENT']       = 4; 
    969         $fields_a['DELETED']      = 5; 
    970          
    971         $mode=$fields_a[$index_field]; 
    972         if (!($mode > 0)) { 
    973             return false; 
    974         } 
    975      
     959        $fields_a['RECENT']       = 3; 
     960        $fields_a['DELETED']      = 3; 
     961 
     962        if (!($mode = $fields_a[$index_field])) { 
     963                return false; 
     964        } 
     965 
    976966        /*  Do "SELECT" command */ 
    977967        if (!iil_C_Select($conn, $mailbox)) { 
    978             return false; 
    979         } 
    980      
    981         /* FETCH date,from,subject headers */ 
    982         if ($mode == 1) { 
    983                 $key     = 'fhi' . ($c++); 
    984                 $request = $key . " FETCH $message_set (BODY.PEEK[HEADER.FIELDS ($index_field)])"; 
    985                 if (!iil_PutLine($fp, $request)) { 
    986                     return false; 
    987                 } 
    988                 do { 
    989                          
    990                         $line=chop(iil_ReadLine($fp, 200)); 
    991                         $a=explode(' ', $line); 
    992                         if (($line[0] == '*') && ($a[2] == 'FETCH') 
    993                             && ($line[strlen($line)-1] != ')')) { 
    994                                 $id=$a[1]; 
    995  
    996                                 $str=$line=chop(iil_ReadLine($fp, 300)); 
    997  
    998                                 while ($line[0] != ')') {                                       //caution, this line works only in this particular case 
    999                                         $line=chop(iil_ReadLine($fp, 300)); 
    1000                                         if ($line[0] != ')') { 
    1001                                                 if (ord($line[0]) <= 32) {                      //continuation from previous header line 
    1002                                                         $str.= ' ' . trim($line); 
    1003                                                 } 
    1004                                                 if ((ord($line[0]) > 32) || (strlen($line[0]) == 0)) { 
    1005                                                         list($field, $string) = iil_SplitHeaderLine($str); 
    1006                                                         if (strcasecmp($field, 'date') == 0) { 
    1007                                                                 $result[$id] = iil_StrToTime($string); 
    1008                                                         } else { 
    1009                                                                 $result[$id] = str_replace('"', '', $string); 
    1010                                                                 if ($normalize) { 
    1011                                                                     $result[$id] = strtoupper($result[$id]); 
    1012                                                                 } 
    1013                                                         } 
    1014                                                         $str=$line; 
    1015                                                 } 
    1016                                         } 
     968                return false; 
     969        } 
     970         
     971        // build FETCH command string 
     972        $key     = 'fhi0'; 
     973        $deleted = $skip_deleted ? ' FLAGS' : ''; 
     974 
     975        if ($mode == 1) 
     976                $request = " FETCH $message_set (BODY.PEEK[HEADER.FIELDS ($index_field)]$deleted)"; 
     977        else if ($mode == 2) { 
     978                if ($index_field == 'SIZE') 
     979                        $request = " FETCH $message_set (RFC822.SIZE$deleted)"; 
     980                else 
     981                        $request = " FETCH $message_set ($index_field$deleted)"; 
     982        } else if ($mode == 3) 
     983                $request = " FETCH $message_set (FLAGS)"; 
     984        else // 4 
     985                $request = " FETCH $message_set (INTERNALDATE$deleted)"; 
     986 
     987        $request = $key . $request; 
     988 
     989        if (!iil_PutLine($conn->fp, $request)) 
     990                return false; 
     991 
     992        $result = array(); 
     993 
     994        do { 
     995                $line = chop(iil_ReadLine($conn->fp, 200)); 
     996                $line = iil_MultLine($conn->fp, $line); 
     997 
     998                if (preg_match('/^\* ([0-9]+) FETCH/', $line, $m)) { 
     999 
     1000                        $id = $m[1]; 
     1001                        $flags = NULL; 
     1002                                         
     1003                        if ($skip_deleted && preg_match('/FLAGS \(([^)]+)\)/', $line, $matches)) { 
     1004                                $flags = explode(' ', strtoupper($matches[1])); 
     1005                                if (in_array('\\DELETED', $flags)) { 
     1006                                        $deleted[$id] = $id; 
     1007                                        continue; 
    10171008                                } 
    10181009                        } 
    1019                         /* 
    1020                         $end_pos = strlen($line)-1; 
    1021                         if (($line[0]=="*") && ($a[2]=="FETCH") && ($line[$end_pos]=="}")) { 
    1022                                 $id = $a[1]; 
    1023                                 $pos = strrpos($line, "{")+1; 
    1024                                 $bytes = (int)substr($line, $pos, $end_pos-$pos); 
    1025                                 $received = 0; 
    1026                                 do { 
    1027                                         $line      = iil_ReadLine($fp, 0); 
    1028                                         $received += strlen($line); 
    1029                                         $line      = chop($line); 
    1030                                          
    1031                                         if ($received>$bytes) { 
    1032                                                 break; 
    1033                                         } else if (!$line) { 
    1034                                                 continue; 
     1010 
     1011                        if ($mode == 1) { 
     1012                                if (preg_match('/BODY\[HEADER\.FIELDS \((DATE|FROM|REPLY-TO|SENDER|TO|SUBJECT)\)\] (.*)/', $line, $matches)) { 
     1013                                        $value = preg_replace(array('/^"*[a-z]+:/i', '/\s+$/sm'), array('', ''), $matches[2]); 
     1014                                        $value = trim($value); 
     1015                                        if ($index_field == 'DATE') { 
     1016                                                $result[$id] = iil_StrToTime($value); 
     1017                                        } else { 
     1018                                                $result[$id] = $value; 
    10351019                                        } 
    1036  
    1037                                         list($field, $string) = explode(': ', $line); 
    1038                                          
    1039                                         if (strcasecmp($field, 'date') == 0) { 
    1040                                                 $result[$id] = iil_StrToTime($string); 
    1041                                         } else if ($index_field != 'DATE') { 
    1042                                                 $result[$id]=strtoupper(str_replace('"', '', $string)); 
    1043                                         } 
    1044                                 } while ($line[0] != ')'); 
    1045                         } else { 
    1046                                 //one line response, not expected so ignore                              
    1047                         } 
    1048                         */ 
    1049                 } while (!iil_StartsWith($line, $key, true)); 
    1050  
    1051         }else if ($mode == 6) { 
    1052  
    1053                 $key     = 'fhi' . ($c++); 
    1054                 $request = $key . " FETCH $message_set (INTERNALDATE)"; 
    1055                 if (!iil_PutLine($fp, $request)) { 
    1056                     return false; 
    1057                 } 
    1058                 do { 
    1059                         $line=chop(iil_ReadLine($fp, 200)); 
    1060                         if ($line[0] == '*') { 
    1061                                 /* 
    1062                                  * original: 
    1063                                  * "* 10 FETCH (INTERNALDATE "31-Jul-2002 09:18:02 -0500")" 
    1064                                  */ 
    1065                                 $paren_pos = strpos($line, '('); 
    1066                                 $foo       = substr($line, 0, $paren_pos); 
    1067                                 $a         = explode(' ', $foo); 
    1068                                 $id        = $a[1]; 
    1069                                  
    1070                                 $open_pos  = strpos($line, '"') + 1; 
    1071                                 $close_pos = strrpos($line, '"'); 
    1072                                 if ($open_pos && $close_pos) { 
    1073                                         $len         = $close_pos - $open_pos; 
    1074                                         $time_str    = substr($line, $open_pos, $len); 
    1075                                         $result[$id] = strtotime($time_str); 
     1020                                } else { 
     1021                                        $result[$id] = ''; 
    10761022                                } 
    1077                         } else { 
    1078                                 $a = explode(' ', $line); 
    1079                         } 
    1080                 } while (!iil_StartsWith($a[0], $key, true)); 
    1081         } else { 
    1082                 if ($mode >= 3) { 
    1083                     $field_name = 'FLAGS'; 
    1084                 } else if ($index_field == 'SIZE') { 
    1085                     $field_name = 'RFC822.SIZE'; 
    1086                 } else { 
    1087                     $field_name = $index_field; 
    1088                 } 
    1089          
    1090                 /*                      FETCH uid, size, flags          */ 
    1091                 $key     = 'fhi' .($c++); 
    1092                 $request = $key . " FETCH $message_set ($field_name)"; 
    1093  
    1094                 if (!iil_PutLine($fp, $request)) { 
    1095                     return false; 
    1096                 } 
    1097                 do { 
    1098                         $line=chop(iil_ReadLine($fp, 200)); 
    1099                         $a = explode(' ', $line); 
    1100                         if (($line[0] == '*') && ($a[2] == 'FETCH')) { 
    1101                                 $line = str_replace('(', '', $line); 
    1102                                 $line = str_replace(')', '', $line); 
    1103                                 $a    = explode(' ', $line); 
    1104                                  
    1105                                 $id = $a[1]; 
    1106  
    1107                                 if (isset($result[$id])) { 
    1108                                     continue; //if we already got the data, skip forward 
     1023                        } else if ($mode == 2) { 
     1024                                if (preg_match('/\((UID|RFC822\.SIZE) ([0-9]+)/', $line, $matches)) { 
     1025                                        $result[$id] = trim($matches[2]); 
     1026                                } else { 
     1027                                        $result[$id] = 0; 
    11091028                                } 
    1110                                 if ($a[3]!=$field_name) { 
    1111                                         continue;  //make sure it's returning what we requested 
     1029                        } else if ($mode == 3) { 
     1030                                if (!$flags && preg_match('/FLAGS \(([^)]+)\)/', $line, $matches)) { 
     1031                                        $flags = explode(' ', $matches[1]); 
    11121032                                } 
    1113                  
    1114                                 /*  Caution, bad assumptions, next several lines */ 
    1115                                 if ($mode == 2) { 
    1116                                     $result[$id] = $a[4]; 
     1033                                $result[$id] = in_array('\\'.$index_field, $flags) ? 1 : 0; 
     1034                        } else if ($mode == 4) { 
     1035                                if (preg_match('/INTERNALDATE "([^"]+)"/', $line, $matches)) { 
     1036                                        $result[$id] = strtotime($matches[1]); 
    11171037                                } else { 
    1118                                         $haystack    = strtoupper($line); 
    1119                                         $result[$id] = (strpos($haystack, $index_field) > 0 ? "F" : "N"); 
     1038                                        $result[$id] = 0; 
    11201039                                } 
    11211040                        } 
    1122                 } while (!iil_StartsWith($line, $key, true)); 
    1123         } 
    1124  
     1041                } 
     1042        } while (!iil_StartsWith($line, $key, true)); 
     1043 
     1044/* 
    11251045        //check number of elements... 
    1126         list($start_mid, $end_mid) = explode(':', $message_set); 
    1127         if (is_numeric($start_mid) && is_numeric($end_mid)) { 
     1046        if (is_numeric($from_idx) && is_numeric($to_idx)) { 
    11281047                //count how many we should have 
    1129                 $should_have = $end_mid - $start_mid +1; 
     1048                $should_have = $to_idx - $from_idx + 1; 
    11301049                 
    11311050                //if we have less, try and fill in the "gaps" 
    11321051                if (count($result) < $should_have) { 
    1133                         for ($i=$start_mid; $i<=$end_mid; $i++) { 
     1052                        for ($i=$from_idx; $i<=$to_idx; $i++) { 
    11341053                                if (!isset($result[$i])) { 
    11351054                                        $result[$i] = ''; 
     
    11381057                } 
    11391058        } 
     1059*/ 
    11401060        return $result;  
    11411061} 
     
    15211441        $fp     = $conn->fp; 
    15221442         
    1523         list($from_idx, $to_idx) = explode(':', $message_set); 
    1524         if (empty($message_set) || (isset($to_idx) 
    1525                 && (int)$from_idx > (int)$to_idx)) { 
    1526                 return false; 
    1527         } 
    1528                  
    15291443        /*  Do "SELECT" command */ 
    15301444        if (!iil_C_Select($conn, $mailbox)) { 
     
    15321446                return false; 
    15331447        } 
     1448 
     1449        $message_set = iil_CompressMessageSet($message_set); 
    15341450 
    15351451        if ($add) 
  • program/steps/mail/show.inc

    ra25d396 r2dd7ee3  
    9999    $next = $prev = $first = $last = -1; 
    100100 
    101     if ((!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') && 
    102       $IMAP->get_capability('sort')) || !empty($_REQUEST['_search'])) 
    103       { 
    104       // Only if we use custom sorting 
    105       $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']); 
    106  
    107       $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index); 
    108  
    109       $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ; 
    110       $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1; 
    111       $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ; 
    112       $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1; 
    113       } 
    114     else 
     101    if ($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] != 'DESC' 
     102        && empty($_REQUEST['_search']) && !$IMAP->skip_deleted) 
    115103      { 
    116104      // this assumes that we are sorted by date_DESC 
     
    123111      $next = $IMAP->get_uid($seq - 1); 
    124112      $last = $IMAP->get_uid(1); 
     113      } 
     114    else  
     115      { 
     116      // Only if we use custom sorting 
     117      $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']); 
     118 
     119      $MESSAGE->index = array_search($IMAP->get_id($MESSAGE->uid), $a_msg_index); 
     120 
     121      $prev = isset($a_msg_index[$MESSAGE->index-1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index-1]) : -1 ; 
     122      $first = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[0]) : -1; 
     123      $next = isset($a_msg_index[$MESSAGE->index+1]) ? $IMAP->get_uid($a_msg_index[$MESSAGE->index+1]) : -1 ; 
     124      $last = count($a_msg_index)>0 ? $IMAP->get_uid($a_msg_index[count($a_msg_index)-1]) : -1; 
    125125      } 
    126126 
Note: See TracChangeset for help on using the changeset viewer.