previousSearch() public method

Use the results from the previous SEARCH command. The IMAP server must support the SEARCHRES extension (RFC 5182) for this query to be used.
public previousSearch ( boolean $not = false, array $opts = [] )
$not boolean If true, don't match the previous query.
$opts array Additional options: - fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Exemplo n.º 1
0
 /**
  * @dataProvider previousSearchQueryProvider
  */
 public function testPreviousSearchQuery($not, $fuzzy, $expected)
 {
     $ob = new Horde_Imap_Client_Search_Query();
     $ob->previousSearch($not, array('fuzzy' => $fuzzy));
     $this->assertEquals($expected, $fuzzy ? $this->_fuzzy($ob, array('ESEARCH', 'SEARCHRES')) : strval($ob));
 }
Exemplo n.º 2
0
 /**
  */
 protected function _expunge($options)
 {
     $unflag = array();
     $mailbox = clone $this->_selected;
     $s_res = null;
     $uidplus = $this->queryCapability('UIDPLUS');
     $use_cache = $this->_initCache(true);
     if ($options['ids']->all) {
         $uid_string = strval($options['ids']);
     } elseif ($uidplus) {
         /* UID EXPUNGE command needs UIDs. */
         if ($options['ids']->sequence) {
             $results = array(Horde_Imap_Client::SEARCH_RESULTS_MATCH);
             if ($this->queryCapability('SEARCHRES')) {
                 $results[] = Horde_Imap_Client::SEARCH_RESULTS_SAVE;
             }
             $s_res = $this->search($mailbox, null, array('results' => $results));
             $uid_string = in_array(Horde_Imap_Client::SEARCH_RESULTS_SAVE, $results) && !empty($s_res['save']) ? '$' : strval($s_res['match']);
         } else {
             $uid_string = strval($options['ids']);
         }
     } else {
         /* Without UIDPLUS, need to temporarily unflag all messages marked
          * as deleted but not a part of requested IDs to delete. Use NOT
          * searches to accomplish this goal. */
         $search_query = new Horde_Imap_Client_Search_Query();
         $search_query->flag(Horde_Imap_Client::FLAG_DELETED, true);
         if ($options['ids']->search_res) {
             $search_query->previousSearch(true);
         } else {
             $search_query->ids($options['ids'], true);
         }
         $res = $this->search($mailbox, $search_query);
         $this->store($mailbox, array('ids' => $res['match'], 'remove' => array(Horde_Imap_Client::FLAG_DELETED)));
         $unflag = $res['match'];
     }
     $list_msgs = !empty($options['list']);
     $tmp =& $this->_temp;
     $tmp['expunge'] = $tmp['vanished'] = array();
     /* We need to get sequence num -> UID lookup table if we are caching.
      * There is no guarantee that if we are using QRESYNC that we will get
      * VANISHED responses, so this is unfortunately necessary. */
     if (is_null($s_res) && ($list_msgs || $use_cache)) {
         $s_res = $uidplus ? $this->_getSeqUidLookup($options['ids'], true) : $this->_getSeqUidLookup($this->getIdsOb(Horde_Imap_Client_Ids::ALL, true));
     }
     /* Always use UID EXPUNGE if available. */
     if ($uidplus) {
         $cmd = $this->_clientCommand(array('UID', 'EXPUNGE', $uid_string));
         $this->_sendLine($cmd);
     } elseif ($use_cache || $list_msgs) {
         $this->_sendLine($this->_clientCommand('EXPUNGE'));
     } else {
         /* This is faster than an EXPUNGE because the server will not
          * return untagged EXPUNGE responses. We can only do this if
          * we are not updating cache information. */
         $this->close(array('expunge' => true));
     }
     if (!empty($unflag)) {
         $this->store($mailbox, array('add' => array(Horde_Imap_Client::FLAG_DELETED), 'ids' => $unflag));
     }
     if (!$use_cache && !$list_msgs) {
         return null;
     }
     $expunged = array();
     if (!empty($tmp['vanished'])) {
         $expunged = $tmp['vanished']->ids;
     } elseif (!empty($tmp['expunge'])) {
         $lookup = $s_res['lookup'];
         /* Expunge responses can come in any order. Thus, we need to
          * reindex anytime we have an index that appears equal to or
          * after a previously seen index. If an IMAP server is smart,
          * it will expunge in reverse order instead. */
         foreach ($tmp['expunge'] as &$val) {
             $found = false;
             $tmp2 = array();
             foreach (array_keys($lookup) as $i => $seq) {
                 if ($found) {
                     $tmp2[$seq - 1] = $lookup[$seq];
                 } elseif ($seq == $val) {
                     $expunged[] = $lookup[$seq];
                     $tmp2 = array_slice($lookup, 0, $i, true);
                     $found = true;
                 }
             }
             $lookup = $tmp2;
         }
     }
     if (empty($expunged)) {
         return null;
     }
     if ($use_cache) {
         $this->_deleteMsgs($mailbox, $expunged);
     }
     /* Update MODSEQ if active for mailbox (QRESYNC only; CONDSTORE
      * requires us to re-SELECT/EXAMINE the mailbox). */
     if (!empty($this->_temp['mailbox']['highestmodseq']) && isset($this->_init['enabled']['QRESYNC'])) {
         $this->_updateMetaData($mailbox, array(self::CACHE_MODSEQ => $this->_temp['mailbox']['highestmodseq']), isset($this->_temp['mailbox']['uidvalidity']) ? $this->_temp['mailbox']['uidvalidity'] : null);
     }
     return $list_msgs ? $this->getIdsOb($expunged, $options['ids']->sequence) : null;
 }