Upstream maildev/maildev state of the touched files before f6ee0b5f24

This commit is contained in:
upstream committed 2026-09-22 20:00:23 +02:00
1 parent 15ecda681f
commit 77bb28b844
6 files changed
+13 -69

No files matched your search

+6 -12
View File
@@ -45,16 +45,14 @@ export function sanitizeHtml(html: string | undefined): string | undefined {
* @param html - HTML content with cid: references
* @param emailId - ID of the email
* @param attachments - Array of attachments with contentId
* @param baseUrl - Optional host to prefix as `//host/...`; unset gives a root-relative URL
* @param basePath - Optional pathname the API is mounted under, e.g. `/mail`
* @param baseUrl - Optional base URL for attachment URLs
* @returns HTML with cid: references replaced with actual URLs
*/
export function replaceCidReferences(
html: string,
emailId: string,
attachments: Array<{ contentId?: string; generatedFileName: string }>,
baseUrl?: string,
basePath?: string
baseUrl?: string
): string {
if (!attachments || attachments.length === 0) {
return html
@@ -74,7 +72,7 @@ export function replaceCidReferences(
'g'
)
const url = buildAttachmentUrl(emailId, attachment.generatedFileName, baseUrl, basePath)
const url = buildAttachmentUrl(emailId, attachment.generatedFileName, baseUrl)
const replacement = `src="${url}"`
result = result.replace(regex, replacement)
@@ -84,19 +82,15 @@ export function replaceCidReferences(
}
/**
* Build URL for an attachment. The API serves these from `${basePath}/api/email/...`,
* so both parts belong here or the src 404s.
* Build URL for an attachment
*/
function buildAttachmentUrl(
emailId: string,
filename: string,
baseUrl?: string,
basePath?: string
baseUrl?: string
): string {
const base = baseUrl ? `//${baseUrl}` : ''
const segments = basePath ? basePath.replace(/^\/+|\/+$/g, '') : ''
const prefix = segments ? `/${segments}` : ''
return `${base}${prefix}/api/email/${emailId}/attachment/${encodeURIComponent(filename)}`
return `${base}/email/${emailId}/attachment/${encodeURIComponent(filename)}`
}
/**