php-imap
php-imap copied to clipboard
Message Move and Copy doesn't work with subfolders
If your inbox structure has INBOX\Archive or Test\Sub and you try moving or copying an email from INBOX->Archive or TEST->Sub it fails with the following error:
Fatal error: Uncaught Webklex\PHPIMAP\Exceptions\ResponseException: Command failed to process: Causes: - request failed - Empty response Error occurred in /var/www/html/assets/vendor/webklex/php-imap/src/Exceptions/ResponseException.php:53 Stack trace: #0 /var/www/html/assets/vendor/webklex/php-imap/src/Connection/Protocols/Response.php(318): Webklex\PHPIMAP\Exceptions\ResponseException::make() #1 /var/www/html/assets/vendor/webklex/php-imap/src/Connection/Protocols/Response.php(308): Webklex\PHPIMAP\Connection\Protocols\Response->validate() #2 /var/www/html/assets/vendor/webklex/php-imap/src/Client.php(669): Webklex\PHPIMAP\Connection\Protocols\Response->validatedData() #3 /var/www/html/assets/vendor/webklex/php-imap/src/Message.php(1108): Webklex\PHPIMAP\Client->openFolder() #4 /var/www/html/cron.inbox.php(148): Webklex\PHPIMAP\Message->move() #5 /var/www/html/cron.inbox.php(75): processMailbox() #6 {main} thrown in /var/www/html/assets/vendor/webklex/php-imap/src/Exceptions/ResponseException.php on line 53
If you try moving between top-level folders (e.g. INBOX to Test) it works as expected.
Note that you CAN read the folder structure of these subfolders (checked to make sure delimiter \ was correct) AND you can read messages in these subfolders (only tested getting From address and Subject line). It is just moving and copying to them that fails.
Used config Default config.
- OS: Alma Linux 8
- PHP: 8.0
- Version: 5.2.0
- Provider: Microsoft 365 (corporate) using oauth
Hi @tiamatloc , thanks a lot for your report. I had a similar situation not so long ago - it turned out to be a read only folder (only folders inside the "INBOX" were writable).
If you are sure it's not "read only" but something else, please provide some code or even better a test case in order to replicate the behavior.
Best regards and happy coding,
Hi @Webklex,
It turns out that I'm an idiot! Even though I did use $client->getFolders(false) to dump a folder list and check the delimiter at the time my brain must have transposed / to \ (which is what it was before switching to your IMAP client). Writing up some code for you and dumping the folders before attempting to move showed that / is actually the delimiter and using that allows me to move the emails.
Sorry to waste your time!