Skip to content

Commit 544af1a

Browse files
fix: allow for empty roots in configuration to properly display flat mailbox hierarchies
refs #9
1 parent 4d572a7 commit 544af1a

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

app/Conjoon/Mail/Client/Folder/Tree/DefaultMailFolderTreeBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function listToTree(MailFolderList $mailFolderList, array $root) :MailFol
111111
$systemFolderTypes[] = $folderType;
112112
}
113113

114-
$parentKey = implode($mailbox->getDelimiter(), $parts);
114+
$parentKey = implode($mailbox->getDelimiter(), $parts) ?: "*";
115115
if (!isset($folders[$parentKey])) {
116116
$folders[$parentKey] = [];
117117
}
@@ -207,7 +207,7 @@ protected function shouldSkipMailFolder(ListMailFolder $listMailFolder, array $r
207207
}
208208
}
209209
}
210-
if ($skip === count($root)) {
210+
if (count($root) && $skip === count($root)) {
211211
return true;
212212
}
213213

tests/app/Conjoon/Mail/Client/Folder/Tree/DefaultMailFolderTreeBuilderTest.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
/**
33
* conjoon
4-
* php-ms-imapuser
5-
* Copyright (C) 2019-2021 Thorsten Suckow-Homberg https://github.com/conjoon/php-ms-imapuser
4+
* php-cn_imapuser
5+
* Copyright (C) 2019 Thorsten Suckow-Homberg https://github.com/conjoon/php-cn_imapuser
66
*
77
* Permission is hereby granted, free of charge, to any person
88
* obtaining a copy of this software and associated documentation
@@ -52,6 +52,38 @@ public function testInstance() {
5252
}
5353

5454

55+
/**
56+
* Tests listToTre
57+
*/
58+
public function testListToTree_Entwürfe() {
59+
60+
$builder = $this->createBuilder();
61+
62+
$mailFolderList = $this->createMailFolderList(
63+
["Entwürfe",
64+
"Gelöschte Elemente"]
65+
);
66+
67+
$mailFolderChildList = $builder->listToTree($mailFolderList, [""]);
68+
69+
$this->assertSame(1, count($mailFolderChildList));
70+
71+
$mailFolder = $mailFolderChildList[0];
72+
$this->assertSame("Entwürfe", $mailFolder->getName());
73+
$this->assertSame("Entwürfe", $mailFolder->getFolderKey()->getId());
74+
$this->assertSame(MailFolder::TYPE_DRAFT, $mailFolder->getFolderType());
75+
$children = $mailFolder->getData();
76+
$this->assertSame(0, count($children));
77+
78+
$drafts = $mailFolderChildList[1];
79+
$this->assertSame("Gelöschte Elemente", $drafts->getName());
80+
$this->assertSame("Gelöschte Elemente", $drafts->getFolderKey()->getId());
81+
$this->assertSame(MailFolder::TYPE_TRASH, $drafts->getFolderType());
82+
$children = $drafts->getData();
83+
$this->assertSame(0, count($children));
84+
}
85+
86+
5587
/**
5688
* Tests listToTre
5789
*/

0 commit comments

Comments
 (0)