我有一个连接到imap电子邮件帐户(目前正在使用gmail进行测试)的功能,以获取UNSEEN的电子邮件。收到电子邮件后,我会遍历这些电子邮件,并在每封电子邮件中执行imap_fetch_overview()
和imap_fetchbody()
。
运行此功能后,所有已搜索的电子邮件都会在收件箱中设置为READ。
反正有没有阻止这种情况发生?理想情况下,我希望电子邮件保持UNSEEN。
这是我的功能
function build_email_data(){
$this->connect();
/* grab emails */
$emails = imap_search($this->inbox,'UNSEEN');
/* if emails are returned, cycle through each... */
if($emails) {
/* put the newest emails on top */
rsort($emails);
$data = array();
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($this->inbox,$email_number,0);
$message = imap_fetchbody($this->inbox,$email_number,1);
$_data['subject'] = $overview[0]->subject;
$_data['from'] = $overview[0]->from;
$_data['body'] = $message;
$_data['owner_id'] = 1;
$_data['email_number'] = $email_number;
$_data['folder_id'] = 1;
$_data['created'] = timestamp_to_mysqldatetime();
$_data['updated'] = timestamp_to_mysqldatetime();
$_data['email_date'] = timestamp_to_mysqldatetime(strtotime($overview[0]->date));
$data[] = $_data;
}
$this->disconnect();
return $data;
}
}
答案 0 :(得分:2)
我弄清楚他们为什么要设置为READ以及如何阻止它。
$message = imap_fetchbody($this->inbox,$email_number,1);
该代码将消息设置为READ。通过添加FT_PEEK作为选项,它仍然是UNSEEN
$message = imap_fetchbody($this->inbox,$email_number,1, FT_PEEK);
答案 1 :(得分:0)
你在混淆UNSEEN和最近吗?获取消息将清除RECENT标志,但只更改标志(添加\ Seen)应更改SEEN标志。