Exemplo n.º 1
0
 /**
  * Copy of rcube_imap::search_index()
  */
 protected function search_index()
 {
     $criteria = $this->search;
     $charset = $this->charset;
     $imap = $this->worker->get_imap();
     if (!$imap->connected()) {
         trigger_error("No IMAP connection for {$this->folder}", E_USER_WARNING);
         if ($this->threading) {
             return new rcube_result_thread($this->folder);
         } else {
             return new rcube_result_index($this->folder);
         }
     }
     if ($this->worker->options['skip_deleted'] && !preg_match('/UNDELETED/', $criteria)) {
         $criteria = 'UNDELETED ' . $criteria;
     }
     // unset CHARSET if criteria string is ASCII, this way
     // SEARCH won't be re-sent after "unsupported charset" response
     if ($charset && $charset != 'US-ASCII' && is_ascii($criteria)) {
         $charset = 'US-ASCII';
     }
     if ($this->threading) {
         $threads = $imap->thread($this->folder, $this->threading, $criteria, true, $charset);
         // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8,
         // but I've seen that Courier doesn't support UTF-8)
         if ($threads->is_error() && $charset && $charset != 'US-ASCII') {
             $threads = $imap->thread($this->folder, $this->threading, rcube_imap::convert_criteria($criteria, $charset), true, 'US-ASCII');
         }
         return $threads;
     }
     if ($this->sort_field) {
         $messages = $imap->sort($this->folder, $this->sort_field, $criteria, true, $charset);
         // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8,
         // but I've seen Courier with disabled UTF-8 support)
         if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
             $messages = $imap->sort($this->folder, $this->sort_field, rcube_imap::convert_criteria($criteria, $charset), true, 'US-ASCII');
         }
     }
     if (!$messages || $messages->is_error()) {
         $messages = $imap->search($this->folder, ($charset && $charset != 'US-ASCII' ? "CHARSET {$charset} " : '') . $criteria, true);
         // Error, try with US-ASCII (some servers may support only US-ASCII)
         if ($messages->is_error() && $charset && $charset != 'US-ASCII') {
             $messages = $imap->search($this->folder, rcube_imap::convert_criteria($criteria, $charset), true);
         }
     }
     return $messages;
 }