ezcMailImapTransport::searchMailbox PHP Method

searchMailbox() public method

This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. See {@link http://www.faqs.org/rfcs/rfc1730.html} - 6.4.4. (or {@link http://www.faqs.org/rfcs/rfc1730.html} - 6.4.4.) for criterias which can be used for searching. The criterias can be combined in the same search string (separate the criterias with spaces). If $criteria is null or empty then it will default to 'ALL' (returns all messages in the mailbox). Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected. Examples: $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'mailbox' ); // Inbox or another mailbox return an ezcMailImapSet containing all messages flagged as 'SEEN' $set = $imap->searchMailbox( 'SEEN' ); return an ezcMailImapSet containing messages with 'release' in their Subject $set = $imap->searchMailbox( 'SUBJECT "release"' ); criterias can be combined: return an ezcMailImapSet containing messages flagged as 'SEEN' and with 'release' in their Subject $set = $imap->searchMailbox( 'SEEN SUBJECT "release"' ); $set can be parsed with ezcMailParser
public searchMailbox ( string $criteria = null ) : ezcMailImapSet
$criteria string
return ezcMailImapSet
    public function searchMailbox($criteria = null)
    {
        $uid = $this->options->uidReferencing ? self::UID : self::NO_UID;
        if ($this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY) {
            throw new ezcMailTransportException("Can't call searchMailbox() on the IMAP transport when a mailbox is not selected.");
        }
        $criteria = trim($criteria);
        if (empty($criteria)) {
            $criteria = 'ALL';
        }
        $matchingMessages = array();
        $tag = $this->getNextTag();
        $this->connection->sendData("{$tag} {$uid}SEARCH {$criteria}");
        $response = $this->getResponse('* SEARCH');
        if (strpos($response, '* SEARCH') !== false) {
            $ids = substr(trim($response), 9);
            if (trim($ids) !== "") {
                $matchingMessages = explode(' ', $ids);
            }
        }
        $response = trim($this->getResponse($tag, $response));
        if ($this->responseType($response) != self::RESPONSE_OK) {
            throw new ezcMailTransportException("The IMAP server could not search the messages by the specified criteria: {$response}.");
        }
        return new ezcMailImapSet($this->connection, array_values($matchingMessages), false, array('uidReferencing' => $this->options->uidReferencing));
    }

Usage Example

コード例 #1
0
ファイル: ClientTest.php プロジェクト: tvpsoft/laravel-kinvey
 /**
  * Get the password reset URL.
  *
  * @return string
  */
 public static function getPasswordResetURL()
 {
     $options = new \ezcMailImapTransportOptions();
     $options->ssl = true;
     $imap = new \ezcMailImapTransport('imap.gmail.com', null, $options);
     $imap->authenticate('*****@*****.**', Config::get('kinvey::testMail'));
     $imap->selectMailbox('Inbox');
     $set = $imap->searchMailbox('FROM "*****@*****.**"');
     $parser = new \ezcMailParser();
     $mail = $parser->parseMail($set);
     preg_match("#https.*#", $mail[0]->generateBody(), $matches);
     $url = html_entity_decode($matches[0]);
     $url = mb_substr($url, 0, -1);
     foreach ($set->getMessageNumbers() as $msgNum) {
         $imap->delete($msgNum);
     }
     $imap->expunge();
     return $url;
 }
All Usage Examples Of ezcMailImapTransport::searchMailbox