gpt4 book ai didi

email - Zend_Mail : moveMessage() exception

转载 作者:行者123 更新时间:2023-12-01 13:03:59 26 4
gpt4 key购买 nike

根据文档,您应该use the getNumberByUniqueId() method在移动/删除电子邮件时检索消息 ID。但是,我似乎仍然在处理文件夹的过程中出现异常:“响应中未找到单个 ID”。

使用的代码如下:

try {
$emailAddresses = array ();
$invalidAddresses = array ();
$errors = array();

$emailValidator = new Zend_Validate_EmailAddress ();
$trimFilter = new Zend_Filter_StringTrim ();

$mail = new Zend_Mail_Storage_Imap (...);
$mail->selectFolder ( '/Unsubscribe' );

echo 'There are ' . $mail->countMessages () . " messages to process\n";

foreach ( $mail as $messageId => $message ) {
try {
$mail->noop ();
$recipientMatch = $trimFilter->filter ( str_ireplace ( 'REMOVE ', '', $message->subject ) );

if (! substr_count ( $recipientMatch, '@' )) {
// Try the sender if the subject line doesn't have an address in
$matches = array ();
$from = $message->getHeader ( 'from' );
preg_match ( '/<(.+@.+)>/', $from, $matches );

if (sizeof ( $matches ) == 2) {
$recipientMatch = $matches [1];
} else {
$recipientMatch = $from;
}
}

if (! $emailValidator->isValid ( $recipientMatch )) {
$invalidAddresses [] = $recipientMatch;
continue;
}

$emailAddresses [] = $recipientMatch;
$messageUniqueId = $mail->getUniqueId ( $messageId );
$mail->moveMessage ( $mail->getNumberByUniqueId ( $messageUniqueId ), '/Unsubscribe/done' );
} catch ( Exception $e ) {
$errors[] = array($recipientMatch , $e);
}
}
} catch ( Zend_Mail_Storage_Exception $e ) {
echo "There was a problem processing the mail account\n", $e->getMessage ();
} catch ( Exception $e ) {
echo "There was an unmatched exception\n", $e->getMessage ();
}

知道为什么抛出异常(Zend Framework v1.10.8)吗?

异常的堆栈跟踪是:

#0 /usr/share/php/libzend-framework-php/Zend/Mail/Storage/Imap.php(163): Zend_Mail_Protocol_Imap->fetch(Array, 4)
#1 /usr/share/php/libzend-framework-php/Zend/Mail/Storage/Abstract.php(307): Zend_Mail_Storage_Imap->getMessage(4)
#2 /tmp/unsubscribe.php(29): Zend_Mail_Storage_Abstract->current()
#3 /tmp/dummy.php(1): include('/tmp/unsubscribe.php')
#4 {main}

Zend_Mail_Protocol_Imap->fetch()中使用的数组内容是:

Array(
0 => 'FLAGS',
1 => 'RFC822.HEADER'
)

最佳答案

你不应该使用这种循环。有了这个循环,只要你删除一条消息,$messageId 就会过时。在下一个周期中,$messageId 将“指向”错误消息甚至没有消息(如 Index-Out-Of-Bounce)。这就是您收到错误消息的原因。

解决方案:首先将所有相关的唯一 ID 收集到一个数组中,然后遍历该数组并调用 moveMessage - 使用从 getNumberByUniqueId 获得的最新 ID!

我希望我没记错,但我认为 moveMessage($id, $folder) 应该是 moveMessage($index, $folder)。这样更准确。但如果这是错误的,请纠正我。

关于email - Zend_Mail : moveMessage() exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4183080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com