ezcMailImapTransport::searchByFlag PHP Method

searchByFlag() protected method

This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. $flag can be one of: Basic flags: - ANSWERED - message has been answered - DELETED - message is marked to be deleted by later EXPUNGE - DRAFT - message is marked as a draft - FLAGGED - message is "flagged" for urgent/special attention - RECENT - message is recent - SEEN - message has been read Opposites of the above flags: - UNANSWERED - UNDELETED - UNDRAFT - UNFLAGGED - OLD - UNSEEN Composite flags: - NEW - equivalent to RECENT + UNSEEN - ALL - all the messages The returned array is something like this: array( 0 => 1, 1 => 5 ); 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.
protected searchByFlag ( string $flag ) : array(int)
$flag string
return array(int)
    protected function searchByFlag($flag)
    {
        $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 searchByFlag() on the IMAP transport when a mailbox is not selected.");
        }
        $matchingMessages = array();
        $flag = $this->normalizeFlag($flag);
        if (in_array($flag, self::$extendedFlags)) {
            $tag = $this->getNextTag();
            $this->connection->sendData("{$tag} {$uid}SEARCH ({$flag})");
            $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 flags: {$response}.");
            }
        } else {
            throw new ezcMailTransportException("Flag '{$flag}' is not allowed for searching.");
        }
        return $matchingMessages;
    }