Ignore:
Timestamp:
Mar 4, 2010 2:39:53 AM (3 years ago)
Author:
thomasb
Message:

Changed signature separator when top-posting (#1486330)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_imap.php

    r3309 r3315  
    600600        if ($this->skip_deleted) { 
    601601          // @TODO: this could be cached 
    602           if ($msg_index = $this->_search_index($mailbox, 'ALL UNDELETED')) { 
     602          if ($msg_index = $this->_search_index($mailbox, 'ALL UNDELETED')) { 
    603603            $max = max($msg_index); 
    604604            list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 
    605605            $msg_index = array_slice($msg_index, $begin, $end-$begin); 
    606             } 
    607         } else if ($max = iil_C_CountMessages($this->conn, $mailbox)) { 
     606          } 
     607        } 
     608        else if ($max = iil_C_CountMessages($this->conn, $mailbox)) { 
    608609          list($begin, $end) = $this->_get_message_range($max, $page); 
    609           $msg_index = range($begin+1, $end); 
    610         } else 
    611           $msg_index = array(); 
     610          $msg_index = range($begin+1, $end); 
     611        } 
     612        else 
     613          $msg_index = array(); 
    612614 
    613615        if ($slice) 
     
    615617 
    616618        // fetch reqested headers from server 
    617         if ($msg_index) 
     619        if ($msg_index) 
    618620          $this->_fetch_headers($mailbox, join(",", $msg_index), $a_msg_headers, $cache_key); 
    619621      } 
     
    750752      if (($cnt > 300 && $cnt > $this->page_size) || ($this->index_sort && $this->sort_field == 'date')) { 
    751753        // use memory less expensive (and quick) method for big result set 
    752         $a_index = $this->message_index('', $this->sort_field, $this->sort_order); 
     754        $a_index = $this->message_index('', $this->sort_field, $this->sort_order); 
    753755        // get messages uids for one page... 
    754756        $msgs = array_slice($a_index, $start_msg, min($cnt-$start_msg, $this->page_size)); 
    755757        if ($slice) 
    756758          $msgs = array_slice($msgs, -$slice, $slice); 
    757         // ...and fetch headers 
     759        // ...and fetch headers 
    758760        $this->_fetch_headers($mailbox, join(',', $msgs), $a_msg_headers, NULL); 
    759761 
     
    767769 
    768770        return array_values($a_msg_headers); 
    769         } 
     771      } 
    770772      else { 
    771773        // for small result set we can fetch all messages headers 
     
    780782 
    781783        // only return the requested part of the set 
    782         $a_msg_headers = array_slice(array_values($a_msg_headers), $start_msg, min($cnt-$start_msg, $this->page_size)); 
     784        $a_msg_headers = array_slice(array_values($a_msg_headers), $start_msg, min($cnt-$start_msg, $this->page_size)); 
    783785        if ($slice) 
    784786          $a_msg_headers = array_slice($a_msg_headers, -$slice, $slice); 
     
    849851      foreach ($a_header_index as $i => $headers) { 
    850852        if ($this->caching_enabled && $cache_index[$headers->id] != $headers->uid) { 
    851           // prevent index duplicates 
    852           if ($cache_index[$headers->id]) { 
    853             $this->remove_message_cache($cache_key, $headers->id, true); 
    854             unset($cache_index[$headers->id]); 
    855             } 
     853          // prevent index duplicates 
     854          if ($cache_index[$headers->id]) { 
     855            $this->remove_message_cache($cache_key, $headers->id, true); 
     856            unset($cache_index[$headers->id]); 
     857          } 
    856858          // add message to cache 
    857           $this->add_message_cache($cache_key, $headers->id, $headers, NULL, 
    858             !in_array($headers->uid, $cache_index)); 
    859           } 
     859          $this->add_message_cache($cache_key, $headers->id, $headers, NULL, 
     860            !in_array($headers->uid, $cache_index)); 
     861        } 
    860862 
    861863        $a_msg_headers[$headers->uid] = $headers; 
     
    913915      // use message index sort for sorting by Date 
    914916      if ($this->index_sort && $this->sort_field == 'date') 
    915         { 
    916         $msgs = $this->search_set; 
    917          
    918         if ($this->search_sort_field != 'date') 
    919           sort($msgs); 
    920          
     917      { 
     918        $msgs = $this->search_set; 
     919 
     920        if ($this->search_sort_field != 'date') 
     921          sort($msgs); 
     922 
    921923        if ($this->sort_order == 'DESC') 
    922924          $this->cache[$key] = array_reverse($msgs); 
    923925        else 
    924926          $this->cache[$key] = $msgs; 
    925         } 
     927      } 
    926928      // sort with SORT command 
    927929      else if ($this->get_capability('sort')) 
    928         { 
     930      { 
    929931        if ($this->sort_field && $this->search_sort_field != $this->sort_field) 
    930932          $this->search('', $this->search_string, $this->search_charset, $this->sort_field); 
     
    934936        else 
    935937          $this->cache[$key] = $this->search_set; 
    936         } 
     938      } 
    937939      else 
    938         { 
     940      { 
    939941        $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, join(',', $this->search_set), $this->sort_field, $this->skip_deleted); 
    940942 
     
    945947 
    946948        $this->cache[$key] = array_keys($a_index); 
    947         } 
     949      } 
    948950    } 
    949951 
     
    10331035      if (isset($cache_index[$id])) 
    10341036        { 
    1035         $for_remove[] = $cache_index[$id]; 
     1037        $for_remove[] = $cache_index[$id]; 
    10361038        unset($cache_index[$id]); 
    10371039        } 
    10381040         
    1039         $for_update[] = $id; 
     1041        $for_update[] = $id; 
    10401042      } 
    10411043 
     
    10521054        foreach ($headers as $header) 
    10531055          $this->add_message_cache($cache_key, $header->id, $header, NULL, 
    1054                 in_array($header->uid, (array)$for_remove)); 
     1056            in_array($header->uid, (array)$for_remove)); 
    10551057      } 
    10561058    } 
     
    10791081    // only if UTF-8 search is not supported 
    10801082    if (empty($results) && !is_array($results) && !empty($charset) && $charset != 'US-ASCII') 
    1081       { 
    1082         // convert strings to US_ASCII 
    1083         if(preg_match_all('/\{([0-9]+)\}\r\n/', $str, $matches, PREG_OFFSET_CAPTURE)) 
    1084           { 
    1085           $last = 0; $res = ''; 
    1086           foreach($matches[1] as $m) 
    1087             { 
    1088             $string_offset = $m[1] + strlen($m[0]) + 4; // {}\r\n 
    1089             $string = substr($str, $string_offset - 1, $m[0]); 
    1090             $string = rcube_charset_convert($string, $charset, 'US-ASCII'); 
    1091             if (!$string) continue; 
    1092             $res .= sprintf("%s{%d}\r\n%s", substr($str, $last, $m[1] - $last - 1), strlen($string), $string); 
    1093             $last = $m[0] + $string_offset - 1; 
    1094             } 
    1095             if ($last < strlen($str)) 
    1096               $res .= substr($str, $last, strlen($str)-$last); 
    1097           } 
    1098         else // strings for conversion not found 
    1099           $res = $str; 
    1100            
    1101         $results = $this->search($mbox_name, $res, NULL, $sort_field); 
    1102       } 
     1083    { 
     1084      // convert strings to US_ASCII 
     1085      if(preg_match_all('/\{([0-9]+)\}\r\n/', $str, $matches, PREG_OFFSET_CAPTURE)) 
     1086      { 
     1087        $last = 0; $res = ''; 
     1088        foreach($matches[1] as $m) 
     1089        { 
     1090          $string_offset = $m[1] + strlen($m[0]) + 4; // {}\r\n 
     1091          $string = substr($str, $string_offset - 1, $m[0]); 
     1092          $string = rcube_charset_convert($string, $charset, 'US-ASCII'); 
     1093          if (!$string) continue; 
     1094          $res .= sprintf("%s{%d}\r\n%s", substr($str, $last, $m[1] - $last - 1), strlen($string), $string); 
     1095          $last = $m[0] + $string_offset - 1; 
     1096        } 
     1097        if ($last < strlen($str)) 
     1098          $res .= substr($str, $last, strlen($str)-$last); 
     1099      } 
     1100      else // strings for conversion not found 
     1101      $res = $str; 
     1102 
     1103      $results = $this->search($mbox_name, $res, NULL, $sort_field); 
     1104    } 
    11031105 
    11041106    $this->set_search_set($str, $results, $charset, $sort_field); 
     
    12501252      // ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 2154 70 NIL NIL NIL) 
    12511253      if ($headers->ctype && $headers->ctype != 'text/plain' 
    1252           && $structure[0] == 'text' && $structure[1] == 'plain') { 
    1253         return false;   
    1254         } 
     1254          && $structure[0] == 'text' && $structure[1] == 'plain') { 
     1255        return false; 
     1256      } 
    12551257 
    12561258      $struct = &$this->_structure_part($structure); 
     
    13031305        if (is_array($part[$i]) && count($part[$i]) > 3) { 
    13041306          // fetch message headers if message/rfc822 or named part (could contain Content-Location header) 
    1305           if (!is_array($part[$i][0])) { 
     1307          if (!is_array($part[$i][0])) { 
    13061308            $tmp_part_id = $struct->mime_id ? $struct->mime_id.'.'.($i+1) : $i+1; 
    13071309            if (strtolower($part[$i][0]) == 'message' && strtolower($part[$i][1]) == 'rfc822') { 
    1308               $raw_part_headers[] = $tmp_part_id; 
    1309               $mime_part_headers[] = $tmp_part_id; 
    1310               } 
     1310              $raw_part_headers[] = $tmp_part_id; 
     1311              $mime_part_headers[] = $tmp_part_id; 
     1312            } 
    13111313            else if (in_array('name', (array)$part[$i][2]) && (empty($part[$i][3]) || $part[$i][3]=='NIL')) { 
    1312               $mime_part_headers[] = $tmp_part_id; 
    1313               } 
     1314              $mime_part_headers[] = $tmp_part_id; 
    13141315            } 
    13151316          } 
     1317        } 
    13161318         
    13171319      // pre-fetch headers of all parts (in one command for better performance) 
     
    13311333          $tmp_part_id = $struct->mime_id ? $struct->mime_id.'.'.($i+1) : $i+1; 
    13321334          $struct->parts[] = $this->_structure_part($part[$i], ++$count, $struct->mime_id, 
    1333             $mime_part_headers[$tmp_part_id], $raw_part_headers[$tmp_part_id]); 
    1334         } 
     1335            $mime_part_headers[$tmp_part_id], $raw_part_headers[$tmp_part_id]); 
     1336        } 
    13351337 
    13361338      return $struct; 
     
    14531455      // we must fetch and parse headers "manually" 
    14541456      if ($i<2) { 
    1455         if (!$headers) 
     1457        if (!$headers) 
    14561458          $headers = iil_C_FetchPartHeader($this->conn, $this->mailbox, $this->_msg_id, false, $part->mime_id); 
    14571459        $filename_mime = ''; 
     
    14701472      } 
    14711473      if ($i<2) { 
    1472         if (!$headers) 
     1474        if (!$headers) 
    14731475          $headers = iil_C_FetchPartHeader($this->conn, $this->mailbox, $this->_msg_id, false, $part->mime_id); 
    14741476        $filename_encoded = ''; 
     
    14871489      } 
    14881490      if ($i<2) { 
    1489         if (!$headers) 
     1491        if (!$headers) 
    14901492          $headers = iil_C_FetchPartHeader($this->conn, $this->mailbox, $this->_msg_id, false, $part->mime_id); 
    14911493        $filename_mime = ''; 
     
    15041506      } 
    15051507      if ($i<2) { 
    1506         if (!$headers) 
     1508        if (!$headers) 
    15071509          $headers = iil_C_FetchPartHeader($this->conn, $this->mailbox, $this->_msg_id, false, $part->mime_id); 
    15081510        $filename_encoded = ''; 
     
    15261528    if (!empty($filename_mime)) { 
    15271529      $part->filename = rcube_imap::decode_mime_string($filename_mime,  
    1528         $part->charset ? $part->charset : $this->struct_charset ? $this->struct_charset : 
    1529             rc_detect_encoding($filename_mime, $this->default_charset)); 
     1530        $part->charset ? $part->charset : ($this->struct_charset ? $this->struct_charset : 
     1531          rc_detect_encoding($filename_mime, $this->default_charset))); 
    15301532      }  
    15311533    else if (!empty($filename_encoded)) { 
     
    15501552    { 
    15511553      while (is_array($structure)) { 
    1552         if (is_array($structure[2]) && $structure[2][0] == 'charset') 
    1553           return $structure[2][1]; 
    1554         $structure = $structure[0]; 
    1555         } 
     1554        if (is_array($structure[2]) && $structure[2][0] == 'charset') 
     1555          return $structure[2][1]; 
     1556        $structure = $structure[0]; 
     1557      } 
    15561558    }  
    15571559 
Note: See TracChangeset for help on using the changeset viewer.