Francisco Presencia
Francisco Presencia

Reputation: 8861

imap_msgno() returns 0 for an uid returned form imap_search()

I'm not sure how to debug this, the function imap_msgno() is returning 0 instead of the message number without any error. This is the part of the code giving the trouble (with debugging info):

// Retrieve and order emails
$search = imap_search($this->open, 'SINCE "' . $date . '"');
$sorted_search = $this->order_search($search, $sorted);

// Store all the messages
$Messages = array();
foreach($sorted_search as $msgUID) {
  $msgNo  = imap_msgno ($this->open, $msgUID);
  $header = imap_header($this->open, $msgNo);

  var_dump($msgUID);
  var_dump($msgNo);
  if (empty($header->message_id)) {
    var_dump($header);
    }
  else {
    echo "Good";
    }
  echo " | ";

  // mode code ...
  }

This should return many int (12) int (10) Good | int (11) int (9) Good | .... However, that's not the case, it returns this (returns added for clarity):

int(12) int(10) Good |
int(11) int(9) Good |
int(10) int(0) bool(false) |
int(9) int(0) bool(false) |
int(8) int(8) Good | 
...

As you can see, the $msgNo seems to be correct. The function imap_msgno() in the documentation doesn't provide any more information about the behaviour of an invalid $msgNo, and I'm pieced as it should be a valid $msgNo since it's part of the returned imap_search(). Any idea of how to debug this or where it's going wrong?

Upvotes: 0

Views: 591

Answers (1)

Andrew
Andrew

Reputation: 1178

Unless they are being set in the order_search call you are returning message numbers and not unique ids. If you set the option SE_UID in the imap_search call e.g.

$search = imap_search($this->open, 'SINCE "' . $date . '"', SE_UID);

You should get unique ids.

Upvotes: 1

Related Questions