Skip to content

Commit 19cf949

Browse files
committed
MailboxConnectionException
1 parent b919f00 commit 19cf949

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Domain\Common\Exception;
6+
7+
use RuntimeException;
8+
use Throwable;
9+
10+
class MailboxConnectionException extends RuntimeException
11+
{
12+
public function __construct(string $mailbox, ?string $message = null, ?Throwable $previous = null)
13+
{
14+
if ($message === null) {
15+
$message = sprintf(
16+
'Cannot open mailbox "%s": %s',
17+
$mailbox,
18+
imap_last_error() ?: 'unknown error'
19+
);
20+
}
21+
parent::__construct($message, 0, $previous);
22+
}
23+
}

src/Domain/Common/Mail/NativeImapMailReader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use DateTimeImmutable;
88
use IMAP\Connection;
9-
use RuntimeException;
9+
use PhpList\Core\Domain\Common\Exception\MailboxConnectionException;
1010

1111
class NativeImapMailReader
1212
{
@@ -24,7 +24,7 @@ public function open(string $mailbox, int $options = 0): Connection
2424
$link = imap_open($mailbox, $this->username, $this->password, $options);
2525

2626
if ($link === false) {
27-
throw new RuntimeException('Cannot open mailbox: '.(imap_last_error() ?: 'unknown error'));
27+
throw new MailboxConnectionException($mailbox);
2828
}
2929

3030
return $link;

0 commit comments

Comments
 (0)