listUniqueIdentifiers() public method

You can fetch the unique identifier for a specific message by providing the $msgNum parameter. The unique identifier can be used to recognize mail from servers between requests. In contrast to the message numbers the unique numbers assigned to an email usually never changes. The format of the returned array is: array( message_num => unique_id ); Example: array( 1 => 216, 2 => 217, 3 => 218, 4 => 219 ); 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.
public listUniqueIdentifiers ( integer $msgNum = null ) : array(string)
$msgNum integer
return array(string)
Esempio n. 1
0
 public function testListUniqueIdentifiersReadOnly()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port);
     $imap->authenticate(self::$user, self::$password);
     $imap->selectMailbox('inbox', true);
     $uids = $imap->listUniqueIdentifiers(1);
     $this->assertEquals(array(1 => self::$ids[0]), $uids);
 }
Esempio n. 2
0
$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);
// 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++) {
Esempio n. 3
0
// 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
// Use this to page through a mailbox
// See the function description for a list of criterias and for how to sort ascending or descending
$set = $imap->sortFromOffset(1, 10, "Date");
// Sort the specified messages by Date