From 08c5fcafd3d9822f77d26c6a53e1d578d75811cf Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 31 Oct 2026 17:02:08 +0800 Subject: [PATCH] fix(mail): preserve outer spacing in notification emails (#40104) Remove the `body {margin: 0; padding: 0}` reset from https://github.com/go-gitea/gitea/pull/38396, which left HTML mails flush against the edge in Apple Mail and Thunderbird. The devtest preview stops injecting its own padding, so it matches delivered mails. These clients render the mail as a document and apply the default 8px body margin again, as with GitHub and GitLab notifications. Webmail clients replace `` and keep their own inset. Fixes https://github.com/go-gitea/gitea/issues/40103 Assisted-by: Codex:GPT-6.1, Claude:Opus 5.5 Co-authored-by: Claude Opus 5.5 Co-authored-by: silverwind --- routers/web/devtest/mail_preview.go | 4 +--- templates/mail/base/head.tmpl | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/routers/web/devtest/mail_preview.go b/routers/web/devtest/mail_preview.go index 81df0657f10..103eef16f37 100644 --- a/routers/web/devtest/mail_preview.go +++ b/routers/web/devtest/mail_preview.go @@ -49,13 +49,11 @@ func MailPreviewRender(ctx *context.Context) { body := mailBody.String() // emulate mail clients, which resolve "cid:" URIs to the mail's inline attachments body = strings.ReplaceAll(body, `src="cid:`, `src="`+setting.AppSubURL+`/devtest/mail-preview-embed/`) - previewStyle := "body {padding: 12px 16px}" // a page can force "color-scheme" on an embedded document but never "prefers-color-scheme" if scheme := ctx.FormString("scheme"); scheme == "light" || scheme == "dark" { body = mailDarkSchemeQuery.ReplaceAllString(body, util.Iif(scheme == "dark", "@media all", "@media not all")) - previewStyle += "\n:root {color-scheme: " + scheme + "}" + body = strings.Replace(body, "", "", 1) } - body = strings.Replace(body, "", "", 1) // fragment templates like "mail/base/head" would be sniffed as text/plain otherwise ctx.Resp.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = ctx.Resp.Write([]byte(body)) diff --git a/templates/mail/base/head.tmpl b/templates/mail/base/head.tmpl index aa1601df1fb..70205f75d58 100644 --- a/templates/mail/base/head.tmpl +++ b/templates/mail/base/head.tmpl @@ -5,7 +5,6 @@ {{.}}