WIP: form attachments — unit tests, test e-mail with attachment, lint
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
02b1e96d3d
commit
701bb420c1
@@ -15,6 +15,9 @@ import { serverText } from '../../integrations/texts.js'
|
||||
* authenticated admin user — a test-send button must never be open to the
|
||||
* public (it would be an open relay / spam vector).
|
||||
*
|
||||
* Body: `{ to, attachmentMB? }` — `attachmentMB` (1–25) attaches a dummy file of
|
||||
* that size, to measure what the mail server really accepts.
|
||||
*
|
||||
* Returns the adapter's own result so the panel can show exactly what happened,
|
||||
* including the transport-specific error (SMTP auth failure, Graph 401, etc.).
|
||||
*/
|
||||
@@ -51,12 +54,20 @@ export const testEmailEndpoint: Endpoint = {
|
||||
return Response.json({ error: serverText(i18n, 'testEmailInvalidRecipient'), ok: false }, { status: 400 })
|
||||
}
|
||||
|
||||
// Optional: a dummy attachment of N MB — proves that a form file of that size
|
||||
// really gets through this mail server (form files are delivered by e-mail only).
|
||||
const requested = Number(req.data?.attachmentMB)
|
||||
const attachmentMB = Number.isFinite(requested) && requested > 0 ? Math.min(Math.floor(requested), 25) : 0
|
||||
|
||||
const site = await siteName(req)
|
||||
const subject = site ? serverText(i18n, 'testEmailSubject', { site }) : serverText(i18n, 'testEmailSubjectGeneric')
|
||||
const text = site ? serverText(i18n, 'testEmailBody', { site }) : serverText(i18n, 'testEmailBodyGeneric')
|
||||
|
||||
try {
|
||||
const info = await req.payload.sendEmail({
|
||||
...(attachmentMB
|
||||
? { attachments: [{ content: Buffer.alloc(attachmentMB * 1024 * 1024, 'ipal-kit test file\n'), contentType: 'text/plain', filename: `test-${attachmentMB}MB.txt` }] }
|
||||
: {}),
|
||||
html: `<p>${escapeHtml(text)}</p>`,
|
||||
subject,
|
||||
text,
|
||||
|
||||
Reference in New Issue
Block a user