Skip to content

Commit

Permalink
parse emails (#14111)
Browse files Browse the repository at this point in the history
  • Loading branch information
michelle0927 authored Sep 27, 2024
1 parent 5efbd06 commit 2cf235b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
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": "0.1.6",
"version": "0.1.7",
"description": "Pipedream Gmail Components",
"main": "gmail.app.mjs",
"keywords": [
Expand Down
32 changes: 27 additions & 5 deletions components/gmail/sources/common/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,39 @@ export default {
decodedContent: Buffer.from(firstPart.body.data, "base64").toString(),
};
},
parseEmail(emailStr) {
if (!emailStr) {
return undefined;
}

const regex = /^(.*)<(.+)>$/;
const match = emailStr.match(regex);

if (match) {
return {
name: match[1].trim(),
email: match[2].trim(),
};
}
return {
name: null,
email: emailStr.trim(),
};
},
getHeaderValue(headers, key) {
return headers.find(({ name }) => name.toLowerCase() === key)?.value;
},
processEmail(msg) {
// Process and structure the email data
const headers = msg.payload.headers;
return {
"id": msg.id,
"threadId": msg.threadId,
"subject": headers.find((h) => h.name.toLowerCase() === "subject")?.value,
"from": headers.find((h) => h.name.toLowerCase() === "from")?.value,
"to": headers.find((h) => h.name.toLowerCase() === "to")?.value,
"reply-to": headers.find((h) => h.name.toLowerCase() === "reply-to")?.value,
"date": headers.find((h) => h.name.toLowerCase() === "date")?.value,
"subject": this.getHeaderValue(headers, "subject"),
"from": this.parseEmail(this.getHeaderValue(headers, "from")),
"to": this.parseEmail(this.getHeaderValue(headers, "to")),
"reply-to": this.parseEmail(this.getHeaderValue(headers, "reply-to")),
"date": this.getHeaderValue(headers, "date"),
"snippet": msg.snippet,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "gmail-new-attachment-received",
name: "New Attachment Received",
description: "Emit new event for each attachment in a message received. This source is capped at 100 max new messages per run.",
version: "0.0.4",
version: "0.0.5",
type: "source",
dedupe: "unique",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "gmail-new-email-matching-search",
name: "New Email Matching Search",
description: "Emit new event when an email matching the search criteria is received. This source is capped at 100 max new messages per run.",
version: "0.0.3",
version: "0.0.4",
type: "source",
dedupe: "unique",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
name: "New Labeled Email",
description: "Emit new event when a new email is labeled.",
type: "source",
version: "0.0.4",
version: "0.0.5",
dedupe: "unique",
props: {
...common.props,
Expand Down
2 changes: 1 addition & 1 deletion components/gmail/sources/new-sent-email/new-sent-email.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "gmail-new-sent-email",
name: "New Sent Email",
description: "Emit new event for each new email sent. (Maximum of 100 events emited per execution)",
version: "0.0.4",
version: "0.0.5",
type: "source",
dedupe: "unique",
props: {
Expand Down

0 comments on commit 2cf235b

Please sign in to comment.