diff --git a/server/utils/agents/aibitat/plugins/gmail/lib.js b/server/utils/agents/aibitat/plugins/gmail/lib.js index 28e52c27b..c751444b4 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 83ebbc06c..98e969ce6 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,