Skip to content

Commit 781e943

Browse files
committed
Fixing address parsing in replyAll option
1 parent 0b409f1 commit 781e943

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

components/gmail/actions/send-email/send-email.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "gmail-send-email",
77
name: "Send Email",
88
description: "Send an email from your Google Workspace email account. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send)",
9-
version: "0.1.16",
9+
version: "0.1.17",
1010
annotations: {
1111
destructiveHint: false,
1212
openWorldHint: true,

components/gmail/gmail.app.mjs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { convert } from "html-to-text";
77
import mime from "mime/types/standard.js";
88
import MailComposer from "nodemailer/lib/mail-composer/index.js";
9+
import addressparser from "nodemailer/lib/addressparser/index.js";
910
import constants from "./common/constants.mjs";
1011
import { JWT } from "google-auth-library";
1112

@@ -273,6 +274,27 @@ export default {
273274
auth,
274275
});
275276
},
277+
/**
278+
* Parse email addresses from a string
279+
* @param {string} addressString - Raw address string to parse
280+
* @returns {string[]} Array of properly formatted email addresses
281+
*/
282+
parseEmailAddresses(addressString) {
283+
if (!addressString || typeof addressString !== "string") {
284+
return [];
285+
}
286+
287+
// Use nodemailer's addressparser to properly handle RFC 5322 format
288+
const parsed = addressparser(addressString.trim());
289+
290+
// Reconstruct addresses in standard format
291+
return parsed.map((addr) => {
292+
if (addr.name) {
293+
return `${addr.name} <${addr.address}>`;
294+
}
295+
return addr.address;
296+
});
297+
},
276298
async getOptionsToSendEmail($, props) {
277299
const {
278300
name: fromName,
@@ -308,8 +330,10 @@ export default {
308330
const to = repliedMessage.payload.headers.find(({ name }) => name.toLowerCase() === "to");
309331
const cc = repliedMessage.payload.headers.find(({ name }) => name.toLowerCase() === "cc");
310332
const bcc = repliedMessage.payload.headers.find(({ name }) => name.toLowerCase() === "bcc");
311-
opts.to = from.value.split(",");
312-
opts.to.push(...to.value.split(","));
333+
opts.to = [
334+
...this.parseEmailAddresses(from.value),
335+
...this.parseEmailAddresses(to.value),
336+
];
313337

314338
// Filter out the current user's email address
315339
const currentUserEmail = email.toLowerCase().trim();
@@ -326,10 +350,10 @@ export default {
326350
...new Set(opts.to),
327351
];
328352
if (cc) {
329-
opts.cc = cc.value;
353+
opts.cc = this.parseEmailAddresses(cc.value);
330354
}
331355
if (bcc) {
332-
opts.bcc = bcc.value;
356+
opts.bcc = this.parseEmailAddresses(bcc.value);
333357
}
334358
}
335359
} catch (err) {

components/gmail/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/gmail",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "Pipedream Gmail Components",
55
"main": "gmail.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)