【问题标题】:Unique identifier for writable Zend Mail Storage messages可写 Zend Mail Storage 消息的唯一标识符
【发布时间】:2017-05-19 17:34:21
【问题描述】:

我正在尝试在 PHP/Zend 中创建一个系统,该系统可以收集来自各种不同帐户(主要是 POP 和 IMAP)的电子邮件,并将它们全部组合到一个系统中,以便进行分析(电子邮件的内容等)

我的计划是从帐户中读取电子邮件并将它们移动到本地,因为如果用户需要查看它们,我正在设计的系统将被调用以原始格式显示电子邮件。我已经使用 Zend_Mail_Storage_Writable_Maildir 创建了一个本地 Maildir 结构,并且我正在添加从每个帐户返回的消息。

我能够连接到各种帐户并检索电子邮件,并将它们添加到我的本地 Maildir 帐户而不会出现问题。我的问题是我似乎找不到唯一标识符来分隔添加到 Maildir 帐户的每条消息(我计划将每封电子邮件的一些电子邮件信息与唯一标识符一起存储在数据库中)。

有谁知道如何获取最近添加到 Zend_Mail_Storage_Writable_Maildir 实例中的消息的唯一标识符?

我的基本代码如下:

// Set config array for connecting to an email account (Hotmail, gMail etc.)
$config = array(
    'host'=> 'xxxx',
    'user' => 'xxxx',
    'password' => 'xxxx',
    'ssl' => 'SSL',
    'port' => 995);

// Connect to the account and get the messages
$mail = new Zend_Mail_Storage_Pop3($config);

// Connect to the local Mairdir instance so we can add new messages
$mailWrite = new Zend_Mail_Storage_Writable_Maildir(array('dirname' => '/xxxx/xxxx/'));

// Loop through the messages and add them        
foreach ($mail as $messageId => $message)
{
    // ADDING THE MESSAGE WORKS FINE, BUT HOW DO I GET THE UNIQUE 
    //  IDENTIFIER FOR THE MESSAGE I JUST ADDED?
    $mailWrite->appendMessage($message);

    // FYI: $messageId seems to be the message ID from the originating account; it
    //  starts at one and increments, so this can't be used :(
}

感谢您提供的任何见解!

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    您可以使用Zend_Mail_Storage_Writable_Maildir::getUniqueId()方法获取添加消息的唯一ID。

    如果您没有将 id 传递给函数,它将返回邮件目录中所有邮件唯一 ID 的数组。

    这是一个例子:

    foreach ($mail as $messageId => $message)
    {
        // ADDING THE MESSAGE WORKS FINE, BUT HOW DO I GET THE UNIQUE 
        //  IDENTIFIER FOR THE MESSAGE I JUST ADDED?
        $mailWrite->appendMessage($message);
    
        $ids = $mailWrite->getUniqueId();
        $lastMessageId = $ids[sizeof($ids)];
    }
    

    值得注意的是,getUniqueId() 的返回数组是基于 1 而不是基于 0,所以请注意这一点。

    另外,我不确定这是错误还是设计使然,但为新添加的文件返回的唯一 ID 不包含文件名中的消息大小或信息字符串,但现有消息会。

    也就是说,你的数组可能看起来像这样:

    array(21) {
      [1]=>
      string(38) "1338311280.0773.1143.localhost.localdomain,S=34226"
      [2]=>
      string(38) "1338311278.5589.1143.localhost.localdomain,S=108985"
      [3]=>
      // ...
      [20]=>
      string(39) "1338311217.6442.18718.localhost.localdomain,S=2142"
      [21]=>
      string(31) "1338312073.7461.18715.localhost.localdomain"
    }
    

    注意最后一条消息是如何没有大小的(刚才用 appendMessage 添加的)。

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-07-28
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      相关资源
      最近更新 更多