dateSearch() public method

Search for messages within a date range.
public dateSearch ( mixed $date, string $range, boolean $header = true, boolean $not = false, array $opts = [] )
$date mixed DateTime or Horde_Date object.
$range string Either: - Horde_Imap_Client_Search_Query::DATE_BEFORE - Horde_Imap_Client_Search_Query::DATE_ON - Horde_Imap_Client_Search_Query::DATE_SINCE
$header boolean If true, search using the date in the message headers. If false, search using the internal IMAP date (usually arrival time).
$not boolean If true, do a 'NOT' search of the range.
$opts array Additional options: - fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Ejemplo n.º 1
0
 /**
  * Purge old messages in the sent-mail mailbox.
  *
  * @return boolean  Whether any messages were purged from the mailbox.
  */
 public function execute()
 {
     global $prefs, $notification;
     /* Get the current UNIX timestamp minus the number of days specified
      * in 'purge_sentmail_keep'.  If a message has a timestamp prior to
      * this value, it will be deleted. */
     $del_time = new Horde_Date(time() - $prefs->getValue('purge_sentmail_keep') * 86400);
     foreach ($this->_getMboxes() as $mbox) {
         /* Open the sent-mail mailbox and get the list of messages older
          * than 'purge_sentmail_keep' days. */
         $query = new Horde_Imap_Client_Search_Query();
         $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
         $msg_ids = $mbox->runSearchQuery($query);
         /* Go through the message list and delete the messages. */
         if ($msg_ids->delete(array('nuke' => true))) {
             $msgcount = count($msg_ids);
             if ($msgcount == 1) {
                 $notification->push(sprintf(_("Purging 1 message from sent-mail mailbox %s."), $mbox->display), 'horde.message');
             } else {
                 $notification->push(sprintf(_("Purging %d messages from sent-mail mailbox."), $msgcount, $mbox->display), 'horde.message');
             }
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 public function getLatestMails($o)
 {
     $aResults = array();
     $aRes = $this->imapProxy->getMMGMaxInFolder($this->imapProxy->currentFolder64, $this->imapProxy->currentFolderStatus['uidvalidity']);
     $sMinDate = $aRes[0]['max_date'] == '' ? '1980-01-01' : $aRes[0]['max_date'];
     //$iMinId	= max(1,O + $aRes[0]['max_id']);
     $oUnseenQuery = new Horde_Imap_Client_Search_Query(array('peek' => true));
     $oUnseenQuery->flag('SEEN', false);
     $oUnseenQuery->dateSearch($sMinDate, Horde_Imap_Client_Search_Query::DATE_SINCE);
     $results = $this->imapProxy->search($oUnseenQuery);
     $aAllIDs = $results['match']->ids;
     if (count($aAllIDs)) {
         $aChunksID = array_chunk($aAllIDs, 30);
         foreach ($aChunksID as $aMsg) {
             $oMMG = new MMG_MAIL_MESSAGE();
             $aMMG = $oMMG->get(array('cols' => array('group_concat(MMG_UID order by MMG_UID) as UIDS'), 'where' => array('MMG_FOLDER' => $this->imapProxy->currentFolder64, 'MMG_FOLDER_UUID' => $this->imapProxy->currentFolderStatus['uidvalidity'], 'MMG_UID' => array('IN', $aMsg))));
             $aMMGId = explode(',', $aMMG[0]['uids']);
             $aMsgToDo = array_diff($aMsg, $aMMGId);
             $aTmp = $this->imapProxy->fetch_overviewWithCache($aMsgToDo, array('account' => $o['account'], 'folder' => $this->imapProxy->currentFolder64));
             foreach ($aTmp as $aHeader) {
                 $from = $aHeader->from[0]->name ? $aHeader->from[0]->name : $aHeader->from[0]->email;
                 if (!array_key_exists($from, $aResults)) {
                     $aResults[$from] = array();
                 }
                 $aResults[$from][] = $aHeader->subject;
             }
         }
         if (count($aResults) > 0) {
             $this->stomp->send("/topic/imapNotifierOnMessage/" . $o['account'], json_encode(array('newEmails' => $aResults)));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Purge old messages in the Trash mailbox.
  *
  * @return boolean  Whether any messages were purged from the mailbox.
  */
 public function execute()
 {
     global $injector, $notification, $prefs;
     /* Get the current UNIX timestamp minus the number of days
        specified in 'purge_trash_keep'.  If a message has a
        timestamp prior to this value, it will be deleted. */
     $del_time = new Horde_Date(time() - $prefs->getValue('purge_trash_keep') * 86400);
     /* Get the list of messages older than 'purge_trash_keep' days. */
     $query = new Horde_Imap_Client_Search_Query();
     $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
     $msg_ids = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TRASH)->runSearchQuery($query);
     /* Go through the message list and delete the messages. */
     if (!$injector->getInstance('IMP_Message')->delete($msg_ids, array('nuke' => true))) {
         return false;
     }
     $msgcount = count($msg_ids);
     $notification->push(sprintf(ngettext("Purging %d message from Trash mailbox.", "Purging %d messages from Trash mailbox.", $msgcount), $msgcount), 'horde.message');
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Purge old messages in the Spam mailbox.
  *
  * @return boolean  Whether any messages were purged from the mailbox.
  */
 public function execute()
 {
     if (!($spam = $this->_spamMbox())) {
         return false;
     }
     /* Get the current UNIX timestamp minus the number of days
        specified in 'purge_spam_keep'.  If a message has a
        timestamp prior to this value, it will be deleted. */
     $del_time = new Horde_Date(time() - $GLOBALS['prefs']->getValue('purge_spam_keep') * 86400);
     /* Get the list of messages older than 'purge_spam_keep' days. */
     $query = new Horde_Imap_Client_Search_Query();
     $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
     $msg_ids = $spam->runSearchQuery($query);
     /* Go through the message list and delete the messages. */
     if ($GLOBALS['injector']->getInstance('IMP_Message')->delete($msg_ids, array('nuke' => true))) {
         $msgcount = count($msg_ids);
         $GLOBALS['notification']->push(sprintf(ngettext("Purging %d message from Spam mailbox.", "Purging %d messages from Spam mailbox.", $msgcount), $msgcount), 'horde.message');
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * Return a folder object containing all IMAP server change information.
  *
  * @param array $options  An array of options.
  *        @see Horde_ActiveSync_Imap_Adapter::getMessageChanges
  *
  * @return Horde_ActiveSync_Folder_Base  The populated folder object.
  */
 public function getChanges(array $options)
 {
     $this->_logger->info(sprintf('[%s] NO CONDSTORE or per mailbox MODSEQ. minuid: %s, total_messages: %s', $this->_procid, $this->_folder->minuid(), $this->_status['messages']));
     $query = new Horde_Imap_Client_Search_Query();
     if (!empty($options['sincedate'])) {
         $query->dateSearch(new Horde_Date($options['sincedate']), Horde_Imap_Client_Search_Query::DATE_SINCE);
     }
     try {
         $search_ret = $this->_imap_ob->search($this->_mbox, $query, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH)));
     } catch (Horde_Imap_Client_Exception $e) {
         $this->_logger->err($e->getMessage());
         throw new Horde_ActiveSync_Exception($e);
     }
     $cnt = $search_ret['count'] / Horde_ActiveSync_Imap_Adapter::MAX_FETCH + 1;
     $query = new Horde_Imap_Client_Fetch_Query();
     $query->flags();
     $flags = array();
     for ($i = 0; $i <= $cnt; $i++) {
         $ids = new Horde_Imap_Client_Ids(array_slice($search_ret['match']->ids, $i * Horde_ActiveSync_Imap_Adapter::MAX_FETCH, Horde_ActiveSync_Imap_Adapter::MAX_FETCH));
         try {
             $fetch_ret = $this->_imap_ob->fetch($this->_mbox, $query, array('ids' => $ids));
         } catch (Horde_Imap_Client_Exception $e) {
             $this->_logger->err($e->getMessage());
             throw new Horde_ActiveSync_Exception($e);
         }
         foreach ($fetch_ret as $uid => $data) {
             $flags[$uid] = array('read' => array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false ? 1 : 0);
             if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWOFIVE) {
                 $flags[$uid]['flagged'] = array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false ? 1 : 0;
             }
         }
     }
     if (!empty($flags)) {
         $this->_folder->setChanges($search_ret['match']->ids, $flags);
     }
     $this->_folder->setRemoved($this->_imap_ob->vanished($this->_mbox, null, array('ids' => new Horde_Imap_Client_Ids($this->_folder->messages())))->ids);
     return $this->_folder;
 }
Ejemplo n.º 6
0
 /**
  * @dataProvider dateSearchQueryProvider
  */
 public function testDateSearchQuery($range, $header, $not, $fuzzy, $expected)
 {
     $ob = new Horde_Imap_Client_Search_Query();
     $ob->dateSearch(new DateTime('January 1, 2010'), $range, $header, $not, array('fuzzy' => $fuzzy));
     $this->assertEquals($expected, $fuzzy ? $this->_fuzzy($ob) : strval($ob));
 }
Ejemplo n.º 7
0
 /**
  * Perform an IMAP search based on a SEARCH request.
  *
  * @param array $query  The search query.
  *
  * @return array  The results array containing an array of hashes:
  *   'uniqueid' => [The unique identifier of the result]
  *   'searchfolderid' => [The mailbox name that this result comes from]
  *
  * @throws Horde_ActiveSync_Exception
  */
 protected function _doQuery(array $query)
 {
     $imap_query = new Horde_Imap_Client_Search_Query();
     $mboxes = array();
     $results = array();
     foreach ($query as $q) {
         switch ($q['op']) {
             case Horde_ActiveSync_Request_Search::SEARCH_AND:
                 return $this->_doQuery(array($q['value']), $range);
             default:
                 foreach ($q as $key => $value) {
                     switch ($key) {
                         case 'FolderType':
                             if ($value != Horde_ActiveSync::CLASS_EMAIL) {
                                 throw new Horde_ActiveSync_Exception('Only Email folders are supported.');
                             }
                             break;
                         case 'serverid':
                             $mboxes[] = new Horde_Imap_Client_Mailbox($value);
                             break;
                         case Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED:
                             if ($q['op'] == Horde_ActiveSync_Request_Search::SEARCH_GREATERTHAN) {
                                 $query_range = Horde_Imap_Client_Search_Query::DATE_SINCE;
                             } elseif ($q['op'] == Horde_ActiveSync_Request_Search::SEARCH_LESSTHAN) {
                                 $query_range = Horde_Imap_Client_Search_Query::DATE_BEFORE;
                             } else {
                                 $query_range = Horde_Imap_Client_Search_Query::DATE_ON;
                             }
                             $imap_query->dateSearch($value, $query_range);
                             break;
                         case Horde_ActiveSync_Request_Search::SEARCH_FREETEXT:
                             $imap_query->text($value, false);
                             break;
                         case 'subquery':
                             $imap_query->andSearch(array($this->_buildSubQuery($value)));
                     }
                 }
         }
     }
     if (empty($mboxes)) {
         foreach ($this->getMailboxes() as $mailbox) {
             $mboxes[] = $mailbox['ob'];
         }
     }
     foreach ($mboxes as $mbox) {
         try {
             $search_res = $this->_getImapOb()->search($mbox, $imap_query, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH, Horde_Imap_Client::SEARCH_RESULTS_SAVE, Horde_Imap_Client::SEARCH_RESULTS_COUNT), 'sort' => array(Horde_Imap_Client::SORT_REVERSE, Horde_Imap_Client::SORT_ARRIVAL)));
         } catch (Horde_Imap_Client_Exception $e) {
             throw new Horde_ActiveSync_Exception($e);
         }
         if ($search_res['count'] == 0) {
             continue;
         }
         $ids = $search_res['match']->ids;
         foreach ($ids as $id) {
             $results[] = array('uniqueid' => $mbox->utf8 . ':' . $id, 'searchfolderid' => $mbox->utf8);
         }
         if (!empty($range)) {
             preg_match('/(.*)\\-(.*)/', $range, $matches);
             $return_count = $matches[2] - $matches[1];
             $results = array_slice($results, $matches[1], $return_count + 1, true);
         }
     }
     return $results;
 }
Ejemplo n.º 8
0
 /**
  * Return message UIDs that are now within the cureent FILTERTYPE value.
  *
  * @param  array                        $options   Options array.
  * @param  boolean                      $is_delete If true, return messages
  *                                                 to SOFTDELETE.
  *
  * @return Horde_Imap_Client_Search_Results
  */
 protected function _searchQuery($options, $is_delete)
 {
     $query = new Horde_Imap_Client_Search_Query();
     $query->dateSearch(new Horde_Date($options['sincedate']), $is_delete ? Horde_Imap_Client_Search_Query::DATE_BEFORE : Horde_Imap_Client_Search_Query::DATE_SINCE);
     $query->ids(new Horde_Imap_Client_Ids($this->_folder->messages()), !$is_delete);
     try {
         return $this->_imap_ob->search($this->_mbox, $query, array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH)));
     } catch (Horde_Imap_Client_Exception $e) {
         $this->_logger->err($e->getMessage());
         throw new Horde_ActiveSync_Exception($e);
     }
 }