Skip to content

Commit 4863f96

Browse files
hamza221st3iny
authored andcommitted
fix(smime): persist sign preference per alias
Signed-off-by: Hamza Mahjoubi <[email protected]> Signed-off-by: Richard Steinmetz <[email protected]>
1 parent f366a5d commit 4863f96

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

lib/Controller/PageController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ public function index(): TemplateResponse {
188188
$this->preferences->getPreference($this->currentUserId, 'internal-addresses', false)
189189
);
190190

191+
$this->initialStateService->provideInitialState(
192+
'smime-sign-aliases',
193+
json_decode($this->preferences->getPreference($this->currentUserId, 'smime-sign-aliases', '[]'), true, 512, JSON_THROW_ON_ERROR) ?? []
194+
);
195+
191196
$this->initialStateService->provideInitialState(
192197
'sort-order',
193198
$this->preferences->getPreference($this->currentUserId, 'sort-order', 'newest')

src/components/Composer.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@
359359
</ActionCheckbox>
360360
<ActionCheckbox v-if="smimeCertificateForCurrentAlias"
361361
:checked="wantsSmimeSign"
362-
@check="wantsSmimeSign = true"
363-
@uncheck="wantsSmimeSign = false">
362+
@check="smimeSignCheck(true)"
363+
@uncheck="smimeSignCheck(false)">
364364
{{ t('mail', 'Sign message with S/MIME') }}
365365
</ActionCheckbox>
366366
<ActionCheckbox v-if="smimeCertificateForCurrentAlias"
@@ -497,6 +497,7 @@ import { TRIGGER_CHANGE_ALIAS, TRIGGER_EDITOR_READY } from '../ckeditor/signatur
497497
import { EDITOR_MODE_HTML, EDITOR_MODE_TEXT } from '../store/constants.js'
498498
import useMainStore from '../store/mainStore.js'
499499
import { mapStores, mapState } from 'pinia'
500+
import { savePreference } from '../service/PreferenceService.js'
500501
501502
const debouncedSearch = debouncePromise(findRecipient, 500)
502503
@@ -689,6 +690,7 @@ export default {
689690
wantsSmimeEncrypt: this.smimeEncrypt,
690691
isPickerOpen: false,
691692
recipientSearchTerms: {},
693+
smimeSignAliases: [],
692694
}
693695
},
694696
computed: {
@@ -939,6 +941,13 @@ export default {
939941
requestMdnVal(val) {
940942
this.$emit('update:request-mdn', val)
941943
},
944+
selectedAlias: {
945+
handler() {
946+
const aliasEmailAddress = this.selectedAlias.emailAddress
947+
this.wantsSmimeSign = this.smimeSignAliases.indexOf(aliasEmailAddress) !== -1
948+
},
949+
immediate: true,
950+
}
942951
},
943952
async beforeMount() {
944953
this.setAlias()
@@ -984,6 +993,8 @@ export default {
984993
if (this.sendAt && this.isSendAtCustom) {
985994
this.selectedDate = new Date(this.sendAt)
986995
}
996+
997+
this.smimeSignAliases = this.mainStore.getPreference('smime-sign-aliases', [])
987998
},
988999
beforeDestroy() {
9891000
window.removeEventListener('mailvelope', this.onMailvelopeLoaded)
@@ -1418,6 +1429,17 @@ export default {
14181429
return this.mainStore.getSmimeCertificate(certificateId)
14191430
},
14201431
1432+
smimeSignCheck(value) {
1433+
this.wantsSmimeSign = value
1434+
if (value) {
1435+
this.smimeSignAliases.push(this.selectedAlias.emailAddress)
1436+
} else {
1437+
this.smimeSignAliases = this.smimeSignAliases
1438+
.filter((alias) => alias !== this.selectedAlias.emailAddress)
1439+
}
1440+
savePreference('smime-sign-aliases', JSON.stringify(this.smimeSignAliases))
1441+
},
1442+
14211443
/**
14221444
* Create a new option for the to, cc and bcc selects.
14231445
*

src/init.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export default function initAfterAppCreation() {
8282
key: 'internal-addresses',
8383
value: loadState('mail', 'internal-addresses', false),
8484
})
85+
mainStore.savePreferenceMutation({
86+
key: 'smime-sign-aliases',
87+
value: loadState('mail', 'smime-sign-aliases', []),
88+
})
8589

8690
const accountSettings = loadState('mail', 'account-settings')
8791
const accounts = loadState('mail', 'accounts', [])

tests/Unit/Controller/PageControllerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function testIndex(): void {
168168
$account1 = $this->createMock(Account::class);
169169
$account2 = $this->createMock(Account::class);
170170
$mailbox = $this->createMock(Mailbox::class);
171-
$this->preferences->expects($this->exactly(11))
171+
$this->preferences->expects($this->exactly(12))
172172
->method('getPreference')
173173
->willReturnMap([
174174
[$this->userId, 'account-settings', '[]', json_encode([])],
@@ -182,6 +182,7 @@ public function testIndex(): void {
182182
[$this->userId, 'layout-message-view', 'threaded', 'threaded'],
183183
[$this->userId, 'follow-up-reminders', 'true', 'true'],
184184
[$this->userId, 'internal-addresses', 'false', 'false'],
185+
[$this->userId, 'smime-sign-aliases', '[]', '[]'],
185186
]);
186187
$this->classificationSettingsService->expects(self::once())
187188
->method('isClassificationEnabled')
@@ -302,7 +303,7 @@ public function testIndex(): void {
302303
->method('getLoginCredentials')
303304
->willReturn($loginCredentials);
304305

305-
$this->initialState->expects($this->exactly(21))
306+
$this->initialState->expects($this->exactly(22))
306307
->method('provideInitialState')
307308
->withConsecutive(
308309
['debug', true],
@@ -312,6 +313,7 @@ public function testIndex(): void {
312313
['tags', []],
313314
['internal-addresses-list', []],
314315
['internal-addresses', false],
316+
['smime-sign-aliases',[]],
315317
['sort-order', 'newest'],
316318
['password-is-unavailable', true],
317319
['preferences', [

0 commit comments

Comments
 (0)