Skip to content

Commit 71ed073

Browse files
committed
Prevent exceptions or warnings upon destruct
1 parent 44a211d commit 71ed073

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/Connection/ImapConnection.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use DirectoryTree\ImapEngine\Connection\Streams\StreamInterface;
1515
use DirectoryTree\ImapEngine\Connection\Tokens\Token;
1616
use DirectoryTree\ImapEngine\Enums\ImapFetchIdentifier;
17-
use DirectoryTree\ImapEngine\Exceptions\Exception;
1817
use DirectoryTree\ImapEngine\Exceptions\ImapCommandException;
1918
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionClosedException;
2019
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionFailedException;
2120
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionTimedOutException;
2221
use DirectoryTree\ImapEngine\Exceptions\ImapResponseException;
2322
use DirectoryTree\ImapEngine\Exceptions\ImapStreamException;
2423
use DirectoryTree\ImapEngine\Support\Str;
24+
use Exception;
2525
use Generator;
2626
use LogicException;
2727

@@ -69,8 +69,14 @@ public static function fake(array $responses = []): static
6969
*/
7070
public function __destruct()
7171
{
72-
if ($this->connected()) {
73-
$this->logout();
72+
if (! $this->connected()) {
73+
return;
74+
}
75+
76+
try {
77+
@$this->logout();
78+
} catch (Exception $e) {
79+
// Do nothing.
7480
}
7581
}
7682

@@ -182,14 +188,7 @@ public function login(string $user, string $password): TaggedResponse
182188
*/
183189
public function logout(): void
184190
{
185-
try {
186-
// It's generally acceptable to send a logout command to an IMAP server
187-
// and not wait for a response. If the server encounters an error
188-
// processing the request, we will have to reconnect anyway.
189-
$this->send('LOGOUT', tag: $tag);
190-
} catch (Exception) {
191-
// Do nothing.
192-
}
191+
$this->send('LOGOUT', tag: $tag);
193192
}
194193

195194
/**

0 commit comments

Comments
 (0)