ezcMailImapTransport::fetchSizes PHP Method

fetchSizes() public method

This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. $messages is an array of message numbers, for example: array( 1, 2, 4 ); The format of the returned array is: array( message_number => size ) 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( 'mailbox' ); // Inbox or another mailbox $sizes = $imap->fetchSizes( array( 1, 2, 4 ) ); The returned array $sizes will be something like: array( 1 => 1043, 2 => 203901, 4 => 14277 );
public fetchSizes ( array $messages ) : array(int)
$messages array
return array(int)
    public function fetchSizes($messages)
    {
        $uid = $this->options->uidReferencing ? self::UID : self::NO_UID;
        if ($this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY) {
            throw new ezcMailTransportException("Can't call fetchSizes() on the IMAP transport when a mailbox is not selected.");
        }
        $sizes = array();
        $ids = implode($messages, ',');
        $tag = $this->getNextTag();
        $this->connection->sendData("{$tag} {$uid}FETCH {$ids} (RFC822.SIZE)");
        $response = trim($this->connection->getLine());
        while (strpos($response, $tag) === false) {
            if (strpos($response, ' FETCH (') !== false) {
                if ($this->options->uidReferencing) {
                    preg_match('/\\*\\s.*\\sFETCH\\s\\(RFC822\\.SIZE\\s(.*)\\sUID\\s(.*)\\)/U', $response, $matches);
                    $sizes[intval($matches[2])] = (int) $matches[1];
                } else {
                    preg_match('/\\*\\s(.*)\\sFETCH\\s\\(RFC822\\.SIZE\\s(.*)\\)/U', $response, $matches);
                    $sizes[intval($matches[1])] = (int) $matches[2];
                }
            }
            $response = trim($this->connection->getLine());
        }
        if ($this->responseType($response) != self::RESPONSE_OK) {
            throw new ezcMailTransportException("The IMAP server could not fetch flags for the messages '{$messages}': {$response}.");
        }
        return $sizes;
    }

Usage Example

 public function testUidFetchSizesNotSelected()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port, array('uidReferencing' => true));
     $imap->authenticate(self::$user, self::$password);
     try {
         $imap->fetchSizes(self::$ids);
         $this->fail("Expected exception was not thrown.");
     } catch (ezcMailTransportException $e) {
     }
 }
All Usage Examples Of ezcMailImapTransport::fetchSizes