ezcMailImapTransport::listUniqueIdentifiers PHP Метод

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

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
Результат array(string)
    public function listUniqueIdentifiers($msgNum = null)
    {
        if ($this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY) {
            throw new ezcMailTransportException("Can't call listUniqueIdentifiers() on the IMAP transport when a mailbox is not selected.");
        }
        $result = array();
        if ($msgNum !== null) {
            $tag = $this->getNextTag();
            $this->connection->sendData("{$tag} UID SEARCH {$msgNum}");
            $response = $this->getResponse('* SEARCH');
            if (strpos($response, '* SEARCH') !== false) {
                $result[(int) $msgNum] = trim(substr($response, 9));
            }
            $response = trim($this->getResponse($tag, $response));
        } else {
            $uids = array();
            $messages = array_keys($this->listMessages());
            $tag = $this->getNextTag();
            $this->connection->sendData("{$tag} UID SEARCH UNDELETED");
            $response = $this->getResponse('* SEARCH');
            if (strpos($response, '* SEARCH') !== false) {
                $response = trim(substr($response, 9));
                if ($response !== "") {
                    $uids = explode(' ', $response);
                }
                for ($i = 0; $i < count($messages); $i++) {
                    $result[trim($messages[$i])] = $uids[$i];
                }
            }
            $response = trim($this->getResponse($tag));
        }
        if ($this->responseType($response) != self::RESPONSE_OK) {
            throw new ezcMailTransportException("The IMAP server could not fetch the unique identifiers: {$response}.");
        }
        return $result;
    }

Usage Example

Пример #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);
 }
All Usage Examples Of ezcMailImapTransport::listUniqueIdentifiers