Skip to content

Commit 0a19905

Browse files
committed
Disconnect gracefully
1 parent 71ed073 commit 0a19905

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Mailbox.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DirectoryTree\ImapEngine\Connection\Loggers\FileLogger;
99
use DirectoryTree\ImapEngine\Connection\Streams\ImapStream;
1010
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
11+
use Exception;
1112

1213
class Mailbox implements MailboxInterface
1314
{
@@ -167,12 +168,14 @@ protected function authenticate(): void
167168
*/
168169
public function disconnect(): void
169170
{
170-
if ($this->connected()) {
171-
$this->connection->logout();
172-
$this->connection->disconnect();
171+
try {
172+
$this->connection?->logout();
173+
$this->connection?->disconnect();
174+
} catch (Exception) {
175+
// Do nothing.
176+
} finally {
177+
$this->connection = null;
173178
}
174-
175-
$this->connection = null;
176179
}
177180

178181
/**

0 commit comments

Comments
 (0)