Merge pull request #2096 from FathiBenNasr/fix/ics-viewer-wait-for-attachments

ics-viewer: read the attachments again once the message body is loaded
This commit is contained in:
Maarten 2026-11-02 22:45:47 +01:00 • committed by GitHub
commit d5776a81e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -92,12 +92,23 @@
// A scheduling mail does not always carry a text/calendar
// attachment either: the part is often inline inside
// multipart/alternative and repeated as application/ics.
// The message is set before its body is fetched
// (populateMessageBody), so attachments are usually still
// empty at this point: read them again when they arrive,
// once per message, and stop listening when it is done or
// when another message is shown.
let subscription = null, found = false;
const stop = () => subscription && (subscription.dispose(), subscription = null);
const readIcs = () => {
if (view.message() !== msg) return stop();
let ics = (msg.attachments() || []).find(attachment =>
'text/calendar' == attachment.mimeType
|| 'application/ics' == attachment.mimeType
|| 'text/x-vcalendar' == attachment.mimeType
|| /\.ics$/i.test(attachment.fileName || ''));
if (ics && ics.download) {
found = true;
stop();
// fetch it and parse the VEVENT
rl.fetch(ics.linkDownload())
@ -131,9 +142,15 @@
isCancelled: VEVENT.isCancelled(),
shouldReply: VEVENT.shouldReply()
});
view.ICSViewer(VEVENT);
view.message() === msg && view.ICSViewer(VEVENT);
}
});
})
.catch(e => console.error('[ics-viewer]', e));
}
};
readIcs();
if (!found && view.message() === msg) {
subscription = msg.attachments.subscribe(readIcs);
}
}
});