email inboc
This commit is contained in:
parent
342eb78676
commit
c26a8a2094
2 changed files with 34 additions and 10 deletions
|
|
@ -18,11 +18,25 @@ function joinAddresses(value) {
|
|||
if (!value) return "";
|
||||
const addresses = Array.isArray(value) ? value : [value];
|
||||
return addresses
|
||||
.map((item) => (typeof item === "string" ? item : item?.email || item?.address))
|
||||
.map((item) => {
|
||||
if (typeof item === "string") return item;
|
||||
if (item?.name && item?.address) return `${item.name} <${item.address}>`;
|
||||
return item?.email || item?.address || "";
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join(", ");
|
||||
}
|
||||
|
||||
function messageBody(email) {
|
||||
const text = (email?.body_text || email?.text_body || email?.plain_text || "").trim();
|
||||
if (text) return { mode: "text", value: text };
|
||||
const html = (email?.body_html || "").trim();
|
||||
if (html) return { mode: "html", value: html };
|
||||
const snippet = (email?.snippet || "").trim();
|
||||
if (snippet) return { mode: "text", value: snippet };
|
||||
return { mode: "text", value: "This message has no readable content." };
|
||||
}
|
||||
|
||||
function detailDate(email) {
|
||||
const value =
|
||||
email?.received_at || email?.sent_at || email?.created_at || email?.updated_at;
|
||||
|
|
@ -51,6 +65,7 @@ export default function MailDetail({
|
|||
onAnalyzeAttachment,
|
||||
}) {
|
||||
const files = email ? attachmentCount(email) : 0;
|
||||
const body = email ? messageBody(email) : null;
|
||||
|
||||
return (
|
||||
<article className={`mail-detail${email || loading ? " open" : ""}`} aria-live="polite">
|
||||
|
|
@ -124,7 +139,11 @@ export default function MailDetail({
|
|||
<time>{detailDate(email)}</time>
|
||||
</div>
|
||||
<div className="mail-detail-body">
|
||||
{email.body_text || email.text_body || email.plain_text || "This message has no plain-text content."}
|
||||
{body?.mode === "html" ? (
|
||||
<div className="mail-detail-body-html" dangerouslySetInnerHTML={{ __html: body.value }} />
|
||||
) : (
|
||||
body?.value
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue