Skip to content

Commit 6f6120d

Browse files
Fix validity of the FROM email address not being checked (#29347)
Fixes #27188. Introduces a check on the installation that tries to parse the FROM address. If it fails, shows a new error message to the user. --------- Co-authored-by: KN4CK3R <[email protected]>
1 parent 08c1926 commit 6f6120d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ email_title = Email Settings
247247
smtp_addr = SMTP Host
248248
smtp_port = SMTP Port
249249
smtp_from = Send Email As
250+
smtp_from_invalid = The "Send Email As" address is invalid
250251
smtp_from_helper = Email address Gitea will use. Enter a plain email address or use the "Name" <[email protected]> format.
251252
mailer_user = SMTP Username
252253
mailer_password = SMTP Password

routers/install/install.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package install
77
import (
88
"fmt"
99
"net/http"
10+
"net/mail"
1011
"os"
1112
"os/exec"
1213
"path/filepath"
@@ -419,6 +420,11 @@ func SubmitInstall(ctx *context.Context) {
419420
}
420421

421422
if len(strings.TrimSpace(form.SMTPAddr)) > 0 {
423+
if _, err := mail.ParseAddress(form.SMTPFrom); err != nil {
424+
ctx.RenderWithErr(ctx.Tr("install.smtp_from_invalid"), tplInstall, &form)
425+
return
426+
}
427+
422428
cfg.Section("mailer").Key("ENABLED").SetValue("true")
423429
cfg.Section("mailer").Key("SMTP_ADDR").SetValue(form.SMTPAddr)
424430
cfg.Section("mailer").Key("SMTP_PORT").SetValue(form.SMTPPort)

0 commit comments

Comments
 (0)