dedupe email items based on name

This commit is contained in:
Timothy Carambat
2026-04-15 09:19:36 -07:00
parent 951ffc3d7b
commit 9334bfef3b
2 changed files with 8 additions and 0 deletions

View File

@@ -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,

View File

@@ -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,