donglu1973 2010-09-28 14:10 采纳率: 100%
浏览 55
已采纳

Zend Mail - 如何在没有电子邮件标记为已打开的情况下阅读

I'm using zend mail extended with zend_mail_storage_imap and I built an application that looks for keywords in user's emails.

The problem is that it opens up each email and keeps it marked as read. Is there a way to check the body of emails and not mark each mail checked as read?

Here's current working code. It's part of an ajax query that automatically looks through someone's inbox. In this current form, it will mark each mail starting with a user's most current mail as read (in gmail). Would it be possible to check the body text, but not mark the email as read. Alternatively, will I need to check if each mail is read or unread before looking it up, and then restore it to that state as a workaround?

if (strpos(htmlentities($storage->getMessage($i)),$searchterm)) 
{
    $fromaddress = str_replace("'","",$storage->getMessage($i)->from);
    $fromaddress = str_replace('"','',$fromaddress);

    $sql = "SELECT `senderemail`,`subscribed` FROM email_spam WHERE `useremail` = '$_SESSION[email_address]' AND `senderemail` = '$fromaddress'";
    $result = mysql_query($sql) or die (mysql_error());

    $num = mysql_num_rows($result);


    if($num == 0)
    {
        $emailmessage = mysql_escape_string($storage->getMessage($i)->getContent());
        $sql_insert = "INSERT into `email_spam` (`message`,`useremail`,`senderemail`,`datetime`,`subscribed`) VALUES ('$emailmessage','$_SESSION[email_address]','$fromaddress',now(),1)";

        mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());

        $sql = "SELECT `emailid`,`datetime` FROM email_spam WHERE `useremail` = '$_SESSION[email_address]' ORDER BY `datetime` desc";
        $getid = mysql_query($sql) or die (mysql_error());

        $num = mysql_num_rows($getid);

    }

}

EDIT - here's the final code for those interested

$storage = new Zend_Mail_Storage_Imap($imap);


$flags = $storage->getMessage($i)->getFlags();      
$newflag = $flags[Zend_Mail_Storage::FLAG_RECENT];  
$oldflag = $flags['\Seen'];

if(!empty($flags['\Seen']))
{
    $read=1;
}
else 
{
    $read=0;
}

The entire code is looped, so here, I perform my entire searching/sorting algorithm for each individual email.

if ($read==0)
{
    $storage->setFlags($i, array(Zend_Mail_Storage::FLAG_RECENT)); //marks as new
}   

Here, I go and mark the emails that were not read (before the implementations) as unread. I think this is the most efficient way (that I could find) of performing this operation. I welcome any other codes or comments.

  • 写回答

5条回答 默认 最新

  • dounue1965 2010-09-28 14:19
    关注

    After reading a message, you could unset the seen flag. See also the imap implementation of the setFlags method. Api documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号