I am trying to read messages from an email... Depending on the subject's content I want to move it to either a "Processes" or "unauthorized" folder
save the messages in an array and then move the message from the INBOX to the Proceeded folder
Here is what I have done
// 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.');
}
I read the message with no issues, but when trying to moving the message I get an error.
.[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
I think the issue is the way how I am passing the $id to the imap_mail_move
function.
I also tried to convert the message sequance number to a UID number like so $f['id'] = imap_uid($this->conn , $id )
and that did not work..
I also tried this
$imapresult = imap_mail_move($this->conn, '1:' . $id, $box);
$imapresult = imap_mail_move($this->conn, '1:' . $id, $box, CP_UID);
I even tried to copy and then delete the message and that did not work.
$imapresult = imap_mail_copy($c, '1', 'INBOX/Processed', CP_MOVE);
I can't get the message to move.
How can I correctly move the message?