ezcMailImapTransport::setFlag PHP Method

setFlag() public method

This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. $messages can be: - a single message number (eg. 1) - a message range (eg. 1:4) - a message list (eg. 1,2,4) $flag can be one of: - 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 - SEEN - message has been read This function automatically adds the '\' in front of the flag when calling the server command. 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. Example: $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'mailbox' ); // Inbox or another mailbox $imap->setFlag( '1:4', 'DRAFT' );
public setFlag ( string $messages, string $flag ) : boolean
$messages string
$flag string
return boolean
    public function setFlag($messages, $flag)
    {
        $uid = $this->options->uidReferencing ? self::UID : self::NO_UID;
        if ($this->state != self::STATE_SELECTED) {
            throw new ezcMailTransportException("Can't call setFlag() when a mailbox is not selected.");
        }
        $flag = $this->normalizeFlag($flag);
        if (in_array($flag, self::$basicFlags)) {
            $tag = $this->getNextTag();
            $this->connection->sendData("{$tag} {$uid}STORE {$messages} +FLAGS (\\{$flag})");
            $response = trim($this->getResponse($tag));
            if ($this->responseType($response) != self::RESPONSE_OK) {
                throw new ezcMailTransportException("The IMAP server could not set flag '{$flag}' on the messages '{$messages}': {$response}.");
            }
        } else {
            throw new ezcMailTransportException("Flag '{$flag}' is not allowed for setting.");
        }
        return true;
    }

Usage Example

コード例 #1
0
 public function testUidSetFlagNotSelected()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port, array('uidReferencing' => true));
     $imap->authenticate(self::$user, self::$password);
     try {
         $imap->setFlag("1", "ANSWERED");
         $this->fail("Expected exception was not thrown.");
     } catch (ezcMailTransportException $e) {
     }
 }
All Usage Examples Of ezcMailImapTransport::setFlag