Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move, delete and get new #587

Open
nico-martin opened this issue Dec 25, 2024 · 1 comment
Open

move, delete and get new #587

nico-martin opened this issue Dec 25, 2024 · 1 comment

Comments

@nico-martin
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
@nico-martin and others