php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

I use move() for move message to another folder, but not working.

Open nhatlinhle opened this issue 4 years ago • 6 comments

I want to move message from folder INBOX to another folder, i am try follow code:

$client->connect();
//Get all Mailboxes
/** @var \Webklex\IMAP\Support\FolderCollection $folders */
$folders = $client->getFolder('INBOX');
/** @var \Webklex\IMAP\Message $detail */
$detail = $folders->messages()->getMessageByUid($uid = $id);
// $detail->delete($expunge = true);
$message = $detail->move('TRASH');
 if ($message == true) {
      dd('Message has ben moved');
  } else {
      dd('False');
  }

but always return false. I have created folder TRASH, and i have collection folder in image: image

I am tried copy() is working, but move() is not work. Please help!

nhatlinhle avatar Apr 05 '21 09:04 nhatlinhle

Some IMAP servers don't support MOVE and UID MOVE IMAP commands, which are used by the move() method of this library. I'm currently debugging the same issue to write a highly detailed issue about this. You can try to use the legacy protocol implementation by changing 'protocol' => 'imap', to 'protocol' => 'legacy-imap', in your configuration, or you can mimic the same behavior as the legacy protocol works by copy the message to trash, and delete the original. In this case, you should think about when to expunge the original (\Deleted flagged) message. (Performance and message id considerations)

Edit: LegacyProtocol relies on imap_* PHP methods, therefore you need imap PHP extension to be installed, probably with SSL support. Check your phpinfo() first.

Edit2: I rather don't recommend using LegacyProtocol, because latest (2.5.0) version:

  • has bugs #124 #125
  • connects to server in readonly mode (see here and here)
  • unable to solve weird UID assignment problems of copied/moved messages of some mail servers (like Zimbra), because underlying raw IMAP responses are inaccessible, therefore it is impossible to get reliably the new UID provided by UIDPLUS extension

zssarkany avatar Apr 06 '21 08:04 zssarkany

Some IMAP servers don't support MOVE and UID MOVE IMAP commands, which are used by the move() method of this library. I'm currently debugging the same issue to write a highly detailed issue about this. You can try to use the legacy protocol implementation by changing 'protocol' => 'imap', to 'protocol' => 'legacy-imap', in your configuration, or you can mimic the same behavior as the legacy protocol works by copy the message to trash, and delete the original. In this case, you should think about when to expunge the original (\Deleted flagged) message. (Performance and message id considerations)

Thanks for the reply, I temporarily using copy the message to trash, and delete the original. Hope you fix it soon. Have nice day!

nhatlinhle avatar Apr 06 '21 08:04 nhatlinhle