listMessages() public method

It returns only the messages with the flag DELETED not set. 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. The format of the returned array is array( message_id => size ); Example: array( 2 => 1700, 5 => 1450, 6 => 21043 ); If $contentType is set, it returns only the messages with $contentType in the Content-Type header. For example $contentType can be "multipart/mixed" to return only the messages with attachments.
public listMessages ( string $contentType = null ) : array(int)
$contentType string
return array(int)
コード例 #1
0
 public function testListMessagesReadOnly()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port);
     $imap->authenticate(self::$user, self::$password);
     $imap->selectMailbox('inbox', true);
     $list = $imap->listMessages();
     $this->assertEquals(array(1 => self::$sizes[0], 2 => self::$sizes[1], 3 => self::$sizes[2], 4 => self::$sizes[3]), $list);
 }
コード例 #2
0
ファイル: mail.php プロジェクト: notion/zeta-mail
// 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);
// Read and parse the headers of the mails in the currentPage from the IMAP server
$mails = array();
$parser = new ezcMailParser();
for ($i = ($options["currentPage"] - 1) * $options["pageSize"]; $i < min($options["currentPage"] * $options["pageSize"], count($messages)); $i++) {
    $msg = $transport->top($messages[$i]);
コード例 #3
0
ファイル: tutorial_imap.php プロジェクト: notion/zeta-mail
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');
// Get the number of messages on the server, combined size, number of recent
// messages and number of unseen messages
// in the variables $num, $size, $recent, $unseen
$imap->status($num, $size, $recent, $unseen);
// Get the list of message numbers on the server and their sizes
// the returned array is something like: array( 1 => 1500, 2 => 45200 )
// where the key is a message number and the value is the message size
$messages = $imap->listMessages();
// Get the list of message unique ids on the server and their sizes
// the returned array is something like: array( 1 => '15', 2 => '16' )
// where the key is an message number and the value is the message unique id
$messages = $imap->listUniqueIdentifiers();
// Usually you will call one of these fetch functions:
// Fetch all messages on the server
$set = $imap->fetchAll();
// Fetch one message from the server (here: get the message no. 2)
$set = $imap->fetchByMessageNr(2);
// Fetch a range of messages from the server (here: get 4 messages starting from message no. 2)
$set = $imap->fetchFromOffset(2, 4);
// Fetch messages which have a certain flag
// See the function description for a list of supported flags
$set = $imap->fetchByFlag("DELETED");
// Fetch a range of messages sorted by Date