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) |
{ 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);
<?php 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
public function testListMailboxesInvalid() { $imap = new ezcMailImapTransport(self::$server, self::$port); $imap->authenticate(self::$user, self::$password); try { $mailboxes = $imap->listMailboxes('"', '*'); $this->fail("Expected exception was not thrown"); } catch (ezcMailTransportException $e) { } }