#89 show decrypted HTML with inline attachments

This commit is contained in:
the-djmaze 2022-01-31 17:29:41 +01:00
parent 8a4ea92cfb
commit 4eb70c3f06
2 changed files with 30 additions and 20 deletions

View file

@ -95,7 +95,6 @@ export class MessageModel extends AbstractModel {
focused: false,
selected: false,
checked: false,
hasAttachments: false,
isHtml: false,
hasImages: false,
@ -174,7 +173,6 @@ export class MessageModel extends AbstractModel {
this.selected(false);
this.checked(false);
this.hasAttachments(false);
this.isHtml(false);
this.hasImages(false);
@ -229,7 +227,6 @@ export class MessageModel extends AbstractModel {
json.Priority = MessagePriority.Normal;
}
if (super.revivePropertiesFromJson(json)) {
this.hasAttachments(!!this.attachments.length);
// this.foundCIDs = isArray(json.FoundCIDs) ? json.FoundCIDs : [];
// this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundCIDs));
@ -324,7 +321,7 @@ export class MessageModel extends AbstractModel {
forwarded: this.isForwarded(),
focused: this.focused(),
important: this.isImportant(),
withAttachments: this.hasAttachments(),
withAttachments: !!this.attachments().length,
emptySubject: !this.subject(),
// hasChildrenMessage: 1 < this.threadsLen(),
hasUnseenSubMessage: this.hasUnseenSubMessage(),
@ -577,7 +574,6 @@ export class MessageModel extends AbstractModel {
this.selected(message.selected());
this.checked(message.checked());
this.hasAttachments(message.hasAttachments());
this.attachments(message.attachments());
this.threads(message.threads());

View file

@ -46,6 +46,7 @@ import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
const currentMessage = () => MessageUserStore.message();
import PostalMime from '../../../../vendors/postal-mime/src/postal-mime.js';
import { AttachmentModel } from 'Model/Attachment';
const mimeToMessage = (data, message) => {
// TODO: Check multipart/signed
@ -53,23 +54,36 @@ const mimeToMessage = (data, message) => {
if (/Content-Type:.+; boundary=/.test(headers)) {
// https://github.com/postalsys/postal-mime
(new PostalMime).parse(data).then(result => {
/*
result.attachments[0] = {
content: ArrayBuffer
disposition: null
filename: "signature.asc"
mimeType: "application/pgp-signature"
};
result.headers;
*/
// TODO: parse inline attachments from result.attachments
let html = result.html,
regex = /^<+|>+$/g;
result.attachments.forEach(data => {
let attachment = new AttachmentModel;
attachment.mimeType = data.mimeType;
attachment.fileName = data.filename;
attachment.content = data.content; // ArrayBuffer
attachment.cid = data.contentId || '';
// Parse inline attachments from result.attachments
if (attachment.cid) {
if (html) {
let cid = 'cid:' + attachment.cid.replace(regex, ''),
b64 = 'data:' + data.mimeType + ';base64,' + btoa(String.fromCharCode(...new Uint8Array(data.content)));
html = html
.replace('src="' + cid + '"', 'src="' + b64 + '"')
.replace("src='" + cid + "'", "src='" + b64 + "'");
}
}
// data.disposition
// data.related = true;
message.attachments.push(attachment);
});
// result.headers;
// TODO: strip script tags and all other security that PHP also does
message.html(result.html || '');
message.plain(result.text || '');
if (result.text) {
message.viewPlain();
} else {
if (html) {
message.html(html.replace(/<\/?script[\s\S]*?>/gi, '') || '');
message.viewHtml();
} else {
message.viewPlain();
}
});
return;
@ -722,7 +736,7 @@ export class MailMessageView extends AbstractViewRight {
if (params.Passphrase) {
rl.app.Remote.post('GnupgDecrypt', null, params)
.then(data => {
// TODO
// TODO mimeToMessage(data, message)
console.dir(data);
})
.catch(error => {