mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-31 13:52:48 +00:00
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 `<body>` 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 <noreply@anthropic.com>
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
1 parent
ae0136acd2
commit
08c5fcafd3
2 files changed
+1
-4
No files matched your search
@@ -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, "</head>", "<style>:root {color-scheme: "+scheme+"}</style></head>", 1)
|
||||
}
|
||||
body = strings.Replace(body, "</head>", "<style>"+previewStyle+"</style></head>", 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))
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<title>{{.}}</title>
|
||||
|
||||
<style>
|
||||
body {margin: 0; padding: 0}
|
||||
body, td {font-family: -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif}
|
||||
a, a:visited {color: #0969da; text-decoration: none}
|
||||
a:hover {text-decoration: underline}
|
||||
|
||||
Reference in new issue
Block a user