Skip to content

Commit fb08d2b

Browse files
authored
Do not send notification emails to inactive users (#19131)
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 60fbaa9 commit fb08d2b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-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)
@@ -405,6 +405,10 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
405405

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

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)