From b7c24138bdda18c294f24e7a69db17efbb47fef5 Mon Sep 17 00:00:00 2001 From: zelfroster Date: Mon, 24 Jul 2023 06:11:06 +0530 Subject: [PATCH] feat: attach message headers to the reply composer --- webui-src/app/mail/mail_compose.js | 48 ++++++++++++++++++++++++++++-- webui-src/app/mail/mail_util.js | 5 +++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/webui-src/app/mail/mail_compose.js b/webui-src/app/mail/mail_compose.js index 1eb2869..fbf8a58 100644 --- a/webui-src/app/mail/mail_compose.js +++ b/webui-src/app/mail/mail_compose.js @@ -61,9 +61,53 @@ const Layout = () => { } if (msgType === 'reply') { - const { subject, replyMessage } = await attrs; + const { subject, replyMessage, timeStamp } = await attrs; const tmb = document.querySelector('#composerMailBody'); - tmb.innerHTML = `

-----Original Message-----

${replyMessage}`; + const time = timeStamp.toLocaleTimeString('UTC', { hour: '2-digit', minute: '2-digit' }); + const dateLong = timeStamp.toLocaleDateString('UTC', { + year: 'numeric', + month: 'long', + day: 'numeric', + }); + const replyMessageHeader = ` + -----Original Message----- +
+ From: + ${rs.userList.userMap[senderId]} +
+ To: + ${Object.keys(recipientList).map( + (recip) => ` + + ${rs.userList.userMap[recipientList[recip]._addr_string] || 'Unknown'}, + + ` + )} +
+
+ Sent: + ${dateLong} ${time} +
+ Subject: + ${subject} +
+
+ + On ${timeStamp.toLocaleDateString()} ${time}, + ${rs.userList.userMap[senderId]} + wrote: + + `; + tmb.innerHTML = ` +
+
+
+ ${replyMessageHeader} +
+ ${replyMessage} +
+
+ `; Data.subject = subject.substring(0, 4) === 'Re: ' ? subject : `Re: ${subject}`; } } diff --git a/webui-src/app/mail/mail_util.js b/webui-src/app/mail/mail_util.js index 50b94bf..7431403 100644 --- a/webui-src/app/mail/mail_util.js +++ b/webui-src/app/mail/mail_util.js @@ -171,6 +171,7 @@ const MessageView = () => { toList: {}, ccList: {}, bccList: {}, + timeStamp: '', files: [], }; function deleteMail() { @@ -210,6 +211,7 @@ const MessageView = () => { MailData.msgId = msgDetails.msgId; MailData.sender = msgDetails.from; MailData.subject = msgDetails.title; + MailData.timeStamp = msgDetails.ts; MailData.recipients = msgDetails.destinations; MailData?.recipients?.forEach((destDetail) => { const { _addr_string: addrString, _mode: mode } = destDetail; // destructuring + renaming @@ -267,7 +269,7 @@ const MessageView = () => { ? [ m('#truncate.truncated-view', [ Object.keys(MailData.toList).map((key, index) => - m('span', { key: index }, `${rs.userList.userMap[key]}, `) + m('span', { key: index }, `${rs.userList.userMap[key] || 'Unknown'}, `) ), ]), m( @@ -325,6 +327,7 @@ const MessageView = () => { recipientList: MailData.toList, subject: MailData.subject, replyMessage: MailData.message, + timeStamp: new Date(MailData.timeStamp * 1000), setShowCompose, }) : m('.widget', m('.widget__heading', m('h3', 'Sender is not known'))),