ezcMailImapTransport::listMailboxes PHP Method

listMailboxes() public method

Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully. For more information about $reference and $mailbox, consult the IMAP RFCs documents ({@link http://www.faqs.org/rfcs/rfc1730.html} or {@link http://www.faqs.org/rfcs/rfc2060.html}, section 7.2.2.). By default, $reference is "" and $mailbox is "*". The array returned contains the mailboxes available for the connected user on this IMAP server. Inbox is a special mailbox, and it can be specified upper-case or lower-case or mixed-case. The other mailboxes should be specified as they are (to the {@link selectMailbox()} method). Example of listing mailboxes: $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $mailboxes = $imap->listMailboxes();
public listMailboxes ( string $reference = '', string $mailbox = '*' ) : array(string)
$reference string
$mailbox string
return array(string)
    public function listMailboxes($reference = '', $mailbox = '*')
    {
        if ($this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY) {
            throw new ezcMailTransportException("Can't call listMailboxes() when not successfully logged in.");
        }
        $result = array();
        $tag = $this->getNextTag();
        $this->connection->sendData("{$tag} LIST \"{$reference}\" \"{$mailbox}\"");
        $response = trim($this->connection->getLine());
        while (strpos($response, '* LIST (') !== false) {
            // only consider the selectable mailboxes
            if (strpos($response, "\\Noselect") === false) {
                $response = substr($response, strpos($response, "\" ") + 2);
                $response = trim($response);
                $response = trim($response, "\"");
                $result[] = $response;
            }
            $response = $this->connection->getLine();
        }
        $response = $this->getResponse($tag, $response);
        if ($this->responseType($response) != self::RESPONSE_OK) {
            throw new ezcMailTransportException("Could not list mailboxes with the parameters '\"{$reference}\"' and '\"{$mailbox}\"': {$response}.");
        }
        return $result;
    }

Usage Example

コード例 #1
0
ファイル: mail.php プロジェクト: notion/zeta-mail
{
    ezcBase::autoload($className);
}
// Start counting how much the execution time will be
$start = microtime(true);
// Read configuration file app.ini with the Configuration component
$iniFile = 'app';
$config = ezcConfigurationManager::getInstance();
$config->init('ezcConfigurationIniReader', dirname(__FILE__));
$options = array('templatePath' => dirname(__FILE__) . $config->getSetting($iniFile, 'TemplateOptions', 'TemplatePath'), 'compilePath' => dirname(__FILE__) . $config->getSetting($iniFile, 'TemplateOptions', 'CompilePath'), 'server' => $config->getSetting($iniFile, 'MailOptions', 'Server'), 'user' => $config->getSetting($iniFile, 'MailOptions', 'User'), 'password' => $config->getSetting($iniFile, 'MailOptions', 'Password'), 'mailbox' => isset($_GET['mailbox']) ? $_GET['mailbox'] : $config->getSetting($iniFile, 'MailOptions', 'Mailbox'), 'pageSize' => $config->getSetting($iniFile, 'MailOptions', 'PageSize'), 'currentPage' => isset($_GET['page']) ? $_GET['page'] : null);
// Create a mail IMAP transport object
$transport = new ezcMailImapTransport($options["server"]);
$transport->authenticate($options["user"], $options["password"]);
$transport->selectMailbox($options["mailbox"]);
// Get the mailboxes names from the server
$mailboxes = $transport->listMailboxes();
sort($mailboxes);
// Get the UIDs of the messages in the selected mailbox
// and the sizes of the messages
$mailIDs = $transport->listUniqueIdentifiers();
$messages = $transport->listMessages();
// Calculate how many pages of mails there will be based on pageSize
$numberOfPages = (int) floor(count($messages) / $options["pageSize"] + 1);
// See if currentPage fits in the range 1..numberOfPages
if ($options["currentPage"] <= 0 || $options["currentPage"] > $numberOfPages || count($messages) % $options["pageSize"] === 0 && $options["currentPage"] >= $numberOfPages) {
    $options["currentPage"] = 1;
}
// Slice the array to the range defined by currentPage
$sizes = array_slice(array_values($messages), ($options["currentPage"] - 1) * $options["pageSize"], $options["pageSize"]);
$mailIDs = array_slice($mailIDs, ($options["currentPage"] - 1) * $options["pageSize"], $options["pageSize"]);
$messages = array_keys($messages);
All Usage Examples Of ezcMailImapTransport::listMailboxes