diff --git a/apps/api/src/dkv/providers/exchange-inbox.provider.ts b/apps/api/src/dkv/providers/exchange-inbox.provider.ts index 9322819..03c6676 100644 --- a/apps/api/src/dkv/providers/exchange-inbox.provider.ts +++ b/apps/api/src/dkv/providers/exchange-inbox.provider.ts @@ -272,12 +272,27 @@ export class ExchangeInboxProvider implements InboxProvider { continue; } - // Collect PDF attachment IDs - const attachmentIds = extractAttrs(block, 't:FileAttachment', 'Id') - .filter((_, idx) => { - const types = extractAll(block, 't:ContentType'); - return (types[idx] ?? '').toLowerCase().includes('pdf'); - }); + // Collect PDF attachment IDs by iterating each FileAttachment block. + // extractAttrs(block, 't:FileAttachment', 'Id') was wrong — the Id lives + // inside a child not on the FileAttachment tag. + const attachmentIds: string[] = []; + const FA_OPEN = ''; + const FA_CLOSE = ''; + let faPos = 0; + while (faPos < block.length) { + const faStart = block.indexOf(FA_OPEN, faPos); + if (faStart === -1) break; + const faEnd = block.indexOf(FA_CLOSE, faStart); + if (faEnd === -1) break; + const faBlock = block.slice(faStart, faEnd); + const attId = extractAttr(faBlock, 't:AttachmentId', 'Id'); + const ct = (extractAll(faBlock, 't:ContentType')[0] ?? '').toLowerCase(); + const nm = (extractAll(faBlock, 't:Name')[0] ?? '').toLowerCase(); + if (attId && (ct.includes('pdf') || nm.endsWith('.pdf'))) { + attachmentIds.push(attId); + } + faPos = faEnd + FA_CLOSE.length; + } if (attachmentIds.length === 0) continue;