diff --git a/dev/Common/Html.js b/dev/Common/Html.js
index 08dc2b559..a34966981 100644
--- a/dev/Common/Html.js
+++ b/dev/Common/Html.js
@@ -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 element
// .replace(/]*>/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(' ')) : '')
diff --git a/dev/Model/Message.js b/dev/Model/Message.js
index a6868dc3e..4086be5cd 100644
--- a/dev/Model/Message.js
+++ b/dev/Model/Message.js
@@ -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()) {
diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js
index 35a33fc1f..34a08babf 100644
--- a/dev/View/Popup/Compose.js
+++ b/dev/View/Popup/Compose.js
@@ -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(),
diff --git a/examples/eml/json-ld.eml b/examples/eml/json-ld.eml
new file mode 100644
index 000000000..099c3a37e
--- /dev/null
+++ b/examples/eml/json-ld.eml
@@ -0,0 +1,283 @@
+Return-Path:
+Delivered-To: json-ld@example.com
+MIME-Version: 1.0
+Date: Mon, 05 Feb 2024 12:37:15 +0000
+Content-Type: multipart/alternative;
+ boundary="46987ad0-df2c-4cc8-8c7b-20e34b1f9bbf-1"
+From: json-ld@example.com
+Message-ID: <2cb0cdd30d1a7ec8c810710da8dc14eedaf10e7e@example.com>
+TLS-Required: No
+Subject: test json-ld
+To: json-ld@example.com
+
+--46987ad0-df2c-4cc8-8c7b-20e34b1f9bbf-1
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+test json-ld
+--46987ad0-df2c-4cc8-8c7b-20e34b1f9bbf-1
+Content-Type: text/html; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+
+
+
+Example of Linked Data (Structured Email)
+
+
+--46987ad0-df2c-4cc8-8c7b-20e34b1f9bbf-1--
diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php
index 6552ec0c1..96f42afa0 100644
--- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php
+++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php
@@ -1066,6 +1066,12 @@ trait Messages
$oMessage->SubParts->append($oPart);
$sHtml = \MailSo\Base\HtmlUtils::BuildHtml($sHtml, $aFoundCids, $aFoundDataURL, $aFoundContentLocationUrls);
+
+ $aLinkedData = $this->GetActionParam('linkedData', []);
+ if ($aLinkedData) {
+ $sHtml = \str_replace('', '', $sHtml);
+ }
+
$this->Plugins()->RunHook('filter.message-html', array($oAccount, $oMessage, &$sHtml));
// First add plain