@travetto/email 2.1.1 → 2.1.4

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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/src/util.ts +16 -9
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/email",
3
3
  "displayName": "Email",
4
- "version": "2.1.1",
4
+ "version": "2.1.4",
5
5
  "description": "Email transmission module.",
6
6
  "keywords": [
7
7
  "email",
@@ -24,19 +24,19 @@
24
24
  "directory": "module/email"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/config": "^2.1.1",
28
- "@travetto/di": "^2.1.1",
29
- "@types/mustache": "^4.1.2",
27
+ "@travetto/config": "^2.1.3",
28
+ "@travetto/di": "^2.1.3",
29
+ "@types/mustache": "^4.1.3",
30
30
  "mustache": "^4.2.0"
31
31
  },
32
32
  "optionalPeerDependencies": {
33
- "nodemailer": "^6.7.2",
33
+ "nodemailer": "^6.7.5",
34
34
  "@types/nodemailer": "^6.4.4"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
39
  "docDependencies": {
40
- "@aws-sdk/client-ses": "^3.53.0"
40
+ "@aws-sdk/client-ses": "^3.118.0"
41
41
  }
42
42
  }
package/src/util.ts CHANGED
@@ -10,18 +10,25 @@ export class MailUtil {
10
10
  * @param html
11
11
  */
12
12
  static async extractImageAttachments(html: string) {
13
- let x = 0;
13
+ let idx = 0;
14
14
  const attachments: Attachment[] = [];
15
+ const contentMap = new Map<string, string>();
15
16
 
16
17
  html = html.replace(/data:(image\/[^;]+);base64,([^"]+)/g, (__, type, content) => {
17
- const cid = `${++x}`;
18
- attachments!.push({
19
- cid,
20
- content: Buffer.from(content, 'base64'),
21
- contentDisposition: 'inline',
22
- contentType: type
23
- });
24
- return `cid:${cid}`;
18
+ // Ensure same data uris map to a single cid
19
+ if (!contentMap.has(content)) {
20
+ const cid = `${idx += 1}`;
21
+ attachments.push({
22
+ cid,
23
+ content: Buffer.from(content, 'base64'),
24
+ contentDisposition: 'inline',
25
+ contentType: type
26
+ });
27
+ contentMap.set(content, cid);
28
+ return `cid:${cid}`;
29
+ } else {
30
+ return contentMap.get(content)!;
31
+ }
25
32
  });
26
33
 
27
34
  return {