From 9334bfef3b3d3aa1785687fe1c931559133a0d3b Mon Sep 17 00:00:00 2001 From: Timothy Carambat Date: Wed, 15 Apr 2026 09:19:36 -0700 Subject: [PATCH] dedupe email items based on name --- server/utils/agents/aibitat/plugins/gmail/lib.js | 5 +++++ server/utils/agents/aibitat/plugins/outlook/lib.js | 3 +++ 2 files changed, 8 insertions(+) diff --git a/server/utils/agents/aibitat/plugins/gmail/lib.js b/server/utils/agents/aibitat/plugins/gmail/lib.js index 28e52c27..c751444b 100644 --- a/server/utils/agents/aibitat/plugins/gmail/lib.js +++ b/server/utils/agents/aibitat/plugins/gmail/lib.js @@ -123,15 +123,20 @@ async function parseAttachment(attachment) { /** * Collect attachments from messages and optionally parse them with user approval. + * Specific files may not show (images) and are pre-stripped by the app script. + * If two attachments have the same name, only the first one will be kept (handling fwd emails) * @param {Object} context - The handler context (this) from the aibitat function * @param {Array} messages - Array of message objects (single message should be wrapped in array) * @returns {Promise<{allAttachments: Array, parsedContent: string}>} */ async function handleAttachments(context, messages) { const allAttachments = []; + const uniqueAttachments = new Set(); messages.forEach((msg, msgIndex) => { if (msg.attachments?.length > 0) { msg.attachments.forEach((att) => { + if (uniqueAttachments.has(att.name)) return; + uniqueAttachments.add(att.name); allAttachments.push({ ...att, messageIndex: msgIndex + 1, diff --git a/server/utils/agents/aibitat/plugins/outlook/lib.js b/server/utils/agents/aibitat/plugins/outlook/lib.js index 83ebbc06..98e969ce 100644 --- a/server/utils/agents/aibitat/plugins/outlook/lib.js +++ b/server/utils/agents/aibitat/plugins/outlook/lib.js @@ -364,9 +364,12 @@ function isParseableMimeType(contentType) { */ async function handleAttachments(context, messages) { const allAttachments = []; + const uniqueAttachments = new Set(); messages.forEach((msg, msgIndex) => { if (msg.attachments?.length > 0) { msg.attachments.forEach((att) => { + if (uniqueAttachments.has(att.name)) return; + uniqueAttachments.add(att.name); allAttachments.push({ ...att, messageIndex: msgIndex + 1,