@openfn/language-gmail 1.3.1 → 1.3.2
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.cjs +17 -14
- package/dist/index.js +17 -14
- package/package.json +1 -1
- package/types/Utils.d.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -147,8 +147,9 @@ async function getMessageContent(message, desiredContent) {
|
|
|
147
147
|
return `Unsupported content type: ${desiredContent.type}`;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
async function
|
|
150
|
+
async function buildAndSendMessage(message) {
|
|
151
151
|
const attachments = await parseAttachments(message.attachments);
|
|
152
|
+
const hasAttachments = attachments && attachments.length > 0;
|
|
152
153
|
const lines = [
|
|
153
154
|
`To: ${message.to}`,
|
|
154
155
|
`Subject: ${message.subject}`,
|
|
@@ -161,18 +162,20 @@ async function sendMessageWithAttachments(message) {
|
|
|
161
162
|
"",
|
|
162
163
|
message.body
|
|
163
164
|
];
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
165
|
+
if (hasAttachments) {
|
|
166
|
+
for (const attachment of attachments) {
|
|
167
|
+
const file = attachment.filename;
|
|
168
|
+
lines.push(
|
|
169
|
+
`--${SEND_MESSAGE_BOUNDARY}`,
|
|
170
|
+
`Content-Type: application/octet-stream; name="${file}"`,
|
|
171
|
+
"Content-Transfer-Encoding: base64",
|
|
172
|
+
`Content-Disposition: attachment; filename="${file}"`,
|
|
173
|
+
"",
|
|
174
|
+
attachment.content
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
lines.push(`--${SEND_MESSAGE_BOUNDARY}--`, "");
|
|
174
178
|
}
|
|
175
|
-
lines.push(`--${SEND_MESSAGE_BOUNDARY}--`, "");
|
|
176
179
|
const rawMessage = lines.join("\r\n");
|
|
177
180
|
const encodedMessage = Buffer.from(rawMessage).toString("base64");
|
|
178
181
|
try {
|
|
@@ -182,7 +185,7 @@ async function sendMessageWithAttachments(message) {
|
|
|
182
185
|
});
|
|
183
186
|
return result.data;
|
|
184
187
|
} catch (error) {
|
|
185
|
-
throw new Error("Error
|
|
188
|
+
throw new Error("Error sending message: " + error.message);
|
|
186
189
|
}
|
|
187
190
|
}
|
|
188
191
|
async function parseAttachments(attachments) {
|
|
@@ -418,7 +421,7 @@ function sendMessage(message) {
|
|
|
418
421
|
const messages = Array.isArray(resolvedMessage) ? resolvedMessage : [resolvedMessage];
|
|
419
422
|
const results = [];
|
|
420
423
|
for (const msg of messages) {
|
|
421
|
-
const result = await
|
|
424
|
+
const result = await buildAndSendMessage(msg);
|
|
422
425
|
results.push(result);
|
|
423
426
|
}
|
|
424
427
|
return {
|
package/dist/index.js
CHANGED
|
@@ -111,8 +111,9 @@ async function getMessageContent(message, desiredContent) {
|
|
|
111
111
|
return `Unsupported content type: ${desiredContent.type}`;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
async function
|
|
114
|
+
async function buildAndSendMessage(message) {
|
|
115
115
|
const attachments = await parseAttachments(message.attachments);
|
|
116
|
+
const hasAttachments = attachments && attachments.length > 0;
|
|
116
117
|
const lines = [
|
|
117
118
|
`To: ${message.to}`,
|
|
118
119
|
`Subject: ${message.subject}`,
|
|
@@ -125,18 +126,20 @@ async function sendMessageWithAttachments(message) {
|
|
|
125
126
|
"",
|
|
126
127
|
message.body
|
|
127
128
|
];
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
if (hasAttachments) {
|
|
130
|
+
for (const attachment of attachments) {
|
|
131
|
+
const file = attachment.filename;
|
|
132
|
+
lines.push(
|
|
133
|
+
`--${SEND_MESSAGE_BOUNDARY}`,
|
|
134
|
+
`Content-Type: application/octet-stream; name="${file}"`,
|
|
135
|
+
"Content-Transfer-Encoding: base64",
|
|
136
|
+
`Content-Disposition: attachment; filename="${file}"`,
|
|
137
|
+
"",
|
|
138
|
+
attachment.content
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
lines.push(`--${SEND_MESSAGE_BOUNDARY}--`, "");
|
|
138
142
|
}
|
|
139
|
-
lines.push(`--${SEND_MESSAGE_BOUNDARY}--`, "");
|
|
140
143
|
const rawMessage = lines.join("\r\n");
|
|
141
144
|
const encodedMessage = Buffer.from(rawMessage).toString("base64");
|
|
142
145
|
try {
|
|
@@ -146,7 +149,7 @@ async function sendMessageWithAttachments(message) {
|
|
|
146
149
|
});
|
|
147
150
|
return result.data;
|
|
148
151
|
} catch (error) {
|
|
149
|
-
throw new Error("Error
|
|
152
|
+
throw new Error("Error sending message: " + error.message);
|
|
150
153
|
}
|
|
151
154
|
}
|
|
152
155
|
async function parseAttachments(attachments) {
|
|
@@ -397,7 +400,7 @@ function sendMessage(message) {
|
|
|
397
400
|
const messages = Array.isArray(resolvedMessage) ? resolvedMessage : [resolvedMessage];
|
|
398
401
|
const results = [];
|
|
399
402
|
for (const msg of messages) {
|
|
400
|
-
const result = await
|
|
403
|
+
const result = await buildAndSendMessage(msg);
|
|
401
404
|
results.push(result);
|
|
402
405
|
}
|
|
403
406
|
return {
|
package/package.json
CHANGED
package/types/Utils.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export function getMessageResult(userId: any, messageId: any): Promise<{
|
|
|
10
10
|
}>;
|
|
11
11
|
export function getContentIndicators(defaultContentRequests?: any[], contentRequests?: any[]): any[];
|
|
12
12
|
export function getMessageContent(message: any, desiredContent: any): Promise<any>;
|
|
13
|
-
export function
|
|
13
|
+
export function buildAndSendMessage(message: any): Promise<any>;
|
|
14
14
|
export function createConnection(state: any): any;
|
|
15
15
|
export function removeConnection(state: any): any;
|