- Created a .cursorignore file to manage local environment files. - Updated .env.example to reflect changes in the public app URL. - Modified the gmail workspace configuration to include the drive-suite path. - Enhanced email view components to support attachment handling and fallback for plain text bodies. - Improved user experience by updating attachment display logic and integrating inline attachment support.
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
/** Render plain-text-only messages with clickable links and readable line breaks. */
|
||
|
||
const URL_RE = /https?:\/\/[^\s<>"')\]]+/gi
|
||
|
||
function escapeHtml(text: string): string {
|
||
return text
|
||
.replace(/&/g, "&")
|
||
.replace(/</g, "<")
|
||
.replace(/>/g, ">")
|
||
}
|
||
|
||
function linkifyEscapedText(text: string): string {
|
||
let out = ""
|
||
let last = 0
|
||
for (const match of text.matchAll(URL_RE)) {
|
||
const index = match.index ?? 0
|
||
out += text.slice(last, index)
|
||
const url = match[0]
|
||
out += `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`
|
||
last = index + url.length
|
||
}
|
||
out += text.slice(last)
|
||
return out
|
||
}
|
||
|
||
/** Insert breaks before common transactional-mail markers when the body is one long line. */
|
||
function softenPlainTextWall(text: string): string {
|
||
if (text.includes("\n")) return text
|
||
return text
|
||
.replace(/,\s*(Cher(?:e)?\s)/gi, ",\n\n$1")
|
||
.replace(/,\s*(Le \d{2}\/\d{2}\/\d{4})/g, ",\n\n$1")
|
||
.replace(/\.\s+(Nous restons)/g, ".\n\n$1")
|
||
.replace(/\.\s+(L['’]équipe)/g, ".\n\n$1")
|
||
.replace(/\.\s+(Pour obtenir)/g, ".\n\n$1")
|
||
.replace(/\.\s+(Vous pouvez)/g, ".\n\n$1")
|
||
}
|
||
|
||
export function plainTextToDisplayHtml(text: string): string {
|
||
const normalized = softenPlainTextWall(text.trim())
|
||
const escaped = escapeHtml(normalized)
|
||
const linked = linkifyEscapedText(escaped)
|
||
return `<pre style="white-space:pre-wrap;font-family:inherit;margin:0;line-height:1.5;">${linked}</pre>`
|
||
}
|