Skip to content

Commit 89e0323

Browse files
mfenniakEarl Warren
authored andcommitted
fix: respect UI DEFAULT_SHOW_FULL_NAME setting in email From: headers (go-gitea#9307)
Changes email's `From` field to respect the server's `DEFAULT_SHOW_FULL_NAME` setting, bringing consistency between seeing an email from a user, opening the related issue, and seeing a different name in Forgejo's web UI. Manually tested by varying the `DEFAULT_SHOW_FULL_NAME` server property, enabling and disabling it: ![image](/attachments/234b26b5-da8a-4220-955e-f20c61e418e8) Fixes go-gitea#9149. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). - Performed manual testing with ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9307 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
1 parent 548cd0c commit 89e0323

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

services/mailer/mail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func fromDisplayName(u *user_model.User) string {
575575
if setting.MailService.FromDisplayNameFormatTemplate != nil {
576576
var ctx bytes.Buffer
577577
err := setting.MailService.FromDisplayNameFormatTemplate.Execute(&ctx, map[string]any{
578-
"DisplayName": u.DisplayName(),
578+
"DisplayName": u.GetDisplayName(),
579579
"AppName": setting.AppName,
580580
"Domain": setting.Domain,
581581
})

services/mailer/mail_test.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -497,31 +497,44 @@ func TestFromDisplayName(t *testing.T) {
497497
defer test.MockVariableValue(&setting.MailService, &setting.Mailer{FromDisplayNameFormatTemplate: template})()
498498

499499
tests := []struct {
500-
userDisplayName string
501-
fromDisplayName string
500+
userDisplayName string
501+
fromDisplayName string
502+
defaultShowFullName bool
502503
}{{
503-
userDisplayName: "test",
504-
fromDisplayName: "test",
504+
userDisplayName: "test",
505+
fromDisplayName: "test",
506+
defaultShowFullName: true,
505507
}, {
506-
userDisplayName: "Hi Its <Mee>",
507-
fromDisplayName: "Hi Its <Mee>",
508+
userDisplayName: "Hi Its <Mee>",
509+
fromDisplayName: "Hi Its <Mee>",
510+
defaultShowFullName: true,
508511
}, {
509-
userDisplayName: "Æsir",
510-
fromDisplayName: "=?utf-8?q?=C3=86sir?=",
512+
userDisplayName: "Æsir",
513+
fromDisplayName: "=?utf-8?q?=C3=86sir?=",
514+
defaultShowFullName: true,
511515
}, {
512-
userDisplayName: "new😀user",
513-
fromDisplayName: "=?utf-8?q?new=F0=9F=98=80user?=",
516+
userDisplayName: "new😀user",
517+
fromDisplayName: "=?utf-8?q?new=F0=9F=98=80user?=",
518+
defaultShowFullName: true,
519+
}, {
520+
userDisplayName: "new😀user",
521+
fromDisplayName: "tmp",
522+
defaultShowFullName: false,
514523
}}
515524

516525
for _, tc := range tests {
517526
t.Run(tc.userDisplayName, func(t *testing.T) {
527+
defer test.MockVariableValue(&setting.UI.DefaultShowFullName, tc.defaultShowFullName)()
528+
518529
user := &user_model.User{FullName: tc.userDisplayName, Name: "tmp"}
519530
got := fromDisplayName(user)
520531
assert.Equal(t, tc.fromDisplayName, got)
521532
})
522533
}
523534

524535
t.Run("template with all available vars", func(t *testing.T) {
536+
defer test.MockVariableValue(&setting.UI.DefaultShowFullName, true)()
537+
525538
template, err = texttmpl.New("mailFrom").Parse("{{ .DisplayName }} (by {{ .AppName }} on [{{ .Domain }}])")
526539
require.NoError(t, err)
527540
defer test.MockVariableValue(&setting.MailService, &setting.Mailer{FromDisplayNameFormatTemplate: template})()

0 commit comments

Comments
 (0)