【发布时间】:2015-03-13 20:55:49
【问题描述】:
我正在尝试阅读电子邮件中的消息...根据主题的内容,我想将其移动到“进程”或“未经授权”文件夹
将消息保存在数组中,然后将消息从收件箱移动到继续文件夹
这是我所做的
// Checks the inbox
if ($messages = imap_search($this->conn,'ALL'))
{
// Sorts the messages newest first
rsort($messages);
// Loops through the messages
foreach ($messages as $id)
{
$header = imap_headerinfo($this->conn, $id);
$message = imap_fetchbody($this->conn, $id, 1);
if( !isset($header->from[0]->mailbox) || empty($header->from[0]->mailbox)
|| !isset($header->from[0]->host) || empty($header->from[0]->host)
|| !isset($header->subject) || empty($header->from[0]->host)
) {
continue;
}
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$subject = $header->subject;
$outlook = $this->_parseReplyExchange($message);
if($outlook !== false){
$newReply = $outlook;
} else {
$newReply = $this->_parseReplySystem($message);
}
$ticketID = $this->_parseTicketID($subject);
if($ticketID !== false){
$f = array();
$f['id'] = $id;
$f['from'] = $from;
$f['subject'] = $subject;
$f['ticketID'] = $ticketID;
$f['message'] = $newReply;
$this->replyList[] = $f;
$imapresult = imap_mail_move($this->conn, $id, $box, CP_UID);
if($imapresult == false){
echo imap_last_error();
}
}
}
}
else
{
exit('No messages on the IMAP server.');
}
我毫无问题地阅读了该消息,但在尝试移动该消息时出现错误。
.[TRYCREATE] The requested item could not be found.
Notice: Unknown: [TRYCREATE] The requested item could not be found. (errflg=2) in Unknown on line 0
我认为问题在于我如何将 $id 传递给 imap_mail_move 函数。
我还尝试将消息序列号转换为像 $f['id'] = imap_uid($this->conn , $id ) 这样的 UID 号,但没有成功..
我也试过了
$imapresult = imap_mail_move($this->conn, '1:' . $id, $box);
$imapresult = imap_mail_move($this->conn, '1:' . $id, $box, CP_UID);
我什至尝试复制然后删除该消息,但没有成功。
$imapresult = imap_mail_copy($c, '1', 'INBOX/Processed', CP_MOVE);
我无法让消息移动。
如何正确移动消息?
【问题讨论】:
-
您正在混合序列 ID 和 UID。为什么将 CP_UID 标志传递给 imap_mail_move?
-
@Max 我尝试使用 将序列号转换为 UID,但这也不起作用
imap_uid($this->conn , $id )似乎我应该传递一个范围,但我不确定我应该如何生成范围?我想一次移动一封邮件,因为在某些情况下邮件被移动到不同的文件夹