Skip to content

Commit d518fac

Browse files
fix
1 parent 7b3a077 commit d518fac

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115

116116
## Gmail OAuth
117117

118-
Scope:
118+
Scope: https://mail.google.com/
119119

120120
## Reference
121121

src/Connection.php

+27
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Connection
2727
protected $sslMode;
2828
protected $currentMailbox;
2929
protected $connected;
30+
protected $registry;
3031

3132
/**
3233
*
@@ -248,4 +249,30 @@ public static function isValid($imap)
248249
{
249250
return is_a($imap, Connection::class) && $imap->isConnected();
250251
}
252+
253+
public function setRegistryValue($space, $item, $key, $value)
254+
{
255+
if (empty($this->registry)) {
256+
$this->registry = [];
257+
}
258+
259+
if (empty($this->registry[$space])) {
260+
$this->registry[$space] = [];
261+
}
262+
263+
if (empty($this->registry[$space][$item])) {
264+
$this->registry[$space][$item] = [];
265+
}
266+
267+
$this->registry[$space][$item][$key] = $value;
268+
}
269+
270+
public function getRegistryValue($space, $item, $key)
271+
{
272+
if (isset($this->registry[$space][$item][$key])) {
273+
return $this->registry[$space][$item][$key];
274+
}
275+
276+
return false;
277+
}
251278
}

src/ImapClient.php

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ImapClient
7575
const COMMAND_CAPABILITY = 2;
7676
const COMMAND_LASTLINE = 4;
7777
const COMMAND_ANONYMIZED = 8;
78+
const COMMAND_RAW_LASTLINE = 16;
7879

7980
const DEBUG_LINE_LENGTH = 4098; // 4KB + 2B for \r\n
8081

@@ -3801,6 +3802,11 @@ public function execute($command, $arguments = array(), $options = 0, $filter =
38013802
$response = preg_replace("/^$tag (OK|NO|BAD|BYE|PREAUTH)?\s*(\[[a-z-]+\])?\s*/i", '', trim($line));
38023803
}
38033804

3805+
// return raw last line only (without command tag, result and response code)
3806+
if ($line && ($options & self::COMMAND_RAW_LASTLINE)) {
3807+
$response = preg_replace("/^$tag (OK|NO|BAD|BYE|PREAUTH)?\s*/i", '', trim($line));
3808+
}
3809+
38043810
return $noresp ? $code : array($code, $response);
38053811
}
38063812

src/Mailbox.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,16 @@ public static function deleteMailbox($imap, $mailbox)
269269
$mailbox = (string) \preg_replace('/^{.+}/', '', $mailbox);
270270
}
271271

272-
$result = $client->execute('DELETE', array($client->escape($mailbox)), ImapClient::COMMAND_LASTLINE);
272+
$result = $client->execute('DELETE', array($client->escape($mailbox)), ImapClient::COMMAND_RAW_LASTLINE);
273273

274274
$success = $result[0] == ImapClient::ERROR_OK;
275275

276-
if (!$success) {
276+
if (!$success && $imap->getRegistryValue('mailbox', $mailbox, 'deleted')) {
277+
Errors::appendError($result[1]);
278+
} elseif (!$success) {
277279
Errors::appendError("Can't delete mailbox {$mailbox}: no such mailbox");
280+
} else {
281+
$imap->setRegistryValue('mailbox', $mailbox, 'deleted', true);
278282
}
279283

280284
return $success;

tests/CompatibilityTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,23 @@ public function testDeleteMailbox()
366366
$this->assertEquals($imapAlerts1, $imapAlerts2);
367367
$this->assertEquals($imapErrors1, $imapErrors2);
368368

369+
$newMailboxName1 = uniqid('new-mailbox-');
370+
imap_createmailbox($imap1, $this->mailbox.$newMailboxName1);
371+
imap_deletemailbox($imap1, $this->mailbox.$newMailboxName1);
372+
imap_deletemailbox($imap1, $this->mailbox.$newMailboxName1);
373+
$imapAlerts1 = imap_alerts();
374+
$imapErrors1 = imap_errors();
375+
376+
$newMailboxName2 = uniqid('new-mailbox-');
377+
imap2_createmailbox($imap2, $this->mailbox.$newMailboxName2);
378+
imap2_deletemailbox($imap2, $this->mailbox.$newMailboxName2);
379+
imap2_deletemailbox($imap2, $this->mailbox.$newMailboxName2);
380+
$imapAlerts2 = imap2_alerts();
381+
$imapErrors2 = imap2_errors();
382+
383+
$this->assertEquals($imapAlerts1, $imapAlerts2);
384+
$this->assertEquals($imapErrors1, $imapErrors2);
385+
369386
imap_close($imap1);
370387
imap2_close($imap2);
371388
}

0 commit comments

Comments
 (0)