snappymail/dev/Model/Identity.js

50 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-10-23 06:56:42 +08:00
//import { AbstractModel } from 'Knoin/AbstractModel';
import { EmailModel } from 'Model/Email';
2024-02-21 01:29:35 +08:00
import { addObservablesTo, addComputablesTo } from 'External/ko';
2016-07-07 05:03:30 +08:00
2024-10-23 06:56:42 +08:00
export class IdentityModel extends EmailModel /*AbstractModel*/ {
2023-02-21 23:02:22 +08:00
constructor() {
2020-10-19 01:19:45 +08:00
super();
2016-07-07 05:03:30 +08:00
addObservablesTo(this, {
2023-02-21 23:02:22 +08:00
id: '',
2024-02-09 09:39:00 +08:00
label: '',
2024-10-23 06:56:42 +08:00
// email: '',
// name: '',
2016-07-07 05:03:30 +08:00
2020-10-25 18:46:58 +08:00
replyTo: '',
bcc: '',
2024-02-12 09:13:39 +08:00
sentFolder: '',
2016-07-07 05:03:30 +08:00
2020-10-25 18:46:58 +08:00
signature: '',
signatureInsertBefore: false,
pgpSign: false,
pgpEncrypt: false,
smimeKey: '',
smimeCertificate: '',
2024-08-06 23:50:43 +08:00
askDelete: false,
exists: false
2020-10-25 18:46:58 +08:00
});
2024-02-21 01:29:35 +08:00
addComputablesTo(this, {
smimeKeyEncrypted: () => this.smimeKey().includes('-----BEGIN ENCRYPTED PRIVATE KEY-----'),
smimeKeyValid: () => /^-----BEGIN (ENCRYPTED |RSA )?PRIVATE KEY-----/.test(this.smimeKey()),
smimeCertificateValid: () => /^-----BEGIN CERTIFICATE-----/.test(this.smimeCertificate())
2024-02-21 01:29:35 +08:00
});
2016-07-07 05:03:30 +08:00
}
/**
* @returns {string}
*/
toString() {
2024-10-23 06:56:42 +08:00
const name = this.name,
email = this.email,
2024-02-09 09:39:00 +08:00
label = this.label();
return (name ? `${name} ` : '') + `<${email}>` + (label ? ` (${label})` : '');
2016-07-07 05:03:30 +08:00
}
}