1
0
Fork 0
forked from forgejo/forgejo

setting: Allow aliases for some email settings

The keys for setting the username and password for incoming and outgoing
mail are inconsisent: one uses `USERNAME` and `PASSWORD`, the other uses
`USER` and `PASSWD`.

To make things simpler, allow both to be configured by either, thus,
`[mailer].USERNAME` and `[mailer.PASSWORD]` will be aliases for `.USER`
and `.PASSWD`, and similarly, `[email.incoming].USER` and
`[email.incoming].PASSWD` will be aliases for `.USERNAME` and
`.PASSWORD`.

Fixes #3355.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-04-22 15:58:19 +02:00
parent 56831d345d
commit 073cc891c6
No known key found for this signature in database
4 changed files with 54 additions and 0 deletions

View file

@ -134,6 +134,14 @@ func loadMailerFrom(rootCfg ConfigProvider) {
sec.Key("PROTOCOL").SetValue("smtp+starttls")
}
// Handle aliases
if sec.HasKey("USERNAME") && !sec.HasKey("USER") {
sec.Key("USER").SetValue(sec.Key("USERNAME").String())
}
if sec.HasKey("PASSWORD") && !sec.HasKey("PASSWD") {
sec.Key("PASSWD").SetValue(sec.Key("PASSWORD").String())
}
// Set default values & validate
sec.Key("NAME").MustString(AppName)
sec.Key("PROTOCOL").In("", []string{"smtp", "smtps", "smtp+starttls", "smtp+unix", "sendmail", "dummy"})