Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/gmail/actions/send-email/send-email.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "gmail-send-email",
name: "Send Email",
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)",
version: "0.1.16",
version: "0.1.17",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
32 changes: 28 additions & 4 deletions components/gmail/gmail.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { convert } from "html-to-text";
import mime from "mime/types/standard.js";
import MailComposer from "nodemailer/lib/mail-composer/index.js";
import addressparser from "nodemailer/lib/addressparser/index.js";
import constants from "./common/constants.mjs";
import { JWT } from "google-auth-library";

Expand Down Expand Up @@ -273,6 +274,27 @@ export default {
auth,
});
},
/**
* Parse email addresses from a string
* @param {string} addressString - Raw address string to parse
* @returns {string[]} Array of properly formatted email addresses
*/
parseEmailAddresses(addressString) {
if (!addressString || typeof addressString !== "string") {
return [];
}

// Use nodemailer's addressparser to properly handle RFC 5322 format
const parsed = addressparser(addressString.trim());

// Reconstruct addresses in standard format
return parsed.map((addr) => {
if (addr.name) {
return `${addr.name} <${addr.address}>`;
}
return addr.address;
});
},
async getOptionsToSendEmail($, props) {
const {
name: fromName,
Expand Down Expand Up @@ -308,8 +330,10 @@ export default {
const to = repliedMessage.payload.headers.find(({ name }) => name.toLowerCase() === "to");
const cc = repliedMessage.payload.headers.find(({ name }) => name.toLowerCase() === "cc");
const bcc = repliedMessage.payload.headers.find(({ name }) => name.toLowerCase() === "bcc");
opts.to = from.value.split(",");
opts.to.push(...to.value.split(","));
opts.to = [
...this.parseEmailAddresses(from.value),
...this.parseEmailAddresses(to.value),
];

// Filter out the current user's email address
const currentUserEmail = email.toLowerCase().trim();
Expand All @@ -326,10 +350,10 @@ export default {
...new Set(opts.to),
];
if (cc) {
opts.cc = cc.value;
opts.cc = this.parseEmailAddresses(cc.value);
}
if (bcc) {
opts.bcc = bcc.value;
opts.bcc = this.parseEmailAddresses(bcc.value);
}
}
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion components/gmail/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/gmail",
"version": "1.3.2",
"version": "1.3.3",
"description": "Pipedream Gmail Components",
"main": "gmail.app.mjs",
"keywords": [
Expand Down
Loading