douyi5822 2012-11-14 09:22
浏览 75
已采纳

我可以阻止imap_search将电子邮件设置为READ

I have a function that connects to an imap email account (currently testing with gmail) to get emails that are UNSEEN. After getting the emails I loop through them and do imap_fetch_overview() and imap_fetchbody() on each email.

After running this function all the emails that have been searched get set to READ in the inbox.

Is there anyway to stop this happening? Ideally i'd like the email to remain UNSEEN.

Here is my function

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;
    }
}
  • 写回答

2条回答 默认 最新

  • duanju7199 2012-11-14 16:45
    关注

    I figured out why they were getting set to READ and also how to stop it.

    $message = imap_fetchbody($this->inbox,$email_number,1);
    

    That code sets the message to READ. By adding FT_PEEK as an option it remains UNSEEN

    $message = imap_fetchbody($this->inbox,$email_number,1, FT_PEEK);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用