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 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