ezcMailImapTransport::selectMailbox PHP Méthode

selectMailbox() public méthode

Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully. Inbox is a special mailbox and can be specified with any case. This method should be called after authentication, and before fetching any messages. Example of selecting a mailbox: $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'Reports 2006' );
public selectMailbox ( string $mailbox, boolean $readOnly = false )
$mailbox string
$readOnly boolean
    public function selectMailbox($mailbox, $readOnly = false)
    {
        if ($this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY) {
            throw new ezcMailTransportException("Can't call selectMailbox() when not successfully logged in.");
        }
        $tag = $this->getNextTag();
        // if the mailbox selection will be successful, $state will be STATE_SELECTED
        // or STATE_SELECTED_READONLY, depending on the $readOnly parameter
        if ($readOnly !== true) {
            $this->connection->sendData("{$tag} SELECT \"{$mailbox}\"");
            $state = self::STATE_SELECTED;
        } else {
            $this->connection->sendData("{$tag} EXAMINE \"{$mailbox}\"");
            $state = self::STATE_SELECTED_READONLY;
        }
        // if the selecting of the mailbox fails (with "NO" or "BAD" response
        // from the server), $state reverts to STATE_AUTHENTICATED
        $response = trim($this->getResponse($tag));
        if ($this->responseType($response) == self::RESPONSE_OK) {
            $this->state = $state;
            $this->selectedMailbox = $mailbox;
        } else {
            $this->state = self::STATE_AUTHENTICATED;
            $this->selectedMailbox = null;
            throw new ezcMailTransportException("Could not select mailbox '{$mailbox}': {$response}.");
        }
    }

Usage Example

 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::selectMailbox