From f0b3d798bceb91e2a57220d752b7c4e8bf7d0f8a Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 23 Oct 2024 00:56:42 +0200 Subject: [PATCH] IdentityModel extends EmailModel --- dev/Model/Email.js | 5 +++++ dev/Model/Identity.js | 13 +++++++------ dev/View/Popup/Compose.js | 18 +++++++++--------- dev/View/Popup/Identity.js | 4 ++-- dev/View/Popup/OpenPgpGenerate.js | 4 ++-- dev/View/User/MailBox/MessageView.js | 4 ++-- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/dev/Model/Email.js b/dev/Model/Email.js index 077aab37b..b4a77efcf 100644 --- a/dev/Model/Email.js +++ b/dev/Model/Email.js @@ -73,4 +73,9 @@ export class EmailModel extends AbstractModel { } return result || name; } + + get domain() { + return this.email.replace(/^.+@([^@]+)$/, '$1'); +// return this.email.slice(this.email.lastIndexOf('@')) + } } diff --git a/dev/Model/Identity.js b/dev/Model/Identity.js index ac38bc376..cd7714f87 100644 --- a/dev/Model/Identity.js +++ b/dev/Model/Identity.js @@ -1,7 +1,8 @@ -import { AbstractModel } from 'Knoin/AbstractModel'; +//import { AbstractModel } from 'Knoin/AbstractModel'; +import { EmailModel } from 'Model/Email'; import { addObservablesTo, addComputablesTo } from 'External/ko'; -export class IdentityModel extends AbstractModel { +export class IdentityModel extends EmailModel /*AbstractModel*/ { /** * @param {string} id * @param {string} email @@ -12,8 +13,8 @@ export class IdentityModel extends AbstractModel { addObservablesTo(this, { id: '', label: '', - email: '', - name: '', +// email: '', +// name: '', replyTo: '', bcc: '', @@ -44,8 +45,8 @@ export class IdentityModel extends AbstractModel { * @returns {string} */ formattedName() { - const name = this.name(), - email = this.email(), + const name = this.name, + email = this.email, label = this.label(); return (name ? `${name} ` : '') + `<${email}>` + (label ? ` (${label})` : ''); } diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 302017dfb..2f30123f4 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -92,7 +92,7 @@ const findIdentity = addresses => { addresses = addresses.map(item => item.email); - return IdentityUserStore.find(item => addresses.includes(item.email())); + return IdentityUserStore.find(item => addresses.includes(item.email)); }, /** @@ -873,8 +873,8 @@ export class ComposePopupView extends AbstractViewPopup { } identity = identity || IdentityUserStore()[0]; if (identity) { -// excludeEmail.add(identity.email()); - excludeEmail[identity.email()] = true; +// excludeEmail.add(identity.email); + excludeEmail[identity.email] = true; } if (arrayLength(options.to)) { @@ -1381,7 +1381,7 @@ export class ComposePopupView extends AbstractViewPopup { allRecipients() { return [ // From/sender is also recipient (Sent mailbox) -// this.currentIdentity().email(), +// this.currentIdentity().email, this.from(), this.to(), this.cc(), @@ -1401,7 +1401,7 @@ export class ComposePopupView extends AbstractViewPopup { key && options.push(['OpenPGP', key]); key = GnuPGUserStore.getPrivateKeyFor(email, 1); key && options.push(['GnuPG', key]); - identity.smimeKeyValid() && identity.smimeCertificateValid() && identity.email() === email + identity.smimeKeyValid() && identity.smimeCertificateValid() && identity.email === email && options.push(['S/MIME']); console.dir({signOptions: options}); this.signOptions(options); @@ -1420,7 +1420,7 @@ export class ComposePopupView extends AbstractViewPopup { const count = recipients.length, identity = this.currentIdentity(), - from = (identity.smimeKey() && identity.smimeCertificate()) ? identity.email() : null; + from = (identity.smimeKey() && identity.smimeCertificate()) ? identity.email : null; count && count === recipients.filter(email => email == from @@ -1497,7 +1497,7 @@ export class ComposePopupView extends AbstractViewPopup { **/ linkedData: [] }, - recipients = draft ? [identity.email()] : this.allRecipients(), + recipients = draft ? [identity.email] : this.allRecipients(), signOptions = !draft && this.doSign() && this.signOptions(), encryptOptions = this.doEncrypt() && this.encryptOptions(), isHtml = this.oEditor.isHtml(); @@ -1593,7 +1593,7 @@ export class ComposePopupView extends AbstractViewPopup { // params.attachCertificate = false; if (identity.smimeKeyEncrypted()) { const pass = await Passphrases.ask(identity, - i18n('SMIME/PRIVATE_KEY_OF', {EMAIL: identity.email()}), + i18n('SMIME/PRIVATE_KEY_OF', {EMAIL: identity.email}), 'CRYPTO/SIGN' ); if (null != pass) { @@ -1633,7 +1633,7 @@ export class ComposePopupView extends AbstractViewPopup { if ('S/MIME' == encryptOptions[i]) { params.encryptCertificates = [identity.smimeCertificate()]; SMimeUserStore.forEach(certificate => { - certificate.emailAddress != identity.email() + certificate.emailAddress != identity.email && recipients.includes(certificate.emailAddress) && params.encryptCertificates.push(certificate.id) }); diff --git a/dev/View/Popup/Identity.js b/dev/View/Popup/Identity.js index f061da0ed..b47b9d07d 100644 --- a/dev/View/Popup/Identity.js +++ b/dev/View/Popup/Identity.js @@ -57,8 +57,8 @@ export class IdentityPopupView extends AbstractViewPopup { this.submitError(oData.message); } }, { - name: identity.name(), - email: identity.email(), + name: identity.name, + email: identity.email, privateKey: identity.smimeKey(), passphrase: result.password }); diff --git a/dev/View/Popup/OpenPgpGenerate.js b/dev/View/Popup/OpenPgpGenerate.js index a2ec51515..e785af81e 100644 --- a/dev/View/Popup/OpenPgpGenerate.js +++ b/dev/View/Popup/OpenPgpGenerate.js @@ -105,9 +105,9 @@ export class OpenPgpGeneratePopupView extends AbstractViewPopup { } onShow() { - this.name(''/*IdentityUserStore()[0].name()*/); + this.name(''/*IdentityUserStore()[0].name*/); this.password(''); - this.email(''/*IdentityUserStore()[0].email()*/); + this.email(''/*IdentityUserStore()[0].email*/); this.emailError(false); this.submitError(''); } diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index 5a879466e..db3cbd106 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -670,7 +670,7 @@ export class MailMessageView extends AbstractViewRight { async smimeDecrypt() { const message = currentMessage(); const addresses = message.from.concat(message.to, message.cc, message.bcc).map(item => item.email), - identity = IdentityUserStore.find(item => addresses.includes(item.email())), + identity = IdentityUserStore.find(item => addresses.includes(item.email)), data = message.smimeEncrypted(); // { partId: "1" } if (data && identity) { delete data.error; @@ -682,7 +682,7 @@ export class MailMessageView extends AbstractViewRight { params.privateKey = identity.smimeKey(); if (identity.smimeKeyEncrypted()) { pass = await Passphrases.ask(identity, - i18n('SMIME/PRIVATE_KEY_OF', {EMAIL: identity.email()}), + i18n('SMIME/PRIVATE_KEY_OF', {EMAIL: identity.email}), 'CRYPTO/DECRYPT' ); if (!pass) {