Skip to content

Commit 45c836b

Browse files
authored
Do not send notification emails to inactive users (#19131) (#19139)
Backport #19131 Backport #19142 Emails should not be sent to inactive users except for Activate and ResetPassword messages. Fix #18950 Signed-off-by: Andrew Thornton <[email protected]>
1 parent f9ea4ab commit 45c836b

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

routers/private/mail.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func SendEmail(ctx *context.PrivateContext) {
6060
}
6161
} else {
6262
err := user_model.IterateUser(func(user *user_model.User) error {
63-
if len(user.Email) > 0 {
63+
if len(user.Email) > 0 && user.IsActive {
6464
emails = append(emails, user.Email)
6565
}
6666
return nil

services/mailer/mail.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ func SendActivateEmailMail(u *user_model.User, email *user_model.EmailAddress) {
146146

147147
// SendRegisterNotifyMail triggers a notify e-mail by admin created a account.
148148
func SendRegisterNotifyMail(u *user_model.User) {
149-
if setting.MailService == nil {
150-
// No mail service configured
149+
if setting.MailService == nil || !u.IsActive {
150+
// No mail service configured OR user is inactive
151151
return
152152
}
153153
locale := translation.NewLocale(u.Language)
@@ -176,8 +176,8 @@ func SendRegisterNotifyMail(u *user_model.User) {
176176

177177
// SendCollaboratorMail sends mail notification to new collaborator.
178178
func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository) {
179-
if setting.MailService == nil {
180-
// No mail service configured
179+
if setting.MailService == nil || !u.IsActive {
180+
// No mail service configured OR the user is inactive
181181
return
182182
}
183183
locale := translation.NewLocale(u.Language)
@@ -404,6 +404,10 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
404404

405405
langMap := make(map[string][]*user_model.User)
406406
for _, user := range recipients {
407+
if !user.IsActive {
408+
// don't send emails to inactive users
409+
continue
410+
}
407411
langMap[user.Language] = append(langMap[user.Language], user)
408412
}
409413

services/mailer/mail_issue.go

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi
125125

126126
langMap := make(map[string][]*user_model.User)
127127
for _, user := range users {
128+
if !user.IsActive {
129+
// Exclude deactivated users
130+
continue
131+
}
128132
// At this point we exclude:
129133
// user that don't have all mails enabled or users only get mail on mention and this is one ...
130134
if !(user.EmailNotificationsPreference == user_model.EmailNotificationsEnabled ||

services/mailer/mail_repo.go

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *repo_mode
3131

3232
langMap := make(map[string][]string)
3333
for _, user := range users {
34+
if !user.IsActive {
35+
// don't send emails to inactive users
36+
continue
37+
}
3438
langMap[user.Language] = append(langMap[user.Language], user.Email)
3539
}
3640

0 commit comments

Comments
 (0)