ezcMailImapTransport::clearFlag PHP 메소드

clearFlag() 공개 메소드

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->clearFlag( '1:4', 'DRAFT' );
public clearFlag ( string $messages, string $flag ) : boolean
$messages string
$flag string
리턴 boolean
    public function clearFlag($messages, $flag)
    {
        $uid = $this->options->uidReferencing ? self::UID : self::NO_UID;
        if ($this->state != self::STATE_SELECTED) {
            throw new ezcMailTransportException("Can't call clearFlag() 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 clear flag '{$flag}' on the messages '{$messages}': {$response}.");
            }
        } else {
            throw new ezcMailTransportException("Flag '{$flag}' is not allowed for clearing.");
        }
        return true;
    }

Usage Example

예제 #1
0
require_once 'tutorial_autoload.php';
// Create a new IMAP transport object by specifying the server name
$imap = new ezcMailImapTransport("imap.example.com");
// Authenticate to the IMAP server
$imap->authenticate("user", "password");
// Select the Inbox mailbox
$imap->selectMailbox('Inbox');
// List the capabilities of the IMAP server
$capabilities = $imap->capability();
// List existing mailboxes
$mailboxes = $imap->listMailboxes("", "*");
// Fetch the hierarchy delimiter character (usually "/")
$delimiter = $imap->getHierarchyDelimiter();
// Create a new mailbox
$imap->createMailbox("Reports 2006");
// Delete a mailbox
$imap->deleteMailbox("Reports 2005");
// Rename a mailbox
$imap->renameMailbox("Reports 2006", "Reports");
// Copy messages from the selected mailbox (here: Inbox) to another mailbox
$imap->copyMessages("1,2,4", "Reports");
// Set a flag to messages
// See the function description for a list of supported flags
$imap->setFlag("1,2,4", "DELETED");
// Clears a flag from messages
// See the function description for a list of supported flags
$imap->clearFlag("1,2,4", "SEEN");
// Append a message to a mailbox. $mail must contain the mail as text
// Use this with a "Sent" or "Drafts" mailbox
$imap->append("Sent", $mail);
All Usage Examples Of ezcMailImapTransport::clearFlag