From 81bde353f4549883524ffa9f52cd92a3f3ad73a4 Mon Sep 17 00:00:00 2001 From: Fathi Ben Nasr Date: Mon, 2 Nov 2026 09:55:31 +0000 Subject: [PATCH] ics-viewer: read the attachments again once the message body is loaded The view sets the message before populateMessageBody() fills its attachments, so attachments() is still empty when the plugin looks for the calendar part, and it never looked again: the event panel did not show up for most invitations. Subscribe to msg.attachments until the part is found or another message is shown, and drop a late result that belongs to a message no longer displayed. --- plugins/ics-viewer/message.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/ics-viewer/message.js b/plugins/ics-viewer/message.js index b0adc469d..6f38cec2f 100644 --- a/plugins/ics-viewer/message.js +++ b/plugins/ics-viewer/message.js @@ -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); } } });