Skip to content

Commit cc0a8bf

Browse files
committed
fix: keep localized mail subject unchanged
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 262aa33 commit cc0a8bf

2 files changed

Lines changed: 7 additions & 40 deletions

File tree

lib/Service/MailService.php

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,13 @@ private function getFileById(int $fileId): File {
4242
return $this->files[$fileId];
4343
}
4444

45-
private function encodeMailSubject(string $subject): string {
46-
if (preg_match('/^[\x20-\x7E]+$/', $subject) === 1) {
47-
return $subject;
48-
}
49-
50-
if (function_exists('mb_encode_mimeheader')) {
51-
$encoded = mb_encode_mimeheader($subject, 'UTF-8', 'B', "\r\n");
52-
if (is_string($encoded) && $encoded !== '') {
53-
return str_replace(["\r", "\n"], '', $encoded);
54-
}
55-
}
56-
57-
if (function_exists('iconv_mime_encode')) {
58-
$encoded = iconv_mime_encode('Subject', $subject, [
59-
'scheme' => 'B',
60-
'input-charset' => 'UTF-8',
61-
'output-charset' => 'UTF-8',
62-
'line-length' => 76,
63-
'line-break-chars' => "\r\n",
64-
]);
65-
if (is_string($encoded) && str_starts_with($encoded, 'Subject: ')) {
66-
return str_replace(["\r", "\n"], '', substr($encoded, 9));
67-
}
68-
}
69-
70-
return $subject;
71-
}
72-
7345
/**
7446
* @psalm-suppress MixedMethodCall
7547
*/
7648
public function notifySignDataUpdated(SignRequest $data, string $email, ?string $description = null): void {
7749
$emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
7850
// 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
79-
$emailTemplate->setSubject($this->encodeMailSubject($this->l10n->t('LibreSign: Changes into a file for you to sign')));
51+
$emailTemplate->setSubject($this->l10n->t('LibreSign: Changes into a file for you to sign'));
8052
$emailTemplate->addHeader();
8153
$emailTemplate->addHeading($this->l10n->t('File to sign'), false);
8254

@@ -112,7 +84,7 @@ public function notifySignDataUpdated(SignRequest $data, string $email, ?string
11284
*/
11385
public function notifyUnsignedUser(SignRequest $data, string $email, ?string $description = null): void {
11486
$emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
115-
$emailTemplate->setSubject($this->encodeMailSubject($this->l10n->t('LibreSign: There is a file for you to sign')));
87+
$emailTemplate->setSubject($this->l10n->t('LibreSign: There is a file for you to sign'));
11688
$emailTemplate->addHeader();
11789
$emailTemplate->addHeading($this->l10n->t('File to sign'), false);
11890

@@ -146,7 +118,7 @@ public function notifyUnsignedUser(SignRequest $data, string $email, ?string $de
146118
public function notifySignedUser(SignRequest $signRequest, string $email, File $libreSignFile, string $displayName): void {
147119
$emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
148120
// 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.
149-
$emailTemplate->setSubject($this->encodeMailSubject($this->l10n->t('LibreSign: A file has been signed')));
121+
$emailTemplate->setSubject($this->l10n->t('LibreSign: A file has been signed'));
150122
$emailTemplate->addHeader();
151123
$emailTemplate->addHeading($this->l10n->t('File signed'), false);
152124
// 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.
@@ -175,7 +147,7 @@ public function notifySignedUser(SignRequest $signRequest, string $email, File $
175147
public function notifyCanceledRequest(SignRequest $signRequest, string $email, File $libreSignFile): void {
176148
$emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
177149
// TRANSLATORS The subject of the email that is sent when a signature request has been canceled.
178-
$emailTemplate->setSubject($this->encodeMailSubject($this->l10n->t('LibreSign: A signature request has been canceled')));
150+
$emailTemplate->setSubject($this->l10n->t('LibreSign: A signature request has been canceled'));
179151
$emailTemplate->addHeader();
180152
$emailTemplate->addHeading($this->l10n->t('Signature request canceled'), false);
181153
// 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.
@@ -197,7 +169,7 @@ public function notifyCanceledRequest(SignRequest $signRequest, string $email, F
197169

198170
public function sendCodeToSign(string $email, string $name, string $code): void {
199171
$emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
200-
$emailTemplate->setSubject($this->encodeMailSubject($this->l10n->t('LibreSign: Code to sign file')));
172+
$emailTemplate->setSubject($this->l10n->t('LibreSign: Code to sign file'));
201173
$emailTemplate->addHeader();
202174
$emailTemplate->addBodyText($this->l10n->t('Use this code to sign the document:'));
203175
$emailTemplate->addBodyText($code);

tests/php/Unit/Service/MailServiceTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function testFailToSendMailToUnsignedUser():void {
116116
$this->assertNull($actual);
117117
}
118118

119-
public function testSendCodeToSignEncodesAccentedSubjectAsMimeHeader(): void {
119+
public function testSendCodeToSignUsesLocalizedSubjectWithoutMutation(): void {
120120
$l10n = $this->createMock(IL10N::class);
121121
$l10n
122122
->method('t')
@@ -139,12 +139,7 @@ public function testSendCodeToSignEncodesAccentedSubjectAsMimeHeader(): void {
139139
$emailTemplate
140140
->expects($this->once())
141141
->method('setSubject')
142-
->with($this->callback(static function (string $subject): bool {
143-
if (preg_match('/^[\x20-\x7E]+$/', $subject) !== 1) {
144-
return false;
145-
}
146-
return str_contains($subject, '=?UTF-8?B?') || str_contains($subject, '=?UTF-8?Q?');
147-
}));
142+
->with('LibreSign : Code nécessaire à la signature du fichier');
148143
$emailTemplate
149144
->expects($this->once())
150145
->method('addHeader');

0 commit comments

Comments
 (0)