diff options
author | Gwyneth Morgan <gwymor@tilde.club> | 2024-02-03 00:41:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-03 00:41:27 +0000 |
commit | 360b3fd17c3315ad9ad9c4e6ac02eda73f48d8ae (patch) | |
tree | eb38aa98eb545176148f23af28169749a4617aa8 /models | |
parent | a6cea595146d0de42aa83c9cca929b015aae4552 (diff) | |
download | gitea-360b3fd17c3315ad9ad9c4e6ac02eda73f48d8ae.tar.gz gitea-360b3fd17c3315ad9ad9c4e6ac02eda73f48d8ae.zip |
Include username in email headers (#28981)
Emails from Gitea comments do not contain the username of the commenter
anywhere, only their display name, so it is not possible to verify who
made a comment from the email itself:
From: "Alice" <email@gitea>
X-Gitea-Sender: Alice
X-Gitea-Recipient: Bob
X-GitHub-Sender: Alice
X-GitHub-Recipient: Bob
This comment looks like it's from @alice.
The X-Gitea/X-GitHub headers also use display names, which is not very
reliable for filtering, and inconsistent with GitHub's behavior:
X-GitHub-Sender: lunny
X-GitHub-Recipient: gwymor
This change includes both the display name and username in the From
header, and switches the other headers from display name to username:
From: "Alice (@fakealice)" <email@gitea>
X-Gitea-Sender: fakealice
X-Gitea-Recipient: bob
X-GitHub-Sender: fakealice
X-GitHub-Recipient: bob
This comment looks like it's from @alice.
Diffstat (limited to 'models')
-rw-r--r-- | models/user/user.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/models/user/user.go b/models/user/user.go index 6d1b1aef18..269a1be725 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -443,6 +443,17 @@ func (u *User) GetDisplayName() string { return u.Name } +// GetCompleteName returns the the full name and username in the form of +// "Full Name (@username)" if full name is not empty, otherwise it returns +// "@username". +func (u *User) GetCompleteName() string { + trimmedFullName := strings.TrimSpace(u.FullName) + if len(trimmedFullName) > 0 { + return fmt.Sprintf("%s (@%s)", trimmedFullName, u.Name) + } + return fmt.Sprintf("@%s", u.Name) +} + func gitSafeName(name string) string { return strings.TrimSpace(strings.NewReplacer("\n", "", "<", "", ">", "").Replace(name)) } |