Question

I am using the PHP IMAP library wrapped in the handy little class from Barbushin: https://github.com/barbushin/php-imap

I started testing against my gmail account, which would fetch my unread emails with the following.

$imap = new IMAP();
$unseen = $imap->searchMailbox('UNSEEN');

The function in the class does the following:

/*
 *      ALL - return all mails matching the rest of the criteria
 *      ANSWERED - match mails with the \\ANSWERED flag set
 *      BCC "string" - match mails with "string" in the Bcc: field
 *      BEFORE "date" - match mails with Date: before "date"
 *      BODY "string" - match mails with "string" in the body of the mail
 *      CC "string" - match mails with "string" in the Cc: field
 *      DELETED - match deleted mails
 *      FLAGGED - match mails with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
 *      FROM "string" - match mails with "string" in the From: field
 *      KEYWORD "string" - match mails with "string" as a keyword
 *      NEW - match new mails
 *      OLD - match old mails
 *      ON "date" - match mails with Date: matching "date"
 *      RECENT - match mails with the \\RECENT flag set
 *      SEEN - match mails that have been read (the \\SEEN flag is set)
 *      SINCE "date" - match mails with Date: after "date"
 *      SUBJECT "string" - match mails with "string" in the Subject:
 *      TEXT "string" - match mails with text "string"
 *      TO "string" - match mails with "string" in the To:
 *      UNANSWERED - match mails that have not been answered
 *      UNDELETED - match mails that are not deleted
 *      UNFLAGGED - match mails that are not flagged
 *      UNKEYWORD "string" - match mails that do not have the keyword "string"
 *      UNSEEN - match mails which have not been read yet
 *
 * @return array Mails ids
 */
public function searchMailbox($criteria = 'ALL') {
    $mailsIds = imap_search($this->imapStream, $criteria, SE_UID, $this->serverEncoding);
    return $mailsIds ? $mailsIds : array();
}

Just a handy wrapper for imap_search(); http://php.net/manual/en/function.imap-search.php

Connected successfully to my exchange server over IMAP, I can now do the following:

$imap = new IMAP();
$unseen = $imap->searchMailbox('ALL');

This will retrieve ALL emails fine, in the inbox on Exchange (as per my connection).

UNSEEN (as documented) worked as expected on Google Mail but not Exchange 2010. ALL works as expected on both. I wondered whether Exchange 2010 used a different flag? NEW and UNREAD also do not work. And the returned details I can get from these mailID's do not contain an array of flags to reverse engineer from.

Any help will be greatly appreciated :)

Was it helpful?

Solution

If it doesn't work, it's a bug in Exchange. The UNSEEN search term corresponds to the lack of the \Seen keyword (a message flag), see RFC 3501, p. 52.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top