Webklex / php-imap

PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled. The protocol is completely integrated and therefore supports IMAP IDLE operation and the "new" oAuth authentication process as well.
https://www.php-imap.com
MIT License
315 stars 149 forks source link

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

Open nhatlinhle opened 3 years ago

nhatlinhle commented 3 years ago

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!

zssarkany commented 3 years ago

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:

nhatlinhle commented 3 years ago

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!

freescout-help commented 1 week ago

We are also facing the problem with move command on some mail servers: https://github.com/freescout-help-desk/freescout/issues/4313#issuecomment-2461184774

Can the suggested here https://stackoverflow.com/a/15816045 approach (UID COPY, UID STORE and UID EXPUNGE) be used in Weklex PHP-IMAP as a fallback when MOVE is not supported by the mail server?

freescout-help commented 1 week ago

Here is the fix: https://github.com/freescout-help-desk/freescout/commit/fc7f4bfc358fa0a11879115089828ff6846cbd53