Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Controller/AccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public function update(int $id,
* @param int|null $archiveMailboxId
* @param int|null $snoozeMailboxId
* @param bool|null $signatureAboveQuote
* @param bool|null $signatureSeparator
* @param bool|null $classificationEnabled
*
* @return JSONResponse
Expand All @@ -233,6 +234,7 @@ public function patchAccount(int $id,
?int $archiveMailboxId = null,
?int $snoozeMailboxId = null,
?bool $signatureAboveQuote = null,
?bool $signatureSeparator = null,
?int $trashRetentionDays = null,
?int $junkMailboxId = null,
?bool $searchBody = null,
Expand Down Expand Up @@ -276,6 +278,9 @@ public function patchAccount(int $id,
if ($signatureAboveQuote !== null) {
$dbAccount->setSignatureAboveQuote($signatureAboveQuote);
}
if ($signatureSeparator !== null) {
$dbAccount->setSignatureSeparator($signatureSeparator);
}
if ($trashRetentionDays !== null) {
// Passing 0 (or lower) disables retention
$dbAccount->setTrashRetentionDays($trashRetentionDays <= 0 ? null : $trashRetentionDays);
Expand Down
9 changes: 9 additions & 0 deletions lib/Db/MailAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
* @method void setSievePassword(?string $sievePassword)
* @method bool|null isSignatureAboveQuote()
* @method void setSignatureAboveQuote(bool $signatureAboveQuote)
* @method bool|null isSignatureSeparator()
* @method void setSignatureSeparator(bool $signatureSeparator)
* @method string getAuthMethod()
* @method void setAuthMethod(string $method)
* @method int getSignatureMode()
Expand Down Expand Up @@ -165,6 +167,8 @@ class MailAccount extends Entity {
protected $sievePassword;
/** @var bool */
protected $signatureAboveQuote = false;
/** @var bool */
protected $signatureSeparator = true;

/** @var int|null */
protected $provisioningId;
Expand Down Expand Up @@ -245,6 +249,9 @@ public function __construct(array $params = []) {
if (isset($params['signatureAboveQuote'])) {
$this->setSignatureAboveQuote($params['signatureAboveQuote']);
}
if (isset($params['signatureSeparator'])) {
$this->setSignatureSeparator($params['signatureSeparator']);
}
if (isset($params['trashRetentionDays'])) {
$this->setTrashRetentionDays($params['trashRetentionDays']);
}
Expand Down Expand Up @@ -276,6 +283,7 @@ public function __construct(array $params = []) {
$this->addType('sieveEnabled', 'boolean');
$this->addType('sievePort', 'integer');
$this->addType('signatureAboveQuote', 'boolean');
$this->addType('signatureSeparator', 'boolean');
$this->addType('signatureMode', 'integer');
$this->addType('smimeCertificateId', 'integer');
$this->addType('quotaPercentage', 'integer');
Expand Down Expand Up @@ -327,6 +335,7 @@ public function toJson() {
'snoozeMailboxId' => $this->getSnoozeMailboxId(),
'sieveEnabled' => ($this->isSieveEnabled() === true),
'signatureAboveQuote' => ($this->isSignatureAboveQuote() === true),
'signatureSeparator' => ($this->isSignatureSeparator() !== false),
'signatureMode' => $this->getSignatureMode(),
'smimeCertificateId' => $this->getSmimeCertificateId(),
'quotaPercentage' => $this->getQuotaPercentage(),
Expand Down
45 changes: 45 additions & 0 deletions lib/Migration/Version5009Date20260617000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Mail\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* @psalm-api
*/
class Version5009Date20260617000000 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @return ISchemaWrapper
*/
#[\Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$accountsTable = $schema->getTable('mail_accounts');

if (!$accountsTable->hasColumn('signature_separator')) {
$accountsTable->addColumn('signature_separator', Types::BOOLEAN, [
'notnull' => false,
'default' => true,
]);
}

return $schema;
}
}
1 change: 1 addition & 0 deletions lib/UserMigration/MailAccountMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface
$newAccount->setSearchBody($accountData['searchBody'] ?? false);
$newAccount->setClassificationEnabled($accountData['classificationEnabled'] ?? false);
$newAccount->setSignatureAboveQuote($accountData['signatureAboveQuote'] ?? false);
$newAccount->setSignatureSeparator($accountData['signatureSeparator'] ?? true);
$newAccount->setPersonalNamespace($accountData['personalNamespace'] ?? null);
if (isset($accountData['inboundPassword'])) {
$newAccount->setInboundPassword($this->crypto->encrypt($accountData['inboundPassword']));
Expand Down
16 changes: 10 additions & 6 deletions src/ckeditor/signature/InsertSignatureCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export default class InsertSignatureCommand extends Command {
* @param {module:engine/model/writer~Writer} writer instance
* @param {string} signature text
* @param {boolean} signatureAboveQuote signature position: above/below the quoted text
* @param {boolean} signatureSeparator whether to prepend the "-- " separator above the signature
*/
insertSignatureElement(editor, writer, signature, signatureAboveQuote) {
insertSignatureElement(editor, writer, signature, signatureAboveQuote, signatureSeparator) {
// Skip empty signature
if (signature.length === 0) {
return
Expand All @@ -55,8 +56,10 @@ export default class InsertSignatureCommand extends Command {
const modelFragment = editor.data.toModel(viewFragment)

const signatureElement = writer.createElement('signature')
writer.append(writer.createText('-- '), signatureElement)
writer.append(writer.createElement('paragraph'), signatureElement)
if (signatureSeparator !== false) {
writer.append(writer.createText('-- '), signatureElement)
writer.append(writer.createElement('paragraph'), signatureElement)
}
writer.append(modelFragment, signatureElement)
if (signatureAboveQuote) {
writer.append(writer.createElement('paragraph'), signatureElement)
Expand Down Expand Up @@ -122,8 +125,9 @@ export default class InsertSignatureCommand extends Command {
* @param {string} trigger TRIGGER_CHANGE_ALIAS or TRIGGER_EDITOR_READY
* @param {string} signature text
* @param {boolean} signatureAboveQuote signature position: above/below the quoted text
* @param {boolean} signatureSeparator whether to prepend the "-- " separator above the signature
*/
execute(trigger, signature, signatureAboveQuote) {
execute(trigger, signature, signatureAboveQuote, signatureSeparator) {
this.editor.model.change((writer) => {
/**
* TRIGGER_CHANGE_ALIAS:
Expand All @@ -139,11 +143,11 @@ export default class InsertSignatureCommand extends Command {

if (trigger === TRIGGER_CHANGE_ALIAS) {
this.removeSignatureElement(this.editor, writer)
this.insertSignatureElement(this.editor, writer, signature, signatureAboveQuote)
this.insertSignatureElement(this.editor, writer, signature, signatureAboveQuote, signatureSeparator)
}

if (trigger === TRIGGER_EDITOR_READY && !this.hasSignatureElement(this.editor)) {
this.insertSignatureElement(this.editor, writer, signature, signatureAboveQuote)
this.insertSignatureElement(this.editor, writer, signature, signatureAboveQuote, signatureSeparator)
}
})
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ export default {
name: account.name,
emailAddress: account.emailAddress,
signatureAboveQuote: account.signatureAboveQuote,
signatureSeparator: account.signatureSeparator,
smimeCertificateId: account.smimeCertificateId,
selectable: account.connectionStatus,
},
Expand All @@ -811,6 +812,7 @@ export default {
name: alias.name,
emailAddress: alias.alias,
signatureAboveQuote: account.signatureAboveQuote,
signatureSeparator: account.signatureSeparator,
smimeCertificateId: alias.smimeCertificateId,
selectable: account.connectionStatus,
}
Expand Down Expand Up @@ -1307,6 +1309,7 @@ export default {
trigger,
toHtml(detect(this.selectedAlias.signature)).value,
this.selectedAlias.signatureAboveQuote,
this.selectedAlias.signatureSeparator,
)

this.changeSignature = false
Expand Down
25 changes: 25 additions & 0 deletions src/components/SignatureSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
{{ t("mail", "Place signature above quoted text") }}
</label>
</div>
<div>
<input
id="signature-separator-toggle"
v-model="signatureSeparator"
type="checkbox"
class="checkbox">
<label for="signature-separator-toggle">
{{ t("mail", "Add a separator line (--) above the signature") }}
</label>
</div>
<NcSelect
v-if="identities.length > 1"
:allow-empty="false"
Expand Down Expand Up @@ -93,6 +103,7 @@ export default {
identity: null,
signature: '',
signatureAboveQuote: this.account.signatureAboveQuote,
signatureSeparator: this.account.signatureSeparator,
}
},

Expand Down Expand Up @@ -136,6 +147,20 @@ export default {
this.signatureAboveQuote = oldVal
}
},
async signatureSeparator(val, oldVal) {
try {
await this.mainStore.patchAccount({
account: this.account,
data: {
signatureSeparator: val,
},
})
logger.debug('signature separator updated to ' + val)
} catch (e) {
logger.error('could not update signature separator', { e })
this.signatureSeparator = oldVal
}
},
},

beforeMount() {
Expand Down
1 change: 1 addition & 0 deletions src/store/mainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default defineStore('main', {
name: '',
showSubscribedOnly: false,
signatureAboveQuote: false,
signatureSeparator: true,
},
},
accountList: [UNIFIED_ACCOUNT_ID],
Expand Down
21 changes: 21 additions & 0 deletions src/tests/unit/components/SignaturePlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ describe('SignaturePlugin', () => {
expect(editor.getData()).toEqual(text)
})

it('Add signature without separator', async () => {
const text = '<p>bonjour bonjour</p>'
const expected = '<p>bonjour bonjour</p><div class="signature"><p>Jane Doe</p></div>'

const editor = await VirtualTestEditor.create({
licenseKey: 'GPL',
initialData: text,
plugins: [Paragraph, SignaturePlugin],
})

editor.execute(
'insertSignature',
TRIGGER_EDITOR_READY,
'<p>Jane Doe</p>',
false,
false,
)

expect(editor.getData()).toEqual(expected)
})

it('Add signature to content above quote', async () => {
const text = '<p>bonjour bonjour</p><div class="quote">"John Doe" john.doe@localhost - January 1, 1970 1:00 AM <blockquote><p>bonjour bonjour</p></blockquote></div>'
const expected = '<p>bonjour bonjour</p><div class="signature">--&nbsp;<p>&nbsp;</p><p>Jane Doe</p><p>&nbsp;</p></div><div class="quote"><p>"John Doe" john.doe@localhost - January 1, 1970 1:00 AM</p><p>bonjour bonjour</p></div>'
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/Db/MailAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function testToAPI() {
'archiveMailboxId' => null,
'sieveEnabled' => false,
'signatureAboveQuote' => false,
'signatureSeparator' => true,
'signatureMode' => null,
'smimeCertificateId' => null,
'quotaPercentage' => 10,
Expand Down Expand Up @@ -103,6 +104,7 @@ public function testMailAccountConstruct() {
'archiveMailboxId' => null,
'sieveEnabled' => false,
'signatureAboveQuote' => false,
'signatureSeparator' => true,
'signatureMode' => null,
'smimeCertificateId' => null,
'quotaPercentage' => null,
Expand Down