我使用的是封装在Barbushin的方便小类中的PHP IMAP库:https://github.com/barbushin/php-imap
我开始测试我的gmail帐户,它会收到以下内容的未读邮件。
$imap = new IMAP();
$unseen = $imap->searchMailbox('UNSEEN');
类中的函数执行以下操作:
/*
* 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();
}
只是imap_search();
的一个方便的包装http://php.net/manual/en/function.imap-search.php
通过IMAP成功连接到我的交换服务器,现在我可以做以下操作:
$imap = new IMAP();
$unseen = $imap->searchMailbox('ALL');
这将检索Exchange上收件箱中的所有电子邮件(根据我的连接)。
UNSEEN
(如文档所示)在Google Mail上按预期工作,但在Exchange 2010上不行。ALL
在两者上都按预期工作。我想知道Exchange 2010是否使用了不同的标志?NEW
和UNREAD
也不工作。并且我可以从这些mailID中获得的返回的详细信息不包含要从中进行逆向工程的标志数组。
任何帮助都将非常感谢:)
如果它不起作用,这是Exchange的一个bug。UNSEEN
搜索词对应于缺少'Seen
关键字(消息标志),参见RFC 3501, p. 52。