mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 08:27:03 +03:00
#89 show decrypted HTML with inline attachments
This commit is contained in:
parent
8a4ea92cfb
commit
4eb70c3f06
2 changed files with 30 additions and 20 deletions
|
|
@ -95,7 +95,6 @@ export class MessageModel extends AbstractModel {
|
||||||
focused: false,
|
focused: false,
|
||||||
selected: false,
|
selected: false,
|
||||||
checked: false,
|
checked: false,
|
||||||
hasAttachments: false,
|
|
||||||
|
|
||||||
isHtml: false,
|
isHtml: false,
|
||||||
hasImages: false,
|
hasImages: false,
|
||||||
|
|
@ -174,7 +173,6 @@ export class MessageModel extends AbstractModel {
|
||||||
|
|
||||||
this.selected(false);
|
this.selected(false);
|
||||||
this.checked(false);
|
this.checked(false);
|
||||||
this.hasAttachments(false);
|
|
||||||
|
|
||||||
this.isHtml(false);
|
this.isHtml(false);
|
||||||
this.hasImages(false);
|
this.hasImages(false);
|
||||||
|
|
@ -229,7 +227,6 @@ export class MessageModel extends AbstractModel {
|
||||||
json.Priority = MessagePriority.Normal;
|
json.Priority = MessagePriority.Normal;
|
||||||
}
|
}
|
||||||
if (super.revivePropertiesFromJson(json)) {
|
if (super.revivePropertiesFromJson(json)) {
|
||||||
this.hasAttachments(!!this.attachments.length);
|
|
||||||
// this.foundCIDs = isArray(json.FoundCIDs) ? json.FoundCIDs : [];
|
// this.foundCIDs = isArray(json.FoundCIDs) ? json.FoundCIDs : [];
|
||||||
// this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundCIDs));
|
// this.attachments(AttachmentCollectionModel.reviveFromJson(json.Attachments, this.foundCIDs));
|
||||||
|
|
||||||
|
|
@ -324,7 +321,7 @@ export class MessageModel extends AbstractModel {
|
||||||
forwarded: this.isForwarded(),
|
forwarded: this.isForwarded(),
|
||||||
focused: this.focused(),
|
focused: this.focused(),
|
||||||
important: this.isImportant(),
|
important: this.isImportant(),
|
||||||
withAttachments: this.hasAttachments(),
|
withAttachments: !!this.attachments().length,
|
||||||
emptySubject: !this.subject(),
|
emptySubject: !this.subject(),
|
||||||
// hasChildrenMessage: 1 < this.threadsLen(),
|
// hasChildrenMessage: 1 < this.threadsLen(),
|
||||||
hasUnseenSubMessage: this.hasUnseenSubMessage(),
|
hasUnseenSubMessage: this.hasUnseenSubMessage(),
|
||||||
|
|
@ -577,7 +574,6 @@ export class MessageModel extends AbstractModel {
|
||||||
|
|
||||||
this.selected(message.selected());
|
this.selected(message.selected());
|
||||||
this.checked(message.checked());
|
this.checked(message.checked());
|
||||||
this.hasAttachments(message.hasAttachments());
|
|
||||||
this.attachments(message.attachments());
|
this.attachments(message.attachments());
|
||||||
|
|
||||||
this.threads(message.threads());
|
this.threads(message.threads());
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
|
||||||
const currentMessage = () => MessageUserStore.message();
|
const currentMessage = () => MessageUserStore.message();
|
||||||
|
|
||||||
import PostalMime from '../../../../vendors/postal-mime/src/postal-mime.js';
|
import PostalMime from '../../../../vendors/postal-mime/src/postal-mime.js';
|
||||||
|
import { AttachmentModel } from 'Model/Attachment';
|
||||||
|
|
||||||
const mimeToMessage = (data, message) => {
|
const mimeToMessage = (data, message) => {
|
||||||
// TODO: Check multipart/signed
|
// TODO: Check multipart/signed
|
||||||
|
|
@ -53,23 +54,36 @@ const mimeToMessage = (data, message) => {
|
||||||
if (/Content-Type:.+; boundary=/.test(headers)) {
|
if (/Content-Type:.+; boundary=/.test(headers)) {
|
||||||
// https://github.com/postalsys/postal-mime
|
// https://github.com/postalsys/postal-mime
|
||||||
(new PostalMime).parse(data).then(result => {
|
(new PostalMime).parse(data).then(result => {
|
||||||
/*
|
let html = result.html,
|
||||||
result.attachments[0] = {
|
regex = /^<+|>+$/g;
|
||||||
content: ArrayBuffer
|
result.attachments.forEach(data => {
|
||||||
disposition: null
|
let attachment = new AttachmentModel;
|
||||||
filename: "signature.asc"
|
attachment.mimeType = data.mimeType;
|
||||||
mimeType: "application/pgp-signature"
|
attachment.fileName = data.filename;
|
||||||
};
|
attachment.content = data.content; // ArrayBuffer
|
||||||
result.headers;
|
attachment.cid = data.contentId || '';
|
||||||
*/
|
// Parse inline attachments from result.attachments
|
||||||
// TODO: 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
|
// TODO: strip script tags and all other security that PHP also does
|
||||||
message.html(result.html || '');
|
|
||||||
message.plain(result.text || '');
|
message.plain(result.text || '');
|
||||||
if (result.text) {
|
if (html) {
|
||||||
message.viewPlain();
|
message.html(html.replace(/<\/?script[\s\S]*?>/gi, '') || '');
|
||||||
} else {
|
|
||||||
message.viewHtml();
|
message.viewHtml();
|
||||||
|
} else {
|
||||||
|
message.viewPlain();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|
@ -722,7 +736,7 @@ export class MailMessageView extends AbstractViewRight {
|
||||||
if (params.Passphrase) {
|
if (params.Passphrase) {
|
||||||
rl.app.Remote.post('GnupgDecrypt', null, params)
|
rl.app.Remote.post('GnupgDecrypt', null, params)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// TODO
|
// TODO mimeToMessage(data, message)
|
||||||
console.dir(data);
|
console.dir(data);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue