Skip to content

Commit 5614529

Browse files
refactor: add new folder mappings
1 parent c123a03 commit 5614529

File tree

2 files changed

+78
-107
lines changed

2 files changed

+78
-107
lines changed

src/Mail/Client/Imap/Util/DefaultFolderIdToTypeMapper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ public function getFolderType(ListMailFolder $listMailFolder): string
102102
// +------------------
103103
// | INBOX
104104
// +------------------
105-
case "[GOOGLE MAIL]/ALLE NACHRICHTEN":
106-
case "[GMAIL]/ALLE NACHRICHTEN":
105+
case "POSTEINGANG":
107106
case "INBOX":
108107
$type = MailFolder::TYPE_INBOX;
109108
break;
@@ -113,6 +112,8 @@ public function getFolderType(ListMailFolder $listMailFolder): string
113112
// +------------------
114113
case "[GOOGLE MAIL]/PAPIERKORB":
115114
case "[GMAIL]/PAPIERKORB":
115+
case "[GOOGLE MAIL]/TRASH":
116+
case "[GMAIL]/TRASH":
116117
case "TRASH":
117118
case "JUNK-E-MAIL":
118119
case "DELETED":
@@ -131,6 +132,8 @@ public function getFolderType(ListMailFolder $listMailFolder): string
131132
// +------------------
132133
case "[GOOGLE MAIL]/ENTWÜRFE":
133134
case "[GMAIL]/ENTWÜRFE":
135+
case "[GOOGLE MAIL]/DRAFTS":
136+
case "[GMAIL]/DRAFTS":
134137
case "DRAFTS":
135138
case "DRAFT":
136139
case "ENTWÜRFE":
@@ -144,6 +147,8 @@ public function getFolderType(ListMailFolder $listMailFolder): string
144147
// +------------------
145148
case "[GOOGLE MAIL]/GESENDET":
146149
case "[GMAIL]/GESENDET":
150+
case "[GOOGLE MAIL]/SENT":
151+
case "[GMAIL]/SENT":
147152
case "GESENDETE ELEMENTE":
148153
case "GESENDET":
149154
case "SENT":

tests/Mail/Client/Imap/Util/DefaultFolderIdToTypeMapperTest.php

Lines changed: 71 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -64,149 +64,133 @@ public function testGetFolderType()
6464
$this->createListMailFolder("Entwürfe", "/")
6565
));
6666

67+
// +--------------------
68+
// | INBOX
69+
// +-------------------
6770
$this->assertSame(
68-
$mapper->getFolderType(
69-
$this->createListMailFolder("SomeRandomFolder/Draft", "/")
70-
),
71-
MailFolder::TYPE_FOLDER
72-
);
73-
$this->assertSame(
74-
$mapper->getFolderType(
75-
$this->createListMailFolder("SomeRandomFolder/Draft/Test", "/")
76-
),
77-
MailFolder::TYPE_FOLDER
71+
MailFolder::TYPE_INBOX,
72+
$mapper->getFolderType($this->createListMailFolder("INBOX", ".")),
7873
);
7974
$this->assertSame(
80-
$mapper->getFolderType(
81-
$this->createListMailFolder("SomeRandom", ".")
82-
),
83-
MailFolder::TYPE_FOLDER
75+
MailFolder::TYPE_INBOX,
76+
$mapper->getFolderType($this->createListMailFolder("POSTEINGANG", ".")),
8477
);
78+
79+
// DRAFTS
8580
$this->assertSame(
86-
$mapper->getFolderType(
87-
$this->createListMailFolder("INBOX", ".")
88-
),
89-
MailFolder::TYPE_INBOX
81+
MailFolder::TYPE_DRAFT,
82+
$mapper->getFolderType($this->createListMailFolder("INBOX.Drafts", "."))
83+
9084
);
9185
$this->assertSame(
92-
$mapper->getFolderType(
93-
$this->createListMailFolder("INBOX/Somefolder/Deep/Drafts", "/")
94-
),
95-
MailFolder::TYPE_FOLDER
86+
MailFolder::TYPE_DRAFT,
87+
$mapper->getFolderType($this->createListMailFolder("INBOX-DRAFTS", "-"))
9688
);
9789
$this->assertSame(
98-
$mapper->getFolderType(
99-
$this->createListMailFolder("INBOX.Drafts", ".")
100-
),
101-
MailFolder::TYPE_DRAFT
90+
MailFolder::TYPE_DRAFT,
91+
$mapper->getFolderType($this->createListMailFolder("Draft", "-"))
10292
);
10393
$this->assertSame(
104-
$mapper->getFolderType(
105-
$this->createListMailFolder("INBOX.Trash.Deep.Deeper.Folder", ".")
106-
),
107-
MailFolder::TYPE_FOLDER
94+
MailFolder::TYPE_DRAFT,
95+
$mapper->getFolderType($this->createListMailFolder("Entwurf", "/"))
10896
);
10997

