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))
}
msgs := make([]*Message, 0, len(recipients))
for _, recipient := range recipients {
- msg := NewMessageFrom(recipient.Email, ctx.Doer.DisplayName(), setting.MailService.FromEmail, subject, mailBody.String())
+ msg := NewMessageFrom(
+ recipient.Email,
+ ctx.Doer.GetCompleteName(),
+ setting.MailService.FromEmail,
+ subject,
+ mailBody.String(),
+ )
msg.Info = fmt.Sprintf("Subject: %s, %s", subject, info)
msg.SetHeader("Message-ID", msgID)
"X-Mailer": "Gitea",
"X-Gitea-Reason": reason,
- "X-Gitea-Sender": ctx.Doer.DisplayName(),
- "X-Gitea-Recipient": recipient.DisplayName(),
+ "X-Gitea-Sender": ctx.Doer.Name,
+ "X-Gitea-Recipient": recipient.Name,
"X-Gitea-Recipient-Address": recipient.Email,
"X-Gitea-Repository": repo.Name,
"X-Gitea-Repository-Path": repo.FullName(),
"X-Gitea-Issue-Link": ctx.Issue.HTMLURL(),
"X-GitHub-Reason": reason,
- "X-GitHub-Sender": ctx.Doer.DisplayName(),
- "X-GitHub-Recipient": recipient.DisplayName(),
+ "X-GitHub-Sender": ctx.Doer.Name,
+ "X-GitHub-Recipient": recipient.Name,
"X-GitHub-Recipient-Address": recipient.Email,
"X-GitLab-NotificationReason": reason,
doer, _, issue, _ := prepareMailerTest(t)
ctx := &mailCommentContext{Context: context.TODO() /* TODO: use a correct context */, Issue: issue, Doer: doer}
- recipient := &user_model.User{Name: "Test", Email: "test@gitea.com"}
+ recipient := &user_model.User{Name: "test", Email: "test@gitea.com"}
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
"List-ID": "user2/repo1 <repo1.user2.localhost>",
"List-Archive": "<https://try.gitea.io/user2/repo1>",
"X-Gitea-Reason": "dummy-reason",
- "X-Gitea-Sender": "< U<se>r Tw<o > ><",
- "X-Gitea-Recipient": "Test",
+ "X-Gitea-Sender": "user2",
+ "X-Gitea-Recipient": "test",
"X-Gitea-Recipient-Address": "test@gitea.com",
"X-Gitea-Repository": "repo1",
"X-Gitea-Repository-Path": "user2/repo1",