fix(dkv): fix EWS attachment ID extraction — FileAttachment has no Id attribute
extractAttrs(block, 't:FileAttachment', 'Id') always returned empty array because the attachment Id lives in a child <t:AttachmentId Id="..."/>, not on the <t:FileAttachment> tag itself. This caused all Exchange inbox checks to silently find zero PDF attachments and report "no matching emails". Fixed by iterating FileAttachment blocks individually and extracting t:AttachmentId/@Id from within each block. Also added filename (.pdf) as fallback when ContentType is application/octet-stream. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -272,12 +272,27 @@ export class ExchangeInboxProvider implements InboxProvider {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect PDF attachment IDs
|
// Collect PDF attachment IDs by iterating each FileAttachment block.
|
||||||
const attachmentIds = extractAttrs(block, 't:FileAttachment', 'Id')
|
// extractAttrs(block, 't:FileAttachment', 'Id') was wrong — the Id lives
|
||||||
.filter((_, idx) => {
|
// inside a child <t:AttachmentId Id="..."/> not on the FileAttachment tag.
|
||||||
const types = extractAll(block, 't:ContentType');
|
const attachmentIds: string[] = [];
|
||||||
return (types[idx] ?? '').toLowerCase().includes('pdf');
|
const FA_OPEN = '<t:FileAttachment>';
|
||||||
});
|
const FA_CLOSE = '</t:FileAttachment>';
|
||||||
|
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;
|
if (attachmentIds.length === 0) continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user