Skip to content

Commit 7a99709

Browse files
fix
1 parent 3ab5a77 commit 7a99709

File tree

5 files changed

+80
-3
lines changed

5 files changed

+80
-3
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ test-ping:
8383
test-get-mailboxes:
8484
@docker-compose run --rm phpunit tests --filter CompatibilityTest::testGetMailboxes
8585

86+
test-delete-mailbox:
87+
@docker-compose run --rm phpunit tests --filter CompatibilityTest::testDeleteMailbox
88+
8689
test-xoauth:
8790
@docker-compose run --rm phpunit tests --filter XoauthTest
8891

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113
- [ ] imap_timeout
114114
- [ ] imap_undelete
115115

116+
## Gmail OAuth
117+
118+
Scope:
119+
116120
## Reference
117121

118122
- <https://www.atmail.com/blog/imap-commands/>

src/Errors.php

+32-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,44 @@
1515

1616
class Errors
1717
{
18+
protected static $alerts = [];
19+
20+
protected static $errors = [];
21+
22+
public static function appendAlert($alert)
23+
{
24+
self::$alerts[] = $alert;
25+
}
26+
27+
public static function appendError($error)
28+
{
29+
self::$errors[] = $error;
30+
}
31+
1832
public static function alerts()
1933
{
20-
return false;
34+
if (empty(self::$alerts)) {
35+
return false;
36+
}
37+
38+
$return = self::$alerts;
39+
40+
self::$alerts = [];
41+
42+
return $return;
2143
}
2244

2345
public static function errors()
2446
{
25-
return false;
47+
if (empty(self::$errors)) {
48+
return false;
49+
}
50+
51+
$return = self::$errors;
52+
53+
self::$errors = [];
54+
55+
return $return;
2656
}
2757

2858
public static function lastError()

src/Mailbox.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,21 @@ public static function deleteMailbox($imap, $mailbox)
264264
}
265265

266266
$client = $imap->getClient();
267+
$client->setDebug(true);
267268

268-
return $client->deleteFolder($mailbox);
269+
if ($mailbox[0] == '{') {
270+
$mailbox = (string) \preg_replace('/^{.+}/', '', $mailbox);
271+
}
272+
273+
$result = $client->execute('DELETE', array($client->escape($mailbox)), ImapClient::COMMAND_LASTLINE);
274+
275+
$success = $result[0] == ImapClient::ERROR_OK;
276+
277+
if (empty($success)) {
278+
Errors::appendError("Can't delete mailbox {$mailbox}: no such mailbox");
279+
}
280+
281+
return $success;
269282
}
270283

271284
/**

tests/CompatibilityTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,33 @@ public function testCreateMailbox()
343343
imap2_close($imap2);
344344
}
345345

346+
public function testDeleteMailbox()
347+
{
348+
$imap1 = imap_open($this->mailbox, $this->username, $this->password);
349+
$imap2 = imap2_open($this->mailbox, $this->username, $this->accessToken, OP_XOAUTH2);
350+
351+
// Reset error buffers
352+
imap_alerts();
353+
imap_errors();
354+
imap2_alerts();
355+
imap2_errors();
356+
357+
$unknownMailbox = 'the-unknown-mailbox';
358+
$deleteMailbox1 = imap_deletemailbox($imap1, $unknownMailbox);
359+
$imapAlerts1 = imap_alerts();
360+
$imapErrors1 = imap_errors();
361+
$deleteMailbox2 = imap2_deletemailbox($imap2, $unknownMailbox);
362+
$imapAlerts2 = imap2_alerts();
363+
$imapErrors2 = imap2_errors();
364+
365+
$this->assertEquals($deleteMailbox1, $deleteMailbox2);
366+
$this->assertEquals($imapAlerts1, $imapAlerts2);
367+
$this->assertEquals($imapErrors1, $imapErrors2);
368+
369+
imap_close($imap1);
370+
imap2_close($imap2);
371+
}
372+
346373
public function testCopy()
347374
{
348375
$imap1 = imap_open($this->mailbox, $this->username, $this->password);

0 commit comments

Comments
 (0)