【问题标题】:php web mail application, how to uniquely identify themphp web 邮件应用程序,如何唯一标识它们
【发布时间】:2015-07-18 17:03:03
【问题描述】:

我目前正在构建一个 php 脚本,它使用 imap 函数从服务器获取电子邮件并将详细信息存储在数据库中。

我的问题是我不知道如何从已经存在的旧邮件中识别新邮件。 以及如何获取发送到邮箱的回复邮件

【问题讨论】:

标签: php email imap


【解决方案1】:

使用UID消息来确定最后一条消息,你必须将最后一个UID存储在表中

  $uidsArray = imap_sort($imapConnection, SORTARRIVAL, 1, SE_UID);
  if ($uidsArray) {
      // read UID last message, XEmailUID - table(mailbox, lastuid mailbox)
      $lastUIDObject = new XEmailUID();
      $lastUIDObject->setImap($mailbox->getId().'/'.$mailboxRef);
      if (!$lastUIDObject->select()) {
           $lastUIDObject->insert();
      }

      $uidMax = 0;

      foreach ($uidsArray as $uid) {
        if ($uid < $lastUIDObject->getUid()) {
           continue;
        }

        if ($uid >= $uidMax) {
            $uidMax = $uid;
        }

       // your function
       $this->_readIMAPMessage(
          $imapConnection,
          $uid,
          $mailboxRef
       );
      }

      if ($uidMax > 0) {
         $lastUIDObject->setUid($uidMax);
         $lastUIDObject->update();
      }
   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    相关资源
    最近更新 更多