ezcMailImapTransport::fetchFromOffset PHP Метод

fetchFromOffset() публичный Метод

This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. Fetches $count messages starting from the $offset and returns them as a {@link ezcMailImapSet}. If $count is not specified or if it is 0, it fetches all messages starting from the $offset. 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->fetchFromOffset( 1, 10 ); $set can be parsed with ezcMailParser
public fetchFromOffset ( integer $offset, integer $count, boolean $deleteFromServer = false ) : ezcMailImapSet
$offset integer
$count integer
$deleteFromServer boolean
Результат ezcMailImapSet
    public function fetchFromOffset($offset, $count = 0, $deleteFromServer = false)
    {
        if ($count < 0) {
            throw new ezcMailInvalidLimitException($offset, $count);
        }
        if ($this->options->uidReferencing) {
            $messages = array_values($this->listUniqueIdentifiers());
            $ids = array_flip($messages);
            if ($count === 0) {
                $count = count($messages);
            }
            if (!isset($ids[$offset])) {
                throw new ezcMailOffsetOutOfRangeException($offset, $count);
            }
            $range = array();
            for ($i = $ids[$offset]; $i < min($count, count($messages)); $i++) {
                $range[] = $messages[$i];
            }
        } else {
            $messages = array_keys($this->listMessages());
            if ($count === 0) {
                $count = count($messages);
            }
            $range = array_slice($messages, $offset - 1, $count, true);
            if (!isset($range[$offset - 1])) {
                throw new ezcMailOffsetOutOfRangeException($offset, $count);
            }
        }
        return new ezcMailImapSet($this->connection, $range, $deleteFromServer, array('uidReferencing' => $this->options->uidReferencing));
    }

Usage Example

Пример #1
0
 public function testFetchFromOffset5()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port);
     $imap->authenticate(self::$user, self::$password);
     $imap->selectMailbox('inbox');
     $set = $imap->fetchFromOffset(1, 0);
     $parser = new ezcMailParser();
     $mail = $parser->parseMail($set);
     $this->assertEquals(4, count($mail));
     $this->assertEquals("pine: Mail with attachment", $mail[1]->subject);
 }
All Usage Examples Of ezcMailImapTransport::fetchFromOffset