Skip to content

Commit bbfcc30

Browse files
committed
parse emails
1 parent aba7264 commit bbfcc30

File tree

7 files changed

+33
-11
lines changed

7 files changed

+33
-11
lines changed

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": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Pipedream Gmail Components",
55
"main": "gmail.app.mjs",
66
"keywords": [

components/gmail/sources/common/base.mjs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,39 @@ export default {
4444
decodedContent: Buffer.from(firstPart.body.data, "base64").toString(),
4545
};
4646
},
47+
parseEmail(emailStr) {
48+
if (!emailStr) {
49+
return undefined;
50+
}
51+
52+
const regex = /^(.*)<(.+)>$/;
53+
const match = emailStr.match(regex);
54+
55+
if (match) {
56+
return {
57+
name: match[1].trim(),
58+
email: match[2].trim(),
59+
};
60+
}
61+
return {
62+
name: null,
63+
email: emailStr.trim(),
64+
};
65+
},
66+
getHeaderValue(headers, key) {
67+
return headers.find(({ name }) => name.toLowerCase() === key)?.value;
68+
},
4769
processEmail(msg) {
4870
// Process and structure the email data
4971
const headers = msg.payload.headers;
5072
return {
5173
"id": msg.id,
5274
"threadId": msg.threadId,
53-
"subject": headers.find((h) => h.name.toLowerCase() === "subject")?.value,
54-
"from": headers.find((h) => h.name.toLowerCase() === "from")?.value,
55-
"to": headers.find((h) => h.name.toLowerCase() === "to")?.value,
56-
"reply-to": headers.find((h) => h.name.toLowerCase() === "reply-to")?.value,
57-
"date": headers.find((h) => h.name.toLowerCase() === "date")?.value,
75+
"subject": this.getHeaderValue(headers, "subject"),
76+
"from": this.parseEmail(this.getHeaderValue(headers, "from")),
77+
"to": this.parseEmail(this.getHeaderValue(headers, "to")),
78+
"reply-to": this.parseEmail(this.getHeaderValue(headers, "reply-to")),
79+
"date": this.getHeaderValue(headers, "date"),
5880
"snippet": msg.snippet,
5981
};
6082
},

components/gmail/sources/new-attachment-received/new-attachment-received.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "gmail-new-attachment-received",
77
name: "New Attachment Received",
88
description: "Emit new event for each attachment in a message received. This source is capped at 100 max new messages per run.",
9-
version: "0.0.4",
9+
version: "0.0.5",
1010
type: "source",
1111
dedupe: "unique",
1212
props: {

components/gmail/sources/new-email-matching-search/new-email-matching-search.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "gmail-new-email-matching-search",
77
name: "New Email Matching Search",
88
description: "Emit new event when an email matching the search criteria is received. This source is capped at 100 max new messages per run.",
9-
version: "0.0.3",
9+
version: "0.0.4",
1010
type: "source",
1111
dedupe: "unique",
1212
props: {

components/gmail/sources/new-email-received/new-email-received.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
name: "New Email Received",
1616
description: "Emit new event when a new email is received.",
1717
type: "source",
18-
version: "0.1.3",
18+
version: "0.1.4",
1919
dedupe: "unique",
2020
props: {
2121
gmail,

components/gmail/sources/new-labeled-email/new-labeled-email.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
name: "New Labeled Email",
99
description: "Emit new event when a new email is labeled.",
1010
type: "source",
11-
version: "0.0.4",
11+
version: "0.0.5",
1212
dedupe: "unique",
1313
props: {
1414
...common.props,

components/gmail/sources/new-sent-email/new-sent-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-new-sent-email",
77
name: "New Sent Email",
88
description: "Emit new event for each new email sent. (Maximum of 100 events emited per execution)",
9-
version: "0.0.4",
9+
version: "0.0.5",
1010
type: "source",
1111
dedupe: "unique",
1212
props: {

0 commit comments

Comments
 (0)