98+
99+
// TRASH
110100
$this->assertSame(
111-
$mapper->getFolderType(
112-
$this->createListMailFolder("Junk/Draft", "/")
113-
),
114-
MailFolder::TYPE_FOLDER
115-
);
116-
$this->assertSame(
117-
$mapper->getFolderType(
118-
$this->createListMailFolder("TRASH.Draft.folder", ".")
119-
),
120-
MailFolder::TYPE_FOLDER
121-
);
122-
$this->assertSame(
123-
$mapper->getFolderType(
124-
$this->createListMailFolder("TRASH", "/")
125-
),
101+
$mapper->getFolderType($this->createListMailFolder("TRASH", "/")),
126102
MailFolder::TYPE_TRASH
127103
);
128104

129105
$this->assertSame(
130-
$mapper->getFolderType(
131-
$this->createListMailFolder("INBOX:TRASH", ":")
132-
),
106+
$mapper->getFolderType($this->createListMailFolder("INBOX:TRASH", ":")),
133107
MailFolder::TYPE_TRASH
134108
);
135-
$this->assertSame(
136-
$mapper->getFolderType(
137-
$this->createListMailFolder("INBOX-DRAFTS", "-")
138-
),
139-
MailFolder::TYPE_DRAFT
140-
);
141109

142110
$this->assertSame(
143-
$mapper->getFolderType(
144-
$this->createListMailFolder("DELETED", ":")
145-
),
111+
$mapper->getFolderType($this->createListMailFolder("DELETED", ":")),
146112
MailFolder::TYPE_TRASH
147113
);
148114

149115
$this->assertSame(
150-
MailFolder::TYPE_DRAFT,
151-
$mapper->getFolderType(
152-
$this->createListMailFolder("Draft", "-")
153-
)
116+
MailFolder::TYPE_TRASH,
117+
$mapper->getFolderType($this->createListMailFolder("DELETED MESSAGES", "."))
154118
);
155119

156120
$this->assertSame(
157-
MailFolder::TYPE_JUNK,
158-
$mapper->getFolderType(
159-
$this->createListMailFolder("Inbox.SPAMVerDacht", ".")
160-
)
121+
MailFolder::TYPE_TRASH,
122+
$mapper->getFolderType($this->createListMailFolder("GELÖSCHT", "."))
161123
);
162-
163124
$this->assertSame(
164125
MailFolder::TYPE_TRASH,
165-
$mapper->getFolderType(
166-
$this->createListMailFolder("DELETED MESSAGES", ".")
167-
)
126+
$mapper->getFolderType($this->createListMailFolder("PapIerKorb", "."))
168127
);
169128

129+
// JUNK
170130
$this->assertSame(
171-
MailFolder::TYPE_SENT,
131+
MailFolder::TYPE_JUNK,
172132
$mapper->getFolderType(
173-
$this->createListMailFolder("SENT MESSAGES", ".")
133+
$this->createListMailFolder("SPAMVerDacht", ".")
174134
)
175135
);
176136

177-
178137
$this->assertSame(
179138
MailFolder::TYPE_JUNK,
180-
$mapper->getFolderType(
181-
$this->createListMailFolder("SPAMVerDacht", ".")
182-
)
139+
$mapper->getFolderType($this->createListMailFolder("Inbox.SPAMVerDacht", "."))
183140
);
184-
185141
$this->assertSame(
186-
MailFolder::TYPE_TRASH,
187-
$mapper->getFolderType(
188-
$this->createListMailFolder("GELÖSCHT", ".")
189-
)
142+
MailFolder::TYPE_JUNK,
143+
$mapper->getFolderType($this->createListMailFolder("Spam", "-"))
190144
);
191145

146+
// SENT
192147
$this->assertSame(
193148
MailFolder::TYPE_SENT,
194-
$mapper->getFolderType(
195-
$this->createListMailFolder("Gesendet", ".")
196-
)
149+
$mapper->getFolderType($this->createListMailFolder("SENT MESSAGES", "."))
150+
);
151+
$this->assertSame(
152+
MailFolder::TYPE_SENT,
153+
$mapper->getFolderType($this->createListMailFolder("Gesendet", "."))
197154
);
198155

199156

157+
158+
// FOLDER
159+
foreach ([
160+
["SomeRandomFolder/Draft", "/"],
161+
["SomeRandomFolder/Draft/Test", "/"],
162+
["SomeRandom", "."],
163+
["INBOX/Somefolder/Deep/Drafts", "/"],
164+
["INBOX.Trash.Deep.Deeper.Folder", "."],
165+
["Junk/Draft", "/"],
166+
["TRASH.Draft.folder", "."]
167+
] as $folder) {
168+
$this->assertSame(
169+
MailFolder::TYPE_FOLDER,
170+
$mapper->getFolderType($this->createListMailFolder($folder[0], $folder[1]))
171+
);
172+
}
173+
174+
175+
// GMAIL
200176
foreach (["Google Mail", "Gmail"] as $label) {
201177
$this->assertSame(
202178
MailFolder::TYPE_SENT,
203179
$mapper->getFolderType($this->createListMailFolder("[$label]/Gesendet", "."))
204180
);
181+
$this->assertSame(
182+
MailFolder::TYPE_SENT,
183+
$mapper->getFolderType($this->createListMailFolder("[$label]/Sent", "."))
184+
);
205185
$this->assertSame(
206186
MailFolder::TYPE_DRAFT,
207187
$mapper->getFolderType($this->createListMailFolder("[$label]/Entwürfe", "."))
208188
);
209189
$this->assertSame(
190+
MailFolder::TYPE_DRAFT,
191+
$mapper->getFolderType($this->createListMailFolder("[$label]/Drafts", "."))
192+
);
193+
$this->assertNotSame(
210194
MailFolder::TYPE_INBOX,
211195
$mapper->getFolderType($this->createListMailFolder("[$label]/Alle Nachrichten", "."))
212196
);
@@ -218,30 +202,12 @@ public function testGetFolderType()
218202
MailFolder::TYPE_TRASH,
219203
$mapper->getFolderType($this->createListMailFolder("[$label]/Papierkorb", "."))
220204
);
205+
$this->assertSame(
206+
MailFolder::TYPE_TRASH,
207+
$mapper->getFolderType($this->createListMailFolder("[$label]/Trash", "."))
208+
);
221209
}
222210

223-
224-
$this->assertSame(
225-
MailFolder::TYPE_TRASH,
226-
$mapper->getFolderType(
227-
$this->createListMailFolder("PapIerKorb", ".")
228-
)
229-
);
230-
231-
$this->assertSame(
232-
MailFolder::TYPE_DRAFT,
233-
$mapper->getFolderType(
234-
$this->createListMailFolder("Entwurf", "/")
235-
)
236-
);
237-
238-
$this->assertSame(
239-
MailFolder::TYPE_JUNK,
240-
$mapper->getFolderType(
241-
$this->createListMailFolder("Spam", "-")
242-
)
243-
);
244-
245211
}
246212

247213

0 commit comments

Comments
 (0)