This commit is contained in:
the-djmaze 2024-02-12 01:01:19 +01:00
parent a45cd5904f
commit 7da5692865
11 changed files with 115 additions and 56 deletions

View file

@ -15,6 +15,7 @@ import { FileInfo, RFC822 } from 'Common/File';
import { AttachmentCollectionModel } from 'Model/AttachmentCollection';
import { EmailCollectionModel } from 'Model/EmailCollection';
import { MimeHeaderCollectionModel } from 'Model/MimeHeaderCollection';
//import { MimeHeaderAutocryptModel } from 'Model/MimeHeaderAutocrypt';
import { AbstractModel } from 'Knoin/AbstractModel';
import PreviewHTML from 'Html/PreviewMessage.html';
@ -75,7 +76,7 @@ export class MessageModel extends AbstractModel {
messageId: '',
inReplyTo: '',
references: '',
autocrypt: {/*addr:'', 'prefer-encrypt':'nopreference', keydata:'BASE64'*/},
// autocrypt: ko.observableArray(),
hasVirus: null, // or boolean when scanned
priority: 3, // Normal
internalTimestamp: 0,
@ -287,12 +288,9 @@ export class MessageModel extends AbstractModel {
}
// https://autocrypt.org/level1.html#the-autocrypt-header
if (value = headers.valueByName('Autocrypt')) {
value.split(';').forEach(entry => {
entry = entry.trim().split('=', 2);
json.autocrypt[entry[0]] = entry[1];
});
}
headers.valuesByName('Autocrypt').forEach(value => {
this.autocrypt.push(new MimeHeaderAutocryptModel(value));
});
*/
return true;
}

View file

@ -0,0 +1,32 @@
//import { AbstractModel } from 'Knoin/AbstractModel';
export class MimeHeaderAutocryptModel/* extends AbstractModel*/
{
constructor(value) {
// super();
this.addr = '';
this.prefer_encrypt = 'nopreference', // nopreference or mutual
this.keydata = '';
if (value) {
value.split(';').forEach(entry => {
entry = entry.split('=');
const trim = str => (str || '').trim().replace(/^["']|["']+$/g, '');
this[trim(entry[0]).replace('-', '_')] = trim(entry[1]);
});
}
}
toString() {
if ('mutual' === this.prefer_encrypt) {
return `addr=${this.addr}; prefer-encrypt=mutual; keydata=${this.keydata}`;
}
return `addr=${this.addr}; keydata=${this.keydata}`;
}
key() {
return '-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n'
+ this.keydata
+ '\n-----END PGP PUBLIC KEY BLOCK-----';
}
}

View file

@ -29,4 +29,10 @@ export class MimeHeaderCollectionModel extends AbstractCollectionModel
return header ? header.value : '';
}
valuesByName(name)
{
name = name.toLowerCase();
return this.filter(header => header.name.toLowerCase() === name).map(header => header.value);
}
}