Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/Connection/ImapConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
use DirectoryTree\ImapEngine\Connection\Streams\StreamInterface;
use DirectoryTree\ImapEngine\Connection\Tokens\Token;
use DirectoryTree\ImapEngine\Enums\ImapFetchIdentifier;
use DirectoryTree\ImapEngine\Exceptions\Exception;
use DirectoryTree\ImapEngine\Exceptions\ImapCommandException;
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionClosedException;
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionFailedException;
use DirectoryTree\ImapEngine\Exceptions\ImapConnectionTimedOutException;
use DirectoryTree\ImapEngine\Exceptions\ImapResponseException;
use DirectoryTree\ImapEngine\Exceptions\ImapStreamException;
use DirectoryTree\ImapEngine\Support\Str;
use Exception;
use Generator;
use LogicException;

Expand Down Expand Up @@ -69,8 +69,14 @@ public static function fake(array $responses = []): static
*/
public function __destruct()
{
if ($this->connected()) {
$this->logout();
if (! $this->connected()) {
return;
}

try {
@$this->logout();
} catch (Exception $e) {
// Do nothing.
}
}

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

/**
Expand Down
13 changes: 8 additions & 5 deletions src/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DirectoryTree\ImapEngine\Connection\Loggers\FileLogger;
use DirectoryTree\ImapEngine\Connection\Streams\ImapStream;
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
use Exception;

class Mailbox implements MailboxInterface
{
Expand Down Expand Up @@ -167,12 +168,14 @@ protected function authenticate(): void
*/
public function disconnect(): void
{
if ($this->connected()) {
$this->connection->logout();
$this->connection->disconnect();
try {
$this->connection?->logout();
$this->connection?->disconnect();
} catch (Exception) {
// Do nothing.
} finally {
$this->connection = null;
}

$this->connection = null;
}

/**
Expand Down