SSilence / php-imap-client

a easy solution for simple IMAP email access in php
MIT License
268 stars 136 forks source link

Bad message number Again #178

Closed matiux closed 7 years ago

matiux commented 7 years ago

Hi, I have read issue #92 but I have no warnings.. I have only wrong number of messages when call $imapClient->countMessages()

$imapClient->selectFolder('Friends/Carl');
$overallMessages = $this->imapClient->countMessages(); // Bad number messages
matiux commented 7 years ago

I figured out that the problem is Gmail. With my personal domain / email, the count works well .. Some idea?

sergey144010 commented 7 years ago

This error usually occurs when the message id is not valid. This method is very simple, there can be no mistakes.

public function countMessages()
{
return imap_num_msg($this->imap);
}

http://php.net/manual/en/function.imap-num-msg.php

BUT all imap servers have different implementation. And they may not correctly work with imap_num_msg().

Try to use imap_status() and pull out the number of messages from there.

imap_status ( resource $imap_stream , string $mailbox , int $options )

http://php.net/manual/en/function.imap-status.php

$status = imap_status($mbox, "{imap.example.org}INBOX", SA_ALL);
if ($status) {
  echo "Messages:   " . $status->messages    . "<br />\n";
  echo "Recent:     " . $status->recent      . "<br />\n";
  echo "Unseen:     " . $status->unseen      . "<br />\n";
  echo "UIDnext:    " . $status->uidnext     . "<br />\n";
  echo "UIDvalidity:" . $status->uidvalidity . "<br />\n";
} else {
  echo "imap_status failed: " . imap_last_error() . "\n";
}
mattparksjr commented 7 years ago

@matiux is this still an issue?

mattparksjr commented 7 years ago

I assume we good here :D