php-imap
php-imap copied to clipboard
Children/subfolders is empty but hasChildren is true
Describe the bug
$folder->getChildren()->total() is 0
Used config See code to reproduce (maybe I'm doing something wrong?)
Code to Reproduce The troubling code section which produces the reported bug.
$cm = new ClientManager([
'accounts' => [
'myaccount' => [
'host' => 'myhost.com',
'port' => 993,
'protocol' => 'imap',
'encryption' => 'ssl',
'username' => 'myusername',
'password' => 'mypassword',
]
]
]);
$client = $cm->account('myaccount');
$folder = $client->getFolder('TestFolder');
var_dump($folder->hasChildren()); // bool(true)
var_dump($folder->getChildren()->total()); // int(0) <-- bug?
Expected behavior
In my case I expect var_dump($folder->getChildren()->total()); to be int(1)
Desktop / Server (please complete the following information):
- OS: Linux Server Debian
- PHP: 8.2.10 (fpm)
- Provider: Gmail / Mailcow
Hello again,
After looking into the source code, I realize why the expected results is "wrong".
The $client->getFolder(...) method calls getFolders(false, ...)
so I managed to make a "workaround" to get what I need like this:
$folders = $client->getFolders(true, 'TestFolder');
$folder = $folders->first();
var_dump($folder->getChildren()->all());
Resulting in:
array(1) {
[0]=>
object(Webklex\PHPIMAP\Folder)#860 (12) {
...
But although I now managed to get a list of subfolders and var_dump($folder->getChildren()); gives me this:
object(Webklex\PHPIMAP\Support\FolderCollection)#918 (3) {
["items":protected]=>
array(1) {
[0]=>
object(Webklex\PHPIMAP\Folder)#919 (12) {
The var_dump($folder->getChildren()->total()); still gives me:
int(0)