fix(Email Trigger (IMAP) Node): Handle attachments correctly (#9410)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-05-15 15:50:53 +02:00
committed by GitHub
parent bf549301df
commit 68a6c81729
9 changed files with 213 additions and 56 deletions

View File

@@ -285,7 +285,7 @@ export class EmailReadImapV1 implements INodeType {
// Returns the email text
const getText = async (parts: any[], message: Message, subtype: string) => {
const getText = async (parts: any[], message: Message, subtype: string): Promise<string> => {
if (!message.attributes.struct) {
return '';
}
@@ -296,12 +296,14 @@ export class EmailReadImapV1 implements INodeType {
);
});
if (textParts.length === 0) {
const part = textParts[0];
if (!part) {
return '';
}
try {
return await connection.getPartData(message, textParts[0]);
const partData = await connection.getPartData(message, part);
return partData.toString();
} catch {
return '';
}
@@ -330,7 +332,7 @@ export class EmailReadImapV1 implements INodeType {
.then(async (partData) => {
// Return it in the format n8n expects
return await this.helpers.prepareBinaryData(
Buffer.from(partData),
partData.buffer,
attachmentPart.disposition.params.filename as string,
);
});