From ee0ab4f028d3f8b529ec96466e66be4372a9e761 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:56:58 +0000 Subject: [PATCH 1/3] fix(mail): handle rejected verification code recipients fix(mail): handle rejected verification code recipients Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> [skip ci] --- lib/Service/MailService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index 5f24ff1d04..494c7efb9a 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -181,7 +181,7 @@ public function sendCodeToSign(string $email, string $name, string $code): void } $message->useTemplate($emailTemplate); try { - $this->mailer->send($message); + $this->sendAndCheck($message); } catch (\Exception $e) { $this->logger->error('Mail with code to sign document could not be sent: ' . $e->getMessage()); throw new LibresignException('Mail with code to sign document could not be sent', 1); From cc9bd0ff25ce3151983e09b9b2afe0b009e8825b Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:23:06 +0000 Subject: [PATCH 2/3] fix(mail): handle rejected verification-code recipients on stable34 Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- lib/Service/MailService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index 494c7efb9a..92b89c911e 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -181,7 +181,9 @@ public function sendCodeToSign(string $email, string $name, string $code): void } $message->useTemplate($emailTemplate); try { - $this->sendAndCheck($message); + if ($this->mailer->send($message) !== []) { + throw new \RuntimeException('Mail transport reported rejected recipients'); + } } catch (\Exception $e) { $this->logger->error('Mail with code to sign document could not be sent: ' . $e->getMessage()); throw new LibresignException('Mail with code to sign document could not be sent', 1); From ddc4487a99e97e67d48f9f7c4cb7d6f6600d0013 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:23:37 +0000 Subject: [PATCH 3/3] test(mail): cover verification-code recipient rejection on stable34 Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- tests/php/Unit/Service/MailServiceTest.php | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/php/Unit/Service/MailServiceTest.php b/tests/php/Unit/Service/MailServiceTest.php index 45a4d69105..0ee1bc2648 100644 --- a/tests/php/Unit/Service/MailServiceTest.php +++ b/tests/php/Unit/Service/MailServiceTest.php @@ -11,11 +11,14 @@ use OCA\Libresign\Db\File; use OCA\Libresign\Db\FileMapper; use OCA\Libresign\Db\SignRequest; +use OCA\Libresign\Exception\LibresignException; use OCA\Libresign\Service\MailService; use OCP\IAppConfig; use OCP\IL10N; use OCP\IURLGenerator; +use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; +use OCP\Mail\IMessage; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -113,4 +116,37 @@ public function testFailToSendMailToUnsignedUser():void { $actual = $this->service->notifyUnsignedUser($signRequest, 'a@b.coop'); $this->assertNull($actual); } + + public function testSendCodeToSignAcceptsSuccessfulSubmission(): void { + $template = $this->createMock(IEMailTemplate::class); + $this->mailer->method('createEMailTemplate')->willReturn($template); + $message = $this->createMock(IMessage::class); + $this->mailer->method('createMessage')->willReturn($message); + $message->expects($this->once()) + ->method('setTo') + ->with(['recipient@example.com']); + $this->mailer->expects($this->once()) + ->method('send') + ->with($message) + ->willReturn([]); + + $this->service->sendCodeToSign('recipient@example.com', '', '123456'); + } + + public function testSendCodeToSignReportsRejectedRecipients(): void { + $template = $this->createMock(IEMailTemplate::class); + $this->mailer->method('createEMailTemplate')->willReturn($template); + $message = $this->createMock(IMessage::class); + $this->mailer->method('createMessage')->willReturn($message); + $this->mailer->expects($this->once()) + ->method('send') + ->with($message) + ->willReturn(['recipient@example.com']); + $this->logger->expects($this->once())->method('error'); + + $this->expectException(LibresignException::class); + $this->expectExceptionMessage('Mail with code to sign document could not be sent'); + $this->service->sendCodeToSign('recipient@example.com', 'Recipient', '123456'); + } + }