Skip to content

Commit 0faf27f

Browse files
committed
Include username in email headers
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.
1 parent 28fe3db commit 0faf27f

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

services/mailer/mail.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,13 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
310310

311311
msgs := make([]*Message, 0, len(recipients))
312312
for _, recipient := range recipients {
313-
msg := NewMessageFrom(recipient.Email, ctx.Doer.DisplayName(), setting.MailService.FromEmail, subject, mailBody.String())
313+
msg := NewMessageFrom(
314+
recipient.Email,
315+
fmt.Sprintf("%s (@%s)", ctx.Doer.DisplayName(), ctx.Doer.Name),
316+
setting.MailService.FromEmail,
317+
subject,
318+
mailBody.String(),
319+
)
314320
msg.Info = fmt.Sprintf("Subject: %s, %s", subject, info)
315321

316322
msg.SetHeader("Message-ID", msgID)
@@ -394,8 +400,8 @@ func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient
394400

395401
"X-Mailer": "Gitea",
396402
"X-Gitea-Reason": reason,
397-
"X-Gitea-Sender": ctx.Doer.DisplayName(),
398-
"X-Gitea-Recipient": recipient.DisplayName(),
403+
"X-Gitea-Sender": ctx.Doer.Name,
404+
"X-Gitea-Recipient": recipient.Name,
399405
"X-Gitea-Recipient-Address": recipient.Email,
400406
"X-Gitea-Repository": repo.Name,
401407
"X-Gitea-Repository-Path": repo.FullName(),
@@ -404,8 +410,8 @@ func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient
404410
"X-Gitea-Issue-Link": ctx.Issue.HTMLURL(),
405411

406412
"X-GitHub-Reason": reason,
407-
"X-GitHub-Sender": ctx.Doer.DisplayName(),
408-
"X-GitHub-Recipient": recipient.DisplayName(),
413+
"X-GitHub-Sender": ctx.Doer.Name,
414+
"X-GitHub-Recipient": recipient.Name,
409415
"X-GitHub-Recipient-Address": recipient.Email,
410416

411417
"X-GitLab-NotificationReason": reason,

services/mailer/mail_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,16 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
239239
doer, _, issue, _ := prepareMailerTest(t)
240240

241241
ctx := &mailCommentContext{Context: context.TODO() /* TODO: use a correct context */, Issue: issue, Doer: doer}
242-
recipient := &user_model.User{Name: "Test", Email: "test@gitea.com"}
242+
recipient := &user_model.User{Name: "test", Email: "test@gitea.com"}
243243

244244
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
245245

246246
expected := map[string]string{
247247
"List-ID": "user2/repo1 <repo1.user2.localhost>",
248248
"List-Archive": "<https://try.gitea.io/user2/repo1>",
249249
"X-Gitea-Reason": "dummy-reason",
250-
"X-Gitea-Sender": "< U<se>r Tw<o > ><",
251-
"X-Gitea-Recipient": "Test",
250+
"X-Gitea-Sender": "user2",
251+
"X-Gitea-Recipient": "test",
252252
"X-Gitea-Recipient-Address": "test@gitea.com",
253253
"X-Gitea-Repository": "repo1",
254254
"X-Gitea-Repository-Path": "user2/repo1",

0 commit comments

Comments
 (0)