Skip to content

[Bug] Get folders list in hierarchical order (BAD Could not parse command) #560

@rskrzypczak

Description

@rskrzypczak

Describe the bug
The problem is the folder name encoding.
if the subdirectory contains a folder with some special character, Gmail may not accept it and return an error.
That's why folder paths should always be utf7-imap.
I'll add that some mail servers can handle this, but as you can see Gmail can't :)

Used config
default

Code to Reproduce
The troubling code section which produces the reported bug.

$client = $this->getClient();
$client->connect();
$folders = $client->getFolders(true); // hierarchical

debug result

>> TAG12 LIST "" "[Gmail]/%%"

<< * LIST (\HasNoChildren \Trash) "/" "[Gmail]/Kosz"
<< * LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam"
<< * LIST (\HasChildren \Important) "/" "[Gmail]/Wa&AXw-ne"
<< TAG12 OK Success
>> TAG13 NOOP

<< TAG13 OK Success
>> TAG14 LIST "" "[Gmail]/Ważne/%%"

<< TAG14 BAD Could not parse command

Expected behavior
The folder hierarchy should be returned, without error.

Desktop / Server (please complete the following information):

  • PHP: 8.3
  • Version: 6.1.0
  • Provider: Gmail

Solution:
in src\Client.php:607 replace full_name to path

if ($hierarchical && $folder->hasChildren()) {
    $pattern = $folder->path.$folder->delimiter.'%'; // here

    $children = $this->getFoldersWithStatus(true, $pattern, true);
    $folder->setChildren($children);
}

after that I get:

>> TAG12 LIST "" "[Gmail]/%%"

<< * LIST (\HasNoChildren \Trash) "/" "[Gmail]/Kosz"
<< * LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam"
<< * LIST (\HasChildren \Important) "/" "[Gmail]/Wa&AXw-ne"
<< TAG12 OK Success
>> TAG13 NOOP

<< TAG13 OK Success
>> TAG14 LIST "" "[Gmail]/Wa&AXw-ne/%%"

<< * LIST (\HasChildren) "/" "[Gmail]/Wa&AXw-ne/Hitachi"
<< TAG14 OK Success

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions