mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 08:27:03 +03:00
Resolve #248 View eml attachments
This commit is contained in:
parent
17de4268b0
commit
e205a0d3e0
4 changed files with 62 additions and 64 deletions
|
|
@ -35,16 +35,20 @@ export const
|
||||||
* @param {string} text
|
* @param {string} text
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
cleanHtml = (html, contentLocationUrls, removeColors) => {
|
cleanHtml = (html, oAttachments, removeColors) => {
|
||||||
const
|
const
|
||||||
debug = false, // Config()->Get('debug', 'enable', false);
|
debug = false, // Config()->Get('debug', 'enable', false);
|
||||||
useProxy = !!SettingsGet('UseLocalProxyForExternalImages'),
|
useProxy = !!SettingsGet('UseLocalProxyForExternalImages'),
|
||||||
detectHiddenImages = true, // !!SettingsGet('try_to_detect_hidden_images'),
|
detectHiddenImages = true, // !!SettingsGet('try_to_detect_hidden_images'),
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
hasExternals: false,
|
hasExternals: false
|
||||||
foundCIDs: [],
|
},
|
||||||
foundContentLocationUrls: []
|
|
||||||
|
findAttachmentByCid = cid => oAttachments.findByCid(cid),
|
||||||
|
findLocationByCid = cid => {
|
||||||
|
const attachment = findAttachmentByCid(cid);
|
||||||
|
return attachment && attachment.contentLocation ? attachment : 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
// convert body attributes to CSS
|
// convert body attributes to CSS
|
||||||
|
|
@ -223,6 +227,8 @@ export const
|
||||||
value = getAttribute('src');
|
value = getAttribute('src');
|
||||||
delAttribute('src');
|
delAttribute('src');
|
||||||
|
|
||||||
|
let attachment;
|
||||||
|
|
||||||
if (detectHiddenImages
|
if (detectHiddenImages
|
||||||
&& 'IMG' === name
|
&& 'IMG' === name
|
||||||
&& (('' != getAttribute('height') && 3 > pInt(getAttribute('height')))
|
&& (('' != getAttribute('height') && 3 > pInt(getAttribute('height')))
|
||||||
|
|
@ -238,15 +244,22 @@ export const
|
||||||
setAttribute('style', 'display:none');
|
setAttribute('style', 'display:none');
|
||||||
setAttribute('data-x-hidden-src', value);
|
setAttribute('data-x-hidden-src', value);
|
||||||
}
|
}
|
||||||
else if (contentLocationUrls[value])
|
else if ((attachment = findLocationByCid(value)))
|
||||||
{
|
{
|
||||||
setAttribute('data-x-src-location', value);
|
if (attachment.download) {
|
||||||
result.foundContentLocationUrls.push(value);
|
oElement.loading = 'lazy';
|
||||||
|
oElement.src = attachment.linkPreview();
|
||||||
|
attachment.isLinked(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ('cid:' === value.slice(0, 4))
|
else if ('cid:' === value.slice(0, 4))
|
||||||
{
|
{
|
||||||
setAttribute('data-x-src-cid', value.slice(4));
|
attachment = findAttachmentByCid(value.slice(4));
|
||||||
result.foundCIDs.push(value.slice(4));
|
if (attachment && attachment.download) {
|
||||||
|
oElement.src = attachment.linkPreview();
|
||||||
|
attachment.isInline(true);
|
||||||
|
attachment.isLinked(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (/^(https?:)?\/\//i.test(value))
|
else if (/^(https?:)?\/\//i.test(value))
|
||||||
{
|
{
|
||||||
|
|
@ -289,7 +302,6 @@ export const
|
||||||
oStyle.removeProperty('min-width');
|
oStyle.removeProperty('min-width');
|
||||||
|
|
||||||
const urls = {
|
const urls = {
|
||||||
cid: [], // 'data-x-style-cid'
|
|
||||||
remote: [], // 'data-x-style-url'
|
remote: [], // 'data-x-style-url'
|
||||||
broken: [] // 'data-x-broken-style-src'
|
broken: [] // 'data-x-broken-style-src'
|
||||||
};
|
};
|
||||||
|
|
@ -302,9 +314,12 @@ export const
|
||||||
found = found[0].replace(/^["'\s]+|["'\s]+$/g, '');
|
found = found[0].replace(/^["'\s]+|["'\s]+$/g, '');
|
||||||
let lowerUrl = found.toLowerCase();
|
let lowerUrl = found.toLowerCase();
|
||||||
if ('cid:' === lowerUrl.slice(0, 4)) {
|
if ('cid:' === lowerUrl.slice(0, 4)) {
|
||||||
found = found.slice(4);
|
const attachment = findAttachmentByCid(found);
|
||||||
urls.cid[property] = found
|
if (attachment && attachment.linkPreview && name) {
|
||||||
result.foundCIDs.push(found);
|
oStyle[property] = "url('" + attachment.linkPreview() + "')";
|
||||||
|
attachment.isInline(true);
|
||||||
|
attachment.isLinked(true);
|
||||||
|
}
|
||||||
} else if (/http[s]?:\/\//.test(lowerUrl) || '//' === found.slice(0, 2)) {
|
} else if (/http[s]?:\/\//.test(lowerUrl) || '//' === found.slice(0, 2)) {
|
||||||
result.hasExternals = true;
|
result.hasExternals = true;
|
||||||
urls.remote[property] = useProxy ? proxy(found) : found;
|
urls.remote[property] = useProxy ? proxy(found) : found;
|
||||||
|
|
@ -319,9 +334,6 @@ export const
|
||||||
// oStyle.removeProperty('background-image');
|
// oStyle.removeProperty('background-image');
|
||||||
// oStyle.removeProperty('list-style-image');
|
// oStyle.removeProperty('list-style-image');
|
||||||
|
|
||||||
if (urls.cid.length) {
|
|
||||||
setAttribute('data-x-style-cid', JSON.stringify(urls.cid));
|
|
||||||
}
|
|
||||||
if (urls.remote.length) {
|
if (urls.remote.length) {
|
||||||
setAttribute('data-x-style-url', JSON.stringify(urls.remote));
|
setAttribute('data-x-style-url', JSON.stringify(urls.remote));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
import { ParseMime } from 'Mime/Parser';
|
import { ParseMime } from 'Mime/Parser';
|
||||||
import { AttachmentModel } from 'Model/Attachment';
|
import { AttachmentModel } from 'Model/Attachment';
|
||||||
|
import { EmailModel } from 'Model/Email';
|
||||||
import { FileInfo } from 'Common/File';
|
import { FileInfo } from 'Common/File';
|
||||||
import { BEGIN_PGP_MESSAGE } from 'Stores/User/Pgp';
|
import { BEGIN_PGP_MESSAGE } from 'Stores/User/Pgp';
|
||||||
|
|
||||||
|
|
@ -16,6 +17,17 @@ export function MimeToMessage(data, message)
|
||||||
let html = struct.getByContentType('text/html');
|
let html = struct.getByContentType('text/html');
|
||||||
html = html ? html.body : '';
|
html = html ? html.body : '';
|
||||||
|
|
||||||
|
if (struct.headers.subject) {
|
||||||
|
message.subject(struct.headers.subject.value);
|
||||||
|
}
|
||||||
|
['from','to'].forEach(name => {
|
||||||
|
if (struct.headers[name]) {
|
||||||
|
let mail = new EmailModel;
|
||||||
|
mail.parse(struct.headers[name].value);
|
||||||
|
message[name].push(mail);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
struct.forEach(part => {
|
struct.forEach(part => {
|
||||||
let cd = part.header('content-disposition'),
|
let cd = part.header('content-disposition'),
|
||||||
cid = part.header('content-id'),
|
cid = part.header('content-id'),
|
||||||
|
|
|
||||||
|
|
@ -381,60 +381,15 @@ export class MessageModel extends AbstractModel {
|
||||||
viewHtml() {
|
viewHtml() {
|
||||||
const body = this.body;
|
const body = this.body;
|
||||||
if (body && this.html()) {
|
if (body && this.html()) {
|
||||||
const contentLocationUrls = {},
|
let result = cleanHtml(this.html(), this.attachments(), SettingsUserStore.removeColors());
|
||||||
oAttachments = this.attachments();
|
|
||||||
|
|
||||||
// Get contentLocationUrls
|
|
||||||
oAttachments.forEach(oAttachment => {
|
|
||||||
if (oAttachment.cid && oAttachment.contentLocation) {
|
|
||||||
contentLocationUrls[oAttachment.contentId()] = oAttachment.contentLocation;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = cleanHtml(this.html(), contentLocationUrls, SettingsUserStore.removeColors());
|
|
||||||
this.hasExternals(result.hasExternals);
|
this.hasExternals(result.hasExternals);
|
||||||
// this.hasInternals = result.foundCIDs.length || result.foundContentLocationUrls.length;
|
|
||||||
this.hasImages(body.rlHasImages = !!result.hasExternals);
|
this.hasImages(body.rlHasImages = !!result.hasExternals);
|
||||||
|
|
||||||
// Hide valid inline attachments in message view 'attachments' section
|
|
||||||
oAttachments.forEach(oAttachment => {
|
|
||||||
let cid = oAttachment.contentId(),
|
|
||||||
found = result.foundCIDs.includes(cid);
|
|
||||||
oAttachment.isInline(found);
|
|
||||||
oAttachment.isLinked(found || result.foundContentLocationUrls.includes(oAttachment.contentLocation));
|
|
||||||
});
|
|
||||||
|
|
||||||
body.innerHTML = result.html;
|
body.innerHTML = result.html;
|
||||||
|
|
||||||
body.classList.toggle('html', 1);
|
body.classList.toggle('html', 1);
|
||||||
body.classList.toggle('plain', 0);
|
body.classList.toggle('plain', 0);
|
||||||
|
|
||||||
// showInternalImages
|
|
||||||
const findAttachmentByCid = cid => this.attachments().findByCid(cid);
|
|
||||||
body.querySelectorAll('[data-x-src-cid],[data-x-src-location],[data-x-style-cid]').forEach(el => {
|
|
||||||
const data = el.dataset;
|
|
||||||
if (data.xSrcCid) {
|
|
||||||
const attachment = findAttachmentByCid(data.xSrcCid);
|
|
||||||
if (attachment && attachment.download) {
|
|
||||||
el.src = attachment.linkPreview();
|
|
||||||
}
|
|
||||||
} else if (data.xSrcLocation) {
|
|
||||||
const attachment = this.attachments.find(item => data.xSrcLocation === item.contentLocation)
|
|
||||||
|| findAttachmentByCid(data.xSrcLocation);
|
|
||||||
if (attachment && attachment.download) {
|
|
||||||
el.loading = 'lazy';
|
|
||||||
el.src = attachment.linkPreview();
|
|
||||||
}
|
|
||||||
} else if (data.xStyleCid) {
|
|
||||||
forEachObjectEntry(JSON.parse(data.xStyleCid), (name, cid) => {
|
|
||||||
const attachment = findAttachmentByCid(cid);
|
|
||||||
if (attachment && attachment.linkPreview && name) {
|
|
||||||
el.style[name] = "url('" + attachment.linkPreview() + "')";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (SettingsUserStore.showImages()) {
|
if (SettingsUserStore.showImages()) {
|
||||||
this.showExternalImages();
|
this.showExternalImages();
|
||||||
}
|
}
|
||||||
|
|
@ -608,7 +563,8 @@ export class MessageModel extends AbstractModel {
|
||||||
);
|
);
|
||||||
return clone.innerHTML;
|
return clone.innerHTML;
|
||||||
}
|
}
|
||||||
return this.html() || plainToHtml(this.plain());
|
let result = cleanHtml(this.html(), this.attachments(), SettingsUserStore.removeColors())
|
||||||
|
return result.html || plainToHtml(this.plain());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ import { PgpUserStore } from 'Stores/User/Pgp';
|
||||||
|
|
||||||
import { MimeToMessage } from 'Mime/Utils';
|
import { MimeToMessage } from 'Mime/Utils';
|
||||||
|
|
||||||
|
import { MessageModel } from 'Model/Message';
|
||||||
|
|
||||||
const
|
const
|
||||||
oMessageScrollerDom = () => elementById('messageItem') || {},
|
oMessageScrollerDom = () => elementById('messageItem') || {},
|
||||||
|
|
||||||
|
|
@ -296,7 +298,23 @@ export class MailMessageView extends AbstractViewRight {
|
||||||
el = eqs(event, '.attachmentsPlace .attachmentItem .attachmentNameParent');
|
el = eqs(event, '.attachmentsPlace .attachmentItem .attachmentNameParent');
|
||||||
if (el) {
|
if (el) {
|
||||||
const attachment = ko.dataFor(el);
|
const attachment = ko.dataFor(el);
|
||||||
attachment && attachment.linkDownload() && download(attachment.linkDownload(), attachment.fileName);
|
if (attachment && attachment.linkDownload()) {
|
||||||
|
if ('message/rfc822' == attachment.mimeType) {
|
||||||
|
// TODO
|
||||||
|
rl.fetch(attachment.linkDownload()).then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
response.text().then(text => {
|
||||||
|
const oMessage = new MessageModel();
|
||||||
|
MimeToMessage(text, oMessage);
|
||||||
|
// cleanHTML
|
||||||
|
oMessage.viewPopupMessage();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
download(attachment.linkDownload(), attachment.fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eqs(event, '.messageItemHeader .subjectParent .flagParent')) {
|
if (eqs(event, '.messageItemHeader .subjectParent .flagParent')) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue