Skip to content

Commit

Permalink
fix: Mailer::send will always thrown an exception in case of errors d…
Browse files Browse the repository at this point in the history
…uring delivery
  • Loading branch information
DeepDiver1975 committed Nov 13, 2023
1 parent 0634d9f commit ad2bb6d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
6 changes: 1 addition & 5 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,8 @@ public function schedule(ITip\Message $iTipMessage) {
->setSubject($subject)
->attach($iTipMessage->message->serialize(), "event.ics", $contentType);
try {
$failed = $this->mailer->send($message);
$this->mailer->send($message);
$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
if ($failed) {
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => \implode(', ', $failed)]);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
}
} catch (\Exception $ex) {
$this->logger->logException($ex, ['app' => 'dav']);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
Expand Down
10 changes: 0 additions & 10 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ public function testFailedDeliveryWithException(): void {
$this->assertIMipState($message, '5.0', 'REQUEST', 'Fellowship meeting');
}

public function testFailedDelivery(): void {
$this->mailer->method('send')->willReturn(['foo@example.net']);
$this->logger->expects(self::once())->method('error')->with('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => 'foo@example.net']);

$message = $this->buildIMIPMessage('REQUEST');

$this->plugin->schedule($message);
$this->assertIMipState($message, '5.0', 'REQUEST', 'Fellowship meeting');
}

public function testDeliveryOfCancel(): void {
$this->mailer->expects($this->once())->method('send');

Expand Down
7 changes: 4 additions & 3 deletions lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public function send(Message $message): array {
try {
$this->getInstance($logger ?? null)->send($message->getMessage());
} catch (TransportExceptionInterface $e) {
$this->logger->logException($e);

# in case of exception it is expected that none of the mails has been sent
$failedRecipients = [];

Expand All @@ -111,7 +109,10 @@ public function send(Message $message): array {
}
});

return $failedRecipients;
$this->logger->logException($e, ['failed-recipients' => $recipients]);

# list of failed recipients is not added by intention to not accidentally disclose private data
throw new \RuntimeException("Failed to deliver email", 0, $e);
}

$allRecipients = [];
Expand Down
19 changes: 5 additions & 14 deletions settings/Controller/MailSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,12 @@ public function sendTestMail() {
$message->setFrom([$this->defaultMailAddress]);
$message->setSubject($this->l10n->t('test email settings'));
$message->setPlainBody('If you received this email, the settings seem to be correct.');
$failed = $this->mailer->send($message);
if (empty($failed)) {
return ['data' =>
['message' =>
(string) $this->l10n->t('Email sent')
],
'status' => 'success'
];
}

return [
'data' => [
'message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', ['not delivered']),
$this->mailer->send($message);
return ['data' =>
['message' =>
(string) $this->l10n->t('Email sent')
],
'status' => 'error',
'status' => 'success'
];
} catch (\Exception $e) {
return [
Expand Down

0 comments on commit ad2bb6d

Please sign in to comment.