ezcMailImapTransport::delete PHP Method

delete() public method

This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. The message number $msgNum must be a valid identifier fetched with e.g. {@link listMessages()}. The message is not physically deleted, but has its DELETED flag set, and can be later undeleted by clearing its DELETED flag with {@link clearFlag()}. 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.
public delete ( integer $msgNum ) : boolean
$msgNum integer
return boolean
    public function delete($msgNum)
    {
        $uid = $this->options->uidReferencing ? self::UID : self::NO_UID;
        if ($this->state != self::STATE_SELECTED) {
            throw new ezcMailTransportException("Can't call delete() when a mailbox is not selected.");
        }
        $tag = $this->getNextTag();
        $this->connection->sendData("{$tag} {$uid}STORE {$msgNum} +FLAGS (\\Deleted)");
        // get the response (should be "{$tag} OK Store completed.")
        $response = trim($this->getResponse($tag));
        if ($this->responseType($response) != self::RESPONSE_OK) {
            throw new ezcMailTransportException("The IMAP server could not delete the message '{$msgNum}': {$response}.");
        }
        return true;
    }

Usage Example

コード例 #1
0
 public function testUidDelete()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port, array('uidReferencing' => true));
     $imap->authenticate(self::$user, self::$password);
     $imap->createMailbox("Guybrush");
     $imap->selectMailbox('inbox');
     $imap->copyMessages(self::$ids[0], "Guybrush");
     $imap->selectMailbox("Guybrush");
     $imap->delete(1);
     $imap->selectMailbox('inbox');
     $imap->deleteMailbox("Guybrush");
 }
All Usage Examples Of ezcMailImapTransport::delete