0

我正在尝试阅读电子邮件中的消息...根据主题的内容,我想将其移动到“进程”或“未经授权”文件夹

将消息保存在一个数组中,然后将消息从收件箱移动到 Proceeded 文件夹

这是我所做的

// 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函数。

我还尝试将消息序列号转换为像这样的 UID 号$f['id'] = imap_uid($this->conn , $id ),但这不起作用..

我也试过这个

$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);

我无法让消息移动。

如何正确移动消息?

4

1 回答 1

2

我发现了这个问题。

问题是该Processed文件夹不是 INBOX 文件夹的子文件夹。这是收件箱旁边的文件夹设置。

这里的要点是使用imap_mail_move()函数时,您需要传递一个序列号或一系列序列号

$imapresult = imap_mail_move($this->conn, $id, $box);

收到的每条消息都有一个序列号1,2,3,n,其中 n 是在给定框中收到的最新消息。

这是$id变量的示例

1
1:5
1,2,5,6,7

第一个示例意味着将消息 1 从当前文件夹移动到定义的新文件夹$box

第二个示例意味着将消息 1、2、3、4、5 从当前文件夹移动到$box.

第三个示例意味着将消息 1、2、5、6、7 从当前文件夹移动到$box.

另外,这里有一些 $box 变量的例子

'INBOX/Processed'
'Unauthorized'

第一个示例表示Processed位于 INBOX 文件夹下的文件夹。

第二个示例表示Unauthorized位于“收件箱”文件夹下一个“相同位置”的文件夹

要知道每个文件夹在您的电子邮件中的位置,您可以使用imap_list函数。

我希望这对其他人有所帮助,因为我花了一段时间才发现这个愚蠢的问题。

于 2015-03-15T18:03:35.950 回答