mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Add some basic support for Linked Data (Structured Email) #1422
This commit is contained in:
parent
ea07ea45b8
commit
be633f78a7
5 changed files with 322 additions and 3 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { createElement } from 'Common/Globals';
|
||||
import { forEachObjectEntry, pInt } from 'Common/Utils';
|
||||
import { forEachObjectEntry, isArray, pInt } from 'Common/Utils';
|
||||
import { SettingsUserStore } from 'Stores/User/Settings';
|
||||
|
||||
const
|
||||
|
|
@ -207,7 +207,8 @@ export const
|
|||
bqLevel = parseInt(SettingsUserStore.maxBlockquotesLevel()),
|
||||
|
||||
result = {
|
||||
hasExternals: false
|
||||
hasExternals: false,
|
||||
linkedData: []
|
||||
},
|
||||
|
||||
findAttachmentByCid = cId => oAttachments.findByCid(cId),
|
||||
|
|
@ -269,6 +270,7 @@ export const
|
|||
// Not supported by <template> element
|
||||
// .replace(/<!doctype[^>]*>/gi, '')
|
||||
// .replace(/<\?xml[^>]*\?>/gi, '')
|
||||
.replace(/<(\/?)head(\s[^>]*)?>/gi, '')
|
||||
.replace(/<(\/?)body(\s[^>]*)?>/gi, '<$1div class="mail-body"$2>')
|
||||
// .replace(/<\/?(html|head)[^>]*>/gi, '')
|
||||
// Fix Reddit https://github.com/the-djmaze/snappymail/issues/540
|
||||
|
|
@ -284,6 +286,21 @@ export const
|
|||
nodeIterator.referenceNode.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic support for Linked Data (Structured Email)
|
||||
* https://json-ld.org/
|
||||
* https://structured.email/
|
||||
**/
|
||||
tmpl.content.querySelectorAll('script[type="application/ld+json"]').forEach(oElement => {
|
||||
// Could be array of objects or single object
|
||||
try {
|
||||
const data = JSON.parse(oElement.textContent);
|
||||
(isArray(data) ? data : [data]).forEach(entry => result.linkedData.push(entry));
|
||||
} catch (e) {
|
||||
console.error(e, oElement.textContent);
|
||||
}
|
||||
});
|
||||
|
||||
tmpl.content.querySelectorAll(
|
||||
disallowedTags
|
||||
+ (0 < bqLevel ? ',' + (new Array(1 + bqLevel).fill('blockquote').join(' ')) : '')
|
||||
|
|
|
|||
|
|
@ -87,6 +87,12 @@ export class MessageModel extends AbstractModel {
|
|||
size: 0,
|
||||
readReceipt: '',
|
||||
preview: null,
|
||||
/**
|
||||
* Basic support for Linked Data (Structured Email)
|
||||
* https://json-ld.org/
|
||||
* https://structured.email/
|
||||
**/
|
||||
linkedData: [],
|
||||
|
||||
attachments: ko.observableArray(new AttachmentCollectionModel),
|
||||
threads: ko.observableArray(),
|
||||
|
|
@ -367,6 +373,7 @@ export class MessageModel extends AbstractModel {
|
|||
let result = msgHtml(this);
|
||||
this.hasExternals(result.hasExternals);
|
||||
this.hasImages(!!result.hasExternals);
|
||||
this.linkedData = result.linkedData;
|
||||
body.innerHTML = result.html;
|
||||
if (!this.isSpam && FolderUserStore.spamFolder() != this.folder) {
|
||||
if ('always' === SettingsUserStore.viewImages()) {
|
||||
|
|
|
|||
|
|
@ -1415,7 +1415,13 @@ export class ComposePopupView extends AbstractViewPopup {
|
|||
// Only used at send, not at save:
|
||||
dsn: this.requestDsn() ? 1 : 0,
|
||||
requireTLS: this.requireTLS() ? 1 : 0,
|
||||
readReceiptRequest: this.requestReadReceipt() ? 1 : 0
|
||||
readReceiptRequest: this.requestReadReceipt() ? 1 : 0,
|
||||
/**
|
||||
* Basic support for Linked Data (Structured Email)
|
||||
* https://json-ld.org/
|
||||
* https://structured.email/
|
||||
**/
|
||||
linkedData: []
|
||||
},
|
||||
recipients = draft ? [identity.email()] : this.allRecipients(),
|
||||
sign = !draft && this.pgpSign() && this.canPgpSign(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue