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

@@ -298,7 +298,11 @@ export class EmailReadImapV2 implements INodeType {
// Returns the email text
const getText = async (parts: MessagePart[], message: Message, subtype: string) => {
const getText = async (
parts: MessagePart[],
message: Message,
subtype: string,
): Promise<string> => {
if (!message.attributes.struct) {
return '';
}
@@ -309,12 +313,14 @@ export class EmailReadImapV2 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 '';
}
@@ -355,7 +361,7 @@ export class EmailReadImapV2 implements INodeType {
?.filename as string,
);
// Return it in the format n8n expects
return await this.helpers.prepareBinaryData(Buffer.from(partData), fileName);
return await this.helpers.prepareBinaryData(partData.buffer, fileName);
});
attachmentPromises.push(attachmentPromise);