This method supports unique IDs instead of message numbers. See
{@link ezcMailImapTransportOptions} for how to enable unique IDs
referencing.
If $deleteFromServer is set to true the mail will be marked for deletion
after retrieval. If not it will be left intact.
Note: for IMAP the first message is 1 (so for $number = 0 an exception
will be thrown).
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.
Example:
$imap = new ezcMailImapTransport( 'imap.example.com' );
$imap->authenticate( 'username', 'password' );
$imap->selectMailbox( 'Inbox' );
$set = $imap->fetchByMessageNr( 1 );
$set can be parsed with ezcMailParser
public fetchByMessageNr ( integer $number, boolean $deleteFromServer = false ) : ezcMailImapSet | ||
$number | integer | |
$deleteFromServer | boolean | |
return | ezcMailImapSet |
public function testImapMessageSource() { $transport = new ezcMailImapTransport("mta1.ez.no"); $transport->authenticate("*****@*****.**", "ezcomponents"); $transport->selectMailbox("Inbox"); $parser = new ezcMailParser(); $set = new ezcMailStorageSet($transport->fetchByMessageNr(1), $this->tempDir); $mail = $parser->parseMail($set); $files = $set->getSourceFiles(); $source = file_get_contents($files[0]); $this->assertEquals(self::$sizes[0], strlen($source)); }
public function testFetchByMessageNrNotFound() { $imap = new ezcMailImapTransport(self::$server, self::$port, array('uidReferencing' => true)); $imap->authenticate(self::$user, self::$password); $imap->selectMailbox('inbox'); try { $message = $imap->fetchByMessageNr(-1); $this->fail('Expected exception was not thrown'); } catch (ezcMailNoSuchMessageException $e) { $this->assertEquals("The message with ID '-1' could not be found.", $e->getMessage()); } }
public function testFixTrailingParanthesis() { $transport = new ezcMailImapTransport(self::$server, self::$port); $transport->authenticate(self::$user, self::$password); $transport->selectMailbox("Inbox"); $parser = new ezcMailParser(); $set = $transport->fetchByMessageNr(1); $mail = $parser->parseMail($set); $this->assertNotEquals(')', substr($mail[0]->body->text, strlen($mail[0]->body->text) - 3, 3)); }
// 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 // See the function description for a list of criterias and for how to sort ascending or descending $set = $imap->sortMessages("1,2,3,4,5", "Date"); // Fetch messages which match the specified criteria. // See the section 6.4.4. of RFC 1730 or 2060 for a list of criterias // (http://www.faqs.org/rfcs/rfc1730.html)