gmail-workspace-mcp-server 0.2.0 → 0.2.1
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
|
@@ -11,6 +11,16 @@ export interface MimeMessageOptions {
|
|
|
11
11
|
inReplyTo?: string;
|
|
12
12
|
references?: string;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Encodes a string as an RFC 2047 encoded-word using UTF-8 and Base64.
|
|
16
|
+
* Only encodes if the string contains non-ASCII characters.
|
|
17
|
+
*
|
|
18
|
+
* Note: RFC 2047 limits encoded-words to 75 characters. Very long non-ASCII
|
|
19
|
+
* subjects should technically be split into multiple encoded-words separated
|
|
20
|
+
* by folding whitespace. In practice, Gmail handles oversized encoded-words
|
|
21
|
+
* correctly, so we encode as a single word for simplicity.
|
|
22
|
+
*/
|
|
23
|
+
export declare function encodeSubject(subject: string): string;
|
|
14
24
|
/**
|
|
15
25
|
* Builds a MIME message from email options.
|
|
16
26
|
* If both plaintextBody and htmlBody are provided, creates a multipart/alternative message.
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MIME message utilities for building and encoding email messages
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* Encodes a string as an RFC 2047 encoded-word using UTF-8 and Base64.
|
|
6
|
+
* Only encodes if the string contains non-ASCII characters.
|
|
7
|
+
*
|
|
8
|
+
* Note: RFC 2047 limits encoded-words to 75 characters. Very long non-ASCII
|
|
9
|
+
* subjects should technically be split into multiple encoded-words separated
|
|
10
|
+
* by folding whitespace. In practice, Gmail handles oversized encoded-words
|
|
11
|
+
* correctly, so we encode as a single word for simplicity.
|
|
12
|
+
*/
|
|
13
|
+
export function encodeSubject(subject) {
|
|
14
|
+
// eslint-disable-next-line no-control-regex
|
|
15
|
+
if (!/[^\x00-\x7F]/.test(subject)) {
|
|
16
|
+
return subject;
|
|
17
|
+
}
|
|
18
|
+
const encoded = Buffer.from(subject, 'utf-8').toString('base64');
|
|
19
|
+
return `=?UTF-8?B?${encoded}?=`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Strips leading newline characters (\r\n, \n, and bare \r) from email body content.
|
|
23
|
+
* Prevents extra blank lines at the top of the email when displayed in Gmail.
|
|
24
|
+
*/
|
|
25
|
+
function stripLeadingNewlines(body) {
|
|
26
|
+
return body.replace(/^[\r\n]+/, '');
|
|
27
|
+
}
|
|
4
28
|
/**
|
|
5
29
|
* Builds a MIME message from email options.
|
|
6
30
|
* If both plaintextBody and htmlBody are provided, creates a multipart/alternative message.
|
|
@@ -10,7 +34,7 @@ export function buildMimeMessage(from, options) {
|
|
|
10
34
|
const headers = [
|
|
11
35
|
`From: ${from}`,
|
|
12
36
|
`To: ${options.to}`,
|
|
13
|
-
`Subject: ${options.subject}`,
|
|
37
|
+
`Subject: ${encodeSubject(options.subject)}`,
|
|
14
38
|
'MIME-Version: 1.0',
|
|
15
39
|
];
|
|
16
40
|
if (options.cc) {
|
|
@@ -29,9 +53,11 @@ export function buildMimeMessage(from, options) {
|
|
|
29
53
|
if (options.plaintextBody && options.htmlBody) {
|
|
30
54
|
const boundary = `boundary_${Date.now()}_${Math.random().toString(36).substring(2)}`;
|
|
31
55
|
headers.push(`Content-Type: multipart/alternative; boundary="${boundary}"`);
|
|
56
|
+
const plainBody = stripLeadingNewlines(options.plaintextBody);
|
|
57
|
+
const htmlBody = stripLeadingNewlines(options.htmlBody);
|
|
32
58
|
const parts = [
|
|
33
|
-
`--${boundary}\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n${
|
|
34
|
-
`--${boundary}\r\nContent-Type: text/html; charset=utf-8\r\n\r\n${
|
|
59
|
+
`--${boundary}\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n${plainBody}`,
|
|
60
|
+
`--${boundary}\r\nContent-Type: text/html; charset=utf-8\r\n\r\n${htmlBody}`,
|
|
35
61
|
`--${boundary}--`,
|
|
36
62
|
];
|
|
37
63
|
return headers.join('\r\n') + '\r\n\r\n' + parts.join('\r\n');
|
|
@@ -39,10 +65,10 @@ export function buildMimeMessage(from, options) {
|
|
|
39
65
|
// Single content type
|
|
40
66
|
if (options.htmlBody) {
|
|
41
67
|
headers.push('Content-Type: text/html; charset=utf-8');
|
|
42
|
-
return headers.join('\r\n') + '\r\n\r\n' + options.htmlBody;
|
|
68
|
+
return headers.join('\r\n') + '\r\n\r\n' + stripLeadingNewlines(options.htmlBody);
|
|
43
69
|
}
|
|
44
70
|
headers.push('Content-Type: text/plain; charset=utf-8');
|
|
45
|
-
return headers.join('\r\n') + '\r\n\r\n' + (options.plaintextBody ?? '');
|
|
71
|
+
return headers.join('\r\n') + '\r\n\r\n' + stripLeadingNewlines(options.plaintextBody ?? '');
|
|
46
72
|
}
|
|
47
73
|
/**
|
|
48
74
|
* Converts a string to base64url encoding (RFC 4648)
|