• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 20284436755

16 Dec 2025 10:14PM UTC coverage: 43.738%. First build
20284436755

Pull #6216

github

web-flow
Merge 263a8cf56 into db13f2cda
Pull Request #6216: feat: custom message for signers

5 of 67 new or added lines in 6 files covered. (7.46%)

5926 of 13549 relevant lines covered (43.74%)

5.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.05
/lib/Service/MailService.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Service;
10

11
use OCA\Libresign\Db\File;
12
use OCA\Libresign\Db\FileMapper;
13
use OCA\Libresign\Db\SignRequest;
14
use OCA\Libresign\Exception\LibresignException;
15
use OCP\IAppConfig;
16
use OCP\IL10N;
17
use OCP\IURLGenerator;
18
use OCP\Mail\IMailer;
19
use Psr\Log\LoggerInterface;
20

21
class MailService {
22
        /** @var array */
23
        private $files = [];
24

25
        public function __construct(
26
                private LoggerInterface $logger,
27
                private IMailer $mailer,
28
                private FileMapper $fileMapper,
29
                private IL10N $l10n,
30
                private IURLGenerator $urlGenerator,
31
                private IAppConfig $appConfig,
32
        ) {
33
        }
49✔
34

35
        /**
36
         * @psalm-suppress MixedReturnStatement
37
         */
38
        private function getFileById(int $fileId): File {
39
                if (!isset($this->files[$fileId])) {
15✔
40
                        $this->files[$fileId] = $this->fileMapper->getById($fileId);
15✔
41
                }
42
                return $this->files[$fileId];
15✔
43
        }
44

45
        /**
46
         * @psalm-suppress MixedMethodCall
47
         */
48
        public function notifySignDataUpdated(SignRequest $data, string $email, ?string $description = null): void {
49
                $emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
×
50
                // TRANSLATORS The subject of the email that is sent after changes are made to the signature request that may affect something for the signer who will sign the document. Some possible reasons: URL for signature changed (when the URL expires), the person who requested the signature sent a notification
51
                $emailTemplate->setSubject($this->l10n->t('LibreSign: Changes into a file for you to sign'));
×
52
                $emailTemplate->addHeader();
×
53
                $emailTemplate->addHeading($this->l10n->t('File to sign'), false);
×
54

NEW
55
                if (!empty($description)) {
×
NEW
56
                        $emailTemplate->addBodyText($description);
×
NEW
57
                        $emailTemplate->addBodyText('');
×
58
                }
59

60
                $emailTemplate->addBodyText($this->l10n->t('Changes have been made in a file that you have to sign. Access the link below:'));
×
61
                $link = $this->urlGenerator->linkToRouteAbsolute('libresign.page.sign', ['uuid' => $data->getUuid()]);
×
62
                $file = $this->getFileById($data->getFileId());
×
63
                $emailTemplate->addBodyButton(
×
64
                        $this->l10n->t('Sign »%s«', [$file->getName()]),
×
65
                        $link
×
66
                );
×
67
                $message = $this->mailer->createMessage();
×
68
                if ($data->getDisplayName()) {
×
69
                        $message->setTo([$email => $data->getDisplayName()]);
×
70
                } else {
71
                        $message->setTo([$email]);
×
72
                }
73
                $message->useTemplate($emailTemplate);
×
74
                try {
75
                        $this->mailer->send($message);
×
76
                } catch (\Exception $e) {
×
77
                        $this->logger->error('Notify changes in unsigned notification mail could not be sent: ' . $e->getMessage());
×
78
                        throw new LibresignException('Notify unsigned notification mail could not be sent', 1);
×
79
                }
80
        }
81

82
        /**
83
         * @psalm-suppress MixedMethodCall
84
         */
85
        public function notifyUnsignedUser(SignRequest $data, string $email, ?string $description = null): void {
86
                $emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
15✔
87
                $emailTemplate->setSubject($this->l10n->t('LibreSign: There is a file for you to sign'));
15✔
88
                $emailTemplate->addHeader();
15✔
89
                $emailTemplate->addHeading($this->l10n->t('File to sign'), false);
15✔
90

91
                if (!empty($description)) {
15✔
NEW
92
                        $emailTemplate->addBodyText($description);
×
NEW
93
                        $emailTemplate->addBodyText('');
×
94
                }
95

96
                $emailTemplate->addBodyText($this->l10n->t('There is a document for you to sign. Access the link below:'));
15✔
97
                $link = $this->urlGenerator->linkToRouteAbsolute('libresign.page.sign', ['uuid' => $data->getUuid()]);
15✔
98
                $file = $this->getFileById($data->getFileId());
15✔
99
                $emailTemplate->addBodyButton(
15✔
100
                        $this->l10n->t('Sign »%s«', [$file->getName()]),
15✔
101
                        $link
15✔
102
                );
15✔
103
                $message = $this->mailer->createMessage();
15✔
104
                if ($data->getDisplayName()) {
15✔
105
                        $message->setTo([$email => $data->getDisplayName()]);
15✔
106
                } else {
107
                        $message->setTo([$email]);
×
108
                }
109
                $message->useTemplate($emailTemplate);
15✔
110
                try {
111
                        $this->mailer->send($message);
15✔
112
                } catch (\Exception $e) {
1✔
113
                        $this->logger->error('Notify unsigned notification mail could not be sent: ' . $e->getMessage());
1✔
114
                        throw new LibresignException('Notify unsigned notification mail could not be sent', 1);
1✔
115
                }
116
        }
117

118
        public function notifySignedUser(SignRequest $signRequest, string $email, File $libreSignFile, string $displayName): void {
119
                $emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
×
120
                // TRANSLATORS The subject of the email that is sent after a document has been signed by a user. This email is sent to the person who requested the signature.
121
                $emailTemplate->setSubject($this->l10n->t('LibreSign: A file has been signed'));
×
122
                $emailTemplate->addHeader();
×
123
                $emailTemplate->addHeading($this->l10n->t('File signed'), false);
×
124
                // TRANSLATORS The text in the email that is sent after a document has been signed by a user. %s will be replaced with the name of the user who signed the document.
125
                $emailTemplate->addBodyText($this->l10n->t('%s signed the document. You can access it using the link below:', [$signRequest->getDisplayName()]));
×
126
                $link = $this->urlGenerator->linkToRouteAbsolute('libresign.page.indexFPath', [
×
127
                        'path' => 'validation/' . $libreSignFile->getUuid(),
×
128
                ]);
×
129
                $file = $this->getFileById($signRequest->getFileId());
×
130
                $emailTemplate->addBodyButton(
×
131
                        // TRANSLATORS The button text in the email that is sent after a document has been signed by a user. %s will be replaced with the name of the file that was signed.
132
                        $this->l10n->t('View signed file »%s«', [$file->getName()]),
×
133
                        $link
×
134
                );
×
135
                $message = $this->mailer->createMessage();
×
136
                $message->setTo([$email => $displayName]);
×
137

138
                $message->useTemplate($emailTemplate);
×
139
                try {
140
                        $this->mailer->send($message);
×
141
                } catch (\Exception $e) {
×
142
                        $this->logger->error('Notify signed notification mail could not be sent: ' . $e->getMessage());
×
143
                        throw new LibresignException('Notify signed notification mail could not be sent', 1);
×
144
                }
145
        }
146

147
        public function notifyCanceledRequest(SignRequest $signRequest, string $email, File $libreSignFile): void {
148
                $emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
2✔
149
                // TRANSLATORS The subject of the email that is sent when a signature request has been canceled.
150
                $emailTemplate->setSubject($this->l10n->t('LibreSign: A signature request has been canceled'));
2✔
151
                $emailTemplate->addHeader();
2✔
152
                $emailTemplate->addHeading($this->l10n->t('Signature request canceled'), false);
2✔
153
                // TRANSLATORS The text in the email that is sent when a signature request has been canceled. %s will be replaced with the name of the file.
154
                $emailTemplate->addBodyText($this->l10n->t('The request for you to sign "%s" has been canceled.', [$libreSignFile->getName()]));
2✔
155
                $message = $this->mailer->createMessage();
2✔
156
                if ($signRequest->getDisplayName()) {
2✔
157
                        $message->setTo([$email => $signRequest->getDisplayName()]);
2✔
158
                } else {
159
                        $message->setTo([$email]);
×
160
                }
161
                $message->useTemplate($emailTemplate);
2✔
162
                try {
163
                        $this->mailer->send($message);
2✔
164
                } catch (\Exception $e) {
×
165
                        $this->logger->error('Notify canceled request mail could not be sent: ' . $e->getMessage());
×
166
                        // Don't throw exception to avoid breaking the flow when mail fails
167
                }
168
        }
169

170
        public function sendCodeToSign(string $email, string $name, string $code): void {
171
                $emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
×
172
                $emailTemplate->setSubject($this->l10n->t('LibreSign: Code to sign file'));
×
173
                $emailTemplate->addHeader();
×
174
                $emailTemplate->addBodyText($this->l10n->t('Use this code to sign the document:'));
×
175
                $emailTemplate->addBodyText($code);
×
176
                $message = $this->mailer->createMessage();
×
177
                if (!empty($name)) {
×
178
                        $message->setTo([$email => $name]);
×
179
                } else {
180
                        $message->setTo([$email]);
×
181
                }
182
                $message->useTemplate($emailTemplate);
×
183
                try {
184
                        $this->mailer->send($message);
×
185
                } catch (\Exception $e) {
×
186
                        $this->logger->error('Mail with code to sign document could not be sent: ' . $e->getMessage());
×
187
                        throw new LibresignException('Mail with code to sign document could not be sent', 1);
×
188
                }
189
        }
190
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc