Skip to content

Commit 8c2fd19

Browse files
committed
updates
1 parent c503561 commit 8c2fd19

File tree

4 files changed

+47
-53
lines changed

4 files changed

+47
-53
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { convert } from "html-to-text";
22
import gmail from "../../gmail.app.mjs";
3-
import {
4-
decodeBase64Url,
5-
extractTextFromParts,
6-
attachTextToParts,
7-
} from "./utils.mjs";
3+
import utils from "../../common/utils.mjs";
84

95
export default {
106
key: "gmail-find-email",
@@ -72,7 +68,7 @@ export default {
7268
}
7369

7470
if (message.payload?.body?.data && !Array.isArray(message.payload.parts)) {
75-
const decodedBody = decodeBase64Url(message.payload.body.data);
71+
const decodedBody = utils.decodeBase64Url(message.payload.body.data);
7672
if (this.withTextPayload) {
7773
newPayload += convert(decodedBody);
7874
} else {
@@ -82,9 +78,9 @@ export default {
8278

8379
if (Array.isArray(message.payload?.parts)) {
8480
if (this.withTextPayload) {
85-
newPayload += extractTextFromParts(message.payload.parts);
81+
newPayload += utils.extractTextFromParts(message.payload.parts);
8682
} else {
87-
attachTextToParts(message.payload.parts);
83+
utils.attachTextToParts(message.payload.parts);
8884
}
8985
}
9086

components/gmail/actions/find-email/utils.mjs

Lines changed: 0 additions & 44 deletions
This file was deleted.

components/gmail/common/utils.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { convert } from "html-to-text";
2+
13
function parseArray(arr) {
24
if (!arr) {
35
return undefined;
@@ -7,6 +9,46 @@ function parseArray(arr) {
79
: arr;
810
}
911

12+
function decodeBase64Url(data) {
13+
const base64 = data.replace(/-/g, "+").replace(/_/g, "/");
14+
return Buffer.from(base64, "base64").toString("utf-8");
15+
};
16+
17+
function extractTextFromParts(parts) {
18+
let text = "";
19+
for (const part of parts) {
20+
if (Array.isArray(part.parts)) {
21+
text += extractTextFromParts(part.parts);
22+
}
23+
if (part.mimeType === "text/plain" && part.body?.data) {
24+
text += decodeBase64Url(part.body.data);
25+
}
26+
else if (part.mimeType === "text/html" && part.body?.data) {
27+
const html = decodeBase64Url(part.body.data);
28+
text += convert(html);
29+
}
30+
}
31+
return text;
32+
};
33+
34+
function attachTextToParts(parts) {
35+
for (const part of parts) {
36+
if (Array.isArray(part.parts)) {
37+
attachTextToParts(part.parts);
38+
}
39+
if (part.mimeType === "text/html" && part.body?.data) {
40+
const html = decodeBase64Url(part.body.data);
41+
part.body.text = convert(html);
42+
}
43+
else if (part.mimeType === "text/plain" && part.body?.data) {
44+
part.body.text = decodeBase64Url(part.body.data);
45+
}
46+
}
47+
};
48+
1049
export default {
1150
parseArray,
51+
decodeBase64Url,
52+
extractTextFromParts,
53+
attachTextToParts,
1254
};

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

0 commit comments

Comments
 (0)