php-imap
php-imap copied to clipboard
Rename folder
I'm trying to rename folders and I have a strange error.
This is my test folder tree:
- folder 1 (rename ok)
- folder 2 (rename ok) -- folder 3 (rename error)
You can see that the folders "folder 1" and "folder 2" are in the root and the folder "folder 3" is inside "folder 2".
The problem is that I can rename the folders "folder 1" and "folder 2" without a problem. But when I try to rename the folder "folder 3" it gives an error.
The path of the folder "folder 2" is "INBOX. folder 2". When trying to rename the folder "folder 3" its path would be "INBOX.folder 2.test".
I have the same problem when I tried to move a folder inside another folder.
The strange thing about it is that both renaming and moving do it on the server, but it returns an error.
This is the error _TypeError: Cannot assign null to property Webklex\PHPIMAP\Events\FolderMovedEvent::$new_folder of type Webklex\PHPIMAP\Folder in file /var/www/html/Plugins/MultiEmail/vendor/webklex/php-imap/src/Events/ FolderMovedEvent.php on line 38 Stack trace:
- TypeError->() /var/www/html/Plugins/MultiEmail/vendor/webklex/php-imap/src/Events/FolderMovedEvent.php:38
- Webklex\PHPIMAP\Events\FolderMovedEvent->__construct() /var/www/html/Plugins/MultiEmail/vendor/webklex/php-imap/src/Events/Event.php:26
- Webklex\PHPIMAP\Events\Event->dispatch() /var/www/html/Plugins/MultiEmail/vendor/webklex/php-imap/src/Folder.php:291
- Webklex\PHPIMAP\Folder->move() /var/www/html/Plugins/MultiEmail/vendor/webklex/php-imap/src/Folder.php:362
- Webklex\PHPIMAP\Folder->rename() /var/www/html/Plugins/MultiEmail/Controller/InboxEmail.php:470
- InvoiceScripts\Plugins\MultiEmail\Controller\InboxEmail->renameFolderAction() /var/www/html/Plugins/MultiEmail/Controller/InboxEmail.php:68
- InvoiceScripts\Plugins\MultiEmail\Controller\InboxEmail->privateCore() /var/www/html/Core/App/AppController.php:187
- InvoiceScripts\Core\App\AppController->loadController() /var/www/html/Core/App/AppDebugController.php:56
- InvoiceScripts\Core\App\AppDebugController->loadController() /var/www/html/Core/App/AppController.php:110
- InvoiceScripts\Core\App\AppController->run() /var/www/html/index.php:93_
My code looks like this:
$currentFolder = $this->client->getFolderByPath('INBOX.folder 2.folder 3');
$path = explode($currentFolder->delimiter, $currentFolder->path);
$path[count($path) - 1] = 'test';
$newPath = implode($currentFolder->delimiter, $path);
$currentFolder->rename(newPath, false);
Any help please? Thank you.
If I use the move() or rename() functions it gives an error. However, if I use the following code it works correctly.
$this->client->getConnection()->renameFolder($currentFolder->full_name, $newPath)->validatedData();