You are here

function mailhandler_get_unread_messages in Mailhandler 6

Same name and namespace in other branches
  1. 7 mailhandler.retrieve.inc \mailhandler_get_unread_messages()

Obtain the number of unread messages for an imap stream

Parameters

$result: IMAP stream - as opened by imap_open

Return value

Array, values contain message numbers

1 call to mailhandler_get_unread_messages()
mailhandler_retrieve in ./mailhandler.retrieve.inc
Connect to mailbox and run message retrieval

File

./mailhandler.retrieve.inc, line 287
Mailbox connection code.

Code

function mailhandler_get_unread_messages($result) {
  $unread_messages = array();
  $number_of_messages = imap_num_msg($result);
  for ($i = 1; $i <= $number_of_messages; $i++) {
    $header = imap_headerinfo($result, $i);

    // only process new messages
    if ($header->Unseen != 'U' && $header->Recent != 'N') {
      continue;
    }
    $unread_messages[] = imap_uid($result, $i);
  }
  return $unread_messages;
}