@social-mail/social-mail-web-server 1.7.253 → 1.7.256

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.7.253",
3
+ "version": "1.7.256",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -91,10 +91,10 @@ export default class MailboxEmailEvents extends AuthenticatedEvents<ChannelEmail
91
91
  async getBody(entity: ChannelEmail) {
92
92
  const ces = ServiceProvider.resolve(this, CachedEmailService);
93
93
  const ea = ServiceProvider.resolve(this, EmailAddressService);
94
- let file = await ces.getHtmlForRecipient(entity);
95
94
  const channel = await ea.getEmailAddress(entity.mailboxID);
96
-
97
95
  const blog = `@` + channel.emailAddress.split("@")[0];
96
+ let file = await ces.getHtmlForRecipient(entity, blog);
97
+
98
98
  file = RegExpExtra.replaceLinks(file, blog);
99
99
  return Content.text(file);
100
100
  }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  import { RegisterSingleton } from "@entity-access/entity-access/dist/di/di.js";
2
3
  import { JSDOM } from 'jsdom';
3
4
  import DOMPurify from 'dompurify';
@@ -96,7 +97,7 @@ export default class HtmlSanitizer {
96
97
  return clean.innerHTML;
97
98
  }
98
99
 
99
- sanitizeExternalResources(html: string, text: string, prefix) {
100
+ sanitizeExternalResources({ html, text, prefix, blog }: { html: string, text: string, prefix, blog?: string }) {
100
101
 
101
102
  const window = new JSDOM('', { url }).window;
102
103
  const purify = DOMPurify(window);
@@ -105,6 +106,13 @@ export default class HtmlSanitizer {
105
106
  for (const e of clean.querySelectorAll("*")) {
106
107
  this.replaceSrc(e, prefix);
107
108
  this.replaceBackground(e, prefix);
109
+ if (e.tagName !== "STYLE") {
110
+ if (e.childElementCount === 0) {
111
+ if(e.textContent) {
112
+ e.textContent = RegExpExtra.replaceLinks(e.textContent, blog);
113
+ }
114
+ }
115
+ }
108
116
  }
109
117
 
110
118
  html = clean?.outerHTML;
@@ -113,9 +121,6 @@ export default class HtmlSanitizer {
113
121
  for (const element of tokenizeCssUrl(html)) {
114
122
  html = html.replaceAll(element, element.replace(/https?\:\/\//, prefix));
115
123
  }
116
-
117
- html = RegExpExtra.replaceTimeAndEmail(html);
118
-
119
124
  return { html, text };
120
125
  }
121
126
 
@@ -27,7 +27,7 @@ export default class CachedEmailService {
27
27
 
28
28
  async getHtmlForRecipient({ emailID }: {
29
29
  emailID: number
30
- }) {
30
+ }, blog: string = "") {
31
31
 
32
32
  const factory = async () => {
33
33
 
@@ -68,7 +68,12 @@ export default class CachedEmailService {
68
68
  text = mail.text;
69
69
  }
70
70
  const htmlService = ServiceProvider.resolve(this, HtmlSanitizer);
71
- const result = htmlService.sanitizeExternalResources(html, text, `/api/emails/d/${ei}/${emailID}/`);
71
+ const result = htmlService.sanitizeExternalResources({
72
+ html,
73
+ text,
74
+ prefix: `/api/emails/d/${ei}/${emailID}/`,
75
+ blog
76
+ });
72
77
 
73
78
  const htmlFile = await this.tempFileService.createTempFile(".html", "text/html");
74
79
  await htmlFile.writeAllText(result.html || "");