mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -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';
|
||||
|
||||
import {
|
||||
ParsedMail,
|
||||
simpleParser,
|
||||
Source as ParserSource,
|
||||
} from 'mailparser';
|
||||
|
||||
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 = {};
|
||||
// @ts-ignore
|
||||
for (const header of responseData.headerLines) {
|
||||
headers[header.key] = header.line;
|
||||
}
|
||||
|
@ -96,6 +98,22 @@ export async function parseRawEmail(this: IExecuteFunctions, messageEncoded: Par
|
|||
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 {
|
||||
json: responseData as unknown as IDataObject,
|
||||
binary: Object.keys(binaryData).length ? binaryData : undefined,
|
||||
|
|
|
@ -454,10 +454,9 @@ export class Gmail implements INodeType {
|
|||
|
||||
let nodeExecutionData: INodeExecutionData;
|
||||
if (format === 'resolved') {
|
||||
const messageEncoded = Buffer.from(responseData.raw, 'base64').toString('utf8');
|
||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||
|
||||
nodeExecutionData = await parseRawEmail.call(this, messageEncoded, dataPropertyNameDownload);
|
||||
nodeExecutionData = await parseRawEmail.call(this, responseData, dataPropertyNameDownload);
|
||||
} else {
|
||||
nodeExecutionData = {
|
||||
json: responseData,
|
||||
|
@ -525,9 +524,9 @@ export class Gmail implements INodeType {
|
|||
);
|
||||
|
||||
if (format === 'resolved') {
|
||||
const messageEncoded = Buffer.from(responseData[i].raw, 'base64').toString('utf8');
|
||||
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;
|
||||
if (format === 'resolved') {
|
||||
const messageEncoded = Buffer.from(responseData.message.raw, 'base64').toString('utf8');
|
||||
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 {
|
||||
nodeExecutionData = {
|
||||
json: responseData,
|
||||
|
@ -728,9 +730,13 @@ export class Gmail implements INodeType {
|
|||
);
|
||||
|
||||
if (format === 'resolved') {
|
||||
const messageEncoded = Buffer.from(responseData[i].message.raw, 'base64').toString('utf8');
|
||||
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