mox/webmail/msg.ts
Mechiel Lukkien 1e15a10b66
webmail: fix js error rerendering additional headers after updated keywords
i've seen the error a few times:

	msgheaderElem.children[(msgheaderElem.children.length - 1)] is undefined

i've seen it happen after sending a reply (with the "answered" flag added).
the updateKeywords callback would render the message again, but the code for
rendering the "additional headers" table rows again was making invalid
assumptions.

the approach is now changed. the backend now just immediately sends the
additional headers to the frontend. before, the frontend would first render the
base message, then render again once the headers came in for the parsed
message. this also prevents a reflow for the (quite common) case that one of
the additional headers are present in the message.
2025-01-13 14:53:43 +01:00

77 lines
2.3 KiB
TypeScript

// Javascript is generated from typescript, do not modify generated javascript because changes will be overwritten.
// Loaded from synchronous javascript.
declare let messageItem: api.MessageItem
// From customization script.
declare let moxBeforeDisplay: (root: HTMLElement) => void
const init = () => {
const mi = api.parser.MessageItem(messageItem)
document.title = '"' + mi.Envelope.Subject + '"- from '+((mi.Envelope.From || []).map(a => formatAddress(a)).join(', ') || '-') + ' (id '+mi.Message.ID+')'
let msgattachmentview = dom.div()
if (mi.Attachments && mi.Attachments.length > 0) {
dom._kids(msgattachmentview,
dom.div(
css('msgAttachments', {borderTop: '1px solid', borderTopColor: styles.borderColor}),
dom.div(dom._class('pad'),
'Attachments: ',
join(mi.Attachments.map(a => a.Filename || '(unnamed)'), () => ', '),
),
)
)
}
const msgheaderview = dom.tbody()
loadMsgheaderView(msgheaderview, mi, [], null, true)
const l = window.location.pathname.split('/')
const w = l[l.length-1]
let iframepath: string
if (w === 'msgtext') {
iframepath = 'text'
} else if (w === 'msghtml') {
iframepath = 'html'
} else if (w === 'msghtmlexternal') {
iframepath = 'htmlexternal'
} else {
window.alert('Unknown message type '+w)
return
}
iframepath += '?sameorigin=true'
let iframe: HTMLIFrameElement
const page = document.getElementById('page')!
const root = dom.div(
dom.div(
css('msgMeta', {backgroundColor: styles.backgroundColorMild, borderBottom: '1px solid', borderBottomColor: styles.borderColor}),
dom.table(
styleClasses.msgHeaders,
msgheaderview,
),
msgattachmentview,
),
iframe=dom.iframe(
attr.title('Message body.'),
attr.src(iframepath),
css('msgIframe', {width: '100%', height: '100%'}),
function load() {
// Note: we load the iframe content specifically in a way that fires the load event only when the content is fully rendered.
iframe.style.height = iframe.contentDocument!.documentElement.scrollHeight+'px'
if (window.location.hash === '#print') {
window.print()
}
},
)
)
if (typeof moxBeforeDisplay !== 'undefined') {
moxBeforeDisplay(root)
}
dom._kids(page, root)
}
try {
init()
} catch (err) {
window.alert('Error: ' + ((err as any).message || '(no message)'))
}