File tree Expand file tree Collapse file tree 4 files changed +47
-53
lines changed Expand file tree Collapse file tree 4 files changed +47
-53
lines changed Original file line number Diff line number Diff line change 11import { convert } from "html-to-text" ;
22import 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
95export 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
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { convert } from "html-to-text" ;
2+
13function 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+
1049export default {
1150 parseArray,
51+ decodeBase64Url,
52+ extractTextFromParts,
53+ attachTextToParts,
1254} ;
Original file line number Diff line number Diff line change 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" : [
You can’t perform that action at this time.
0 commit comments