mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Add GMail email id to messages with format "resolved"
This commit is contained in:
parent
3ba050819a
commit
a4689fef8c
|
@ -3,8 +3,8 @@ import {
|
||||||
} from 'request';
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ParsedMail,
|
||||||
simpleParser,
|
simpleParser,
|
||||||
Source as ParserSource,
|
|
||||||
} from 'mailparser';
|
} from 'mailparser';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -71,11 +71,13 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function parseRawEmail(this: IExecuteFunctions, messageEncoded: ParserSource, dataPropertyNameDownload: string): Promise<INodeExecutionData> {
|
export async function parseRawEmail(this: IExecuteFunctions, messageData: any, dataPropertyNameDownload: string): Promise<INodeExecutionData> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
const responseData = await simpleParser(messageEncoded);
|
const messageEncoded = Buffer.from(messageData.raw, 'base64').toString('utf8');
|
||||||
|
let responseData = await simpleParser(messageEncoded);
|
||||||
|
|
||||||
const headers: IDataObject = {};
|
const headers: IDataObject = {};
|
||||||
|
// @ts-ignore
|
||||||
for (const header of responseData.headerLines) {
|
for (const header of responseData.headerLines) {
|
||||||
headers[header.key] = header.line;
|
headers[header.key] = header.line;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +98,22 @@ export async function parseRawEmail(this: IExecuteFunctions, messageEncoded: Par
|
||||||
responseData.attachments = undefined;
|
responseData.attachments = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mailBaseData: IDataObject = {};
|
||||||
|
|
||||||
|
const resolvedModeAddProperties = [
|
||||||
|
'id',
|
||||||
|
'threadId',
|
||||||
|
'labelIds',
|
||||||
|
'sizeEstimate',
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const key of resolvedModeAddProperties) {
|
||||||
|
// @ts-ignore
|
||||||
|
mailBaseData[key] = messageData[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = Object.assign(mailBaseData, responseData);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
json: responseData as unknown as IDataObject,
|
json: responseData as unknown as IDataObject,
|
||||||
binary: Object.keys(binaryData).length ? binaryData : undefined,
|
binary: Object.keys(binaryData).length ? binaryData : undefined,
|
||||||
|
|
|
@ -454,10 +454,9 @@ export class Gmail implements INodeType {
|
||||||
|
|
||||||
let nodeExecutionData: INodeExecutionData;
|
let nodeExecutionData: INodeExecutionData;
|
||||||
if (format === 'resolved') {
|
if (format === 'resolved') {
|
||||||
const messageEncoded = Buffer.from(responseData.raw, 'base64').toString('utf8');
|
|
||||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||||
|
|
||||||
nodeExecutionData = await parseRawEmail.call(this, messageEncoded, dataPropertyNameDownload);
|
nodeExecutionData = await parseRawEmail.call(this, responseData, dataPropertyNameDownload);
|
||||||
} else {
|
} else {
|
||||||
nodeExecutionData = {
|
nodeExecutionData = {
|
||||||
json: responseData,
|
json: responseData,
|
||||||
|
@ -525,9 +524,9 @@ export class Gmail implements INodeType {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (format === 'resolved') {
|
if (format === 'resolved') {
|
||||||
const messageEncoded = Buffer.from(responseData[i].raw, 'base64').toString('utf8');
|
|
||||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||||
responseData[i] = await parseRawEmail.call(this, messageEncoded, dataPropertyNameDownload);
|
|
||||||
|
responseData[i] = await parseRawEmail.call(this, responseData[i], dataPropertyNameDownload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -654,10 +653,13 @@ export class Gmail implements INodeType {
|
||||||
|
|
||||||
let nodeExecutionData: INodeExecutionData;
|
let nodeExecutionData: INodeExecutionData;
|
||||||
if (format === 'resolved') {
|
if (format === 'resolved') {
|
||||||
const messageEncoded = Buffer.from(responseData.message.raw, 'base64').toString('utf8');
|
|
||||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||||
|
|
||||||
nodeExecutionData = await parseRawEmail.call(this, messageEncoded, dataPropertyNameDownload);
|
nodeExecutionData = await parseRawEmail.call(this, responseData.message, dataPropertyNameDownload);
|
||||||
|
|
||||||
|
// Add the draft-id
|
||||||
|
nodeExecutionData.json.messageId = nodeExecutionData.json.id;
|
||||||
|
nodeExecutionData.json.id = responseData.id;
|
||||||
} else {
|
} else {
|
||||||
nodeExecutionData = {
|
nodeExecutionData = {
|
||||||
json: responseData,
|
json: responseData,
|
||||||
|
@ -728,9 +730,13 @@ export class Gmail implements INodeType {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (format === 'resolved') {
|
if (format === 'resolved') {
|
||||||
const messageEncoded = Buffer.from(responseData[i].message.raw, 'base64').toString('utf8');
|
|
||||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||||
responseData[i] = await parseRawEmail.call(this, messageEncoded, dataPropertyNameDownload);
|
const id = responseData[i].id;
|
||||||
|
responseData[i] = await parseRawEmail.call(this, responseData[i].message, dataPropertyNameDownload);
|
||||||
|
|
||||||
|
// Add the draft-id
|
||||||
|
responseData[i].json.messageId = responseData[i].json.id;
|
||||||
|
responseData[i].json.id = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue