I have a function that should move an Email to a new folder, deletes the email in the current folder and then returns the new Email:
function emailMove(MessageInterface $mail, string $newFolder): MessageInterface
{
$mailId = $mail->getId();
$mailbox = $this->connection->getMailbox($newFolder);
$mail->move($mailbox);
$mail->delete();
$this->connection->expunge();
$messages = $mailbox->getMessages(
new RawExpression(
sprintf('TEXT "Message-ID: %s"', $mailId)
)
);
$newMessageId = $messages[0] ?? null;
if (!$newMessageId) {
throw new Error('error', 'Email not moved');
}
$this->folder = $newFolder;
return $mailbox->getMessage($newMessageId);
}
The problem is that the way to search the email by Message-ID does not seem to be very reliable. For example it does not work if the änewFolder is the trash.
Is there a better way?
I have a function that should move an Email to a new folder, deletes the email in the current folder and then returns the new Email:
The problem is that the way to search the email by Message-ID does not seem to be very reliable. For example it does not work if the änewFolder is the trash.
Is there a better way?