groundmail-nodemailer 0.15.45 → 0.15.46
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/dist/index.js +11 -3
- package/package.json +2 -2
- package/src/transport.ts +18 -3
package/dist/index.js
CHANGED
|
@@ -58,12 +58,20 @@ function headerMap(headers) {
|
|
|
58
58
|
}
|
|
59
59
|
return out;
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
var TEXT_ENCODINGS = /* @__PURE__ */ new Set(["utf8", "usascii", "ascii"]);
|
|
62
|
+
async function attachmentContentToBase64(content, encoding) {
|
|
62
63
|
if (content == null) {
|
|
63
64
|
throw new Error("Attachment is missing content");
|
|
64
65
|
}
|
|
65
66
|
if (typeof content === "string") {
|
|
66
|
-
|
|
67
|
+
const enc = String(encoding || "utf8").toLowerCase().replace(/[-_\s]/g, "");
|
|
68
|
+
if (TEXT_ENCODINGS.has(enc)) {
|
|
69
|
+
return Buffer.from(content).toString("base64");
|
|
70
|
+
}
|
|
71
|
+
if (!Buffer.isEncoding(enc)) {
|
|
72
|
+
throw new Error(`Unsupported attachment encoding "${String(encoding)}"`);
|
|
73
|
+
}
|
|
74
|
+
return Buffer.from(content, enc).toString("base64");
|
|
67
75
|
}
|
|
68
76
|
if (Buffer.isBuffer(content)) {
|
|
69
77
|
return content.toString("base64");
|
|
@@ -110,7 +118,7 @@ async function mailDataToSendParams(data) {
|
|
|
110
118
|
return {
|
|
111
119
|
filename: String(filename),
|
|
112
120
|
contentType,
|
|
113
|
-
content: await attachmentContentToBase64(att.content),
|
|
121
|
+
content: await attachmentContentToBase64(att.content, att.encoding),
|
|
114
122
|
...att.cid ? { contentId: String(att.cid) } : {}
|
|
115
123
|
};
|
|
116
124
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "groundmail-nodemailer",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.46",
|
|
4
4
|
"description": "Nodemailer transport for Groundmail (HTTP API, not SMTP)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"groundmail": ">=0.13.0"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"groundmail": "0.52.
|
|
49
|
+
"groundmail": "0.52.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/nodemailer": "^8.0.2",
|
package/src/transport.ts
CHANGED
|
@@ -78,12 +78,27 @@ function headerMap(headers: MailMessage['data']['headers']): Record<string, stri
|
|
|
78
78
|
return out
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
const TEXT_ENCODINGS = new Set(['utf8', 'usascii', 'ascii'])
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* `encoding` says how a string `content` is encoded ("base64", "hex", …), the same way
|
|
85
|
+
* Nodemailer reads it: the string is decoded to bytes first. It is ignored for Buffers.
|
|
86
|
+
*/
|
|
87
|
+
async function attachmentContentToBase64(content: unknown, encoding?: unknown): Promise<string> {
|
|
82
88
|
if (content == null) {
|
|
83
89
|
throw new Error('Attachment is missing content')
|
|
84
90
|
}
|
|
85
91
|
if (typeof content === 'string') {
|
|
86
|
-
|
|
92
|
+
const enc = String(encoding || 'utf8')
|
|
93
|
+
.toLowerCase()
|
|
94
|
+
.replace(/[-_\s]/g, '')
|
|
95
|
+
if (TEXT_ENCODINGS.has(enc)) {
|
|
96
|
+
return Buffer.from(content).toString('base64')
|
|
97
|
+
}
|
|
98
|
+
if (!Buffer.isEncoding(enc)) {
|
|
99
|
+
throw new Error(`Unsupported attachment encoding "${String(encoding)}"`)
|
|
100
|
+
}
|
|
101
|
+
return Buffer.from(content, enc).toString('base64')
|
|
87
102
|
}
|
|
88
103
|
if (Buffer.isBuffer(content)) {
|
|
89
104
|
return content.toString('base64')
|
|
@@ -137,7 +152,7 @@ export async function mailDataToSendParams(data: MailMessage['data']): Promise<S
|
|
|
137
152
|
return {
|
|
138
153
|
filename: String(filename),
|
|
139
154
|
contentType,
|
|
140
|
-
content: await attachmentContentToBase64(att.content),
|
|
155
|
+
content: await attachmentContentToBase64(att.content, att.encoding),
|
|
141
156
|
...(att.cid ? { contentId: String(att.cid) } : {}),
|
|
142
157
|
}
|
|
143
158
|
}),
|