Skip to content

Commit

Permalink
Do not send notification emails to inactive users (go-gitea#19131)
Browse files Browse the repository at this point in the history
Emails should not be sent to inactive users except for Activate and ResetPassword
messages.

Fix go-gitea#18950

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored and Stelios Malathouras committed Mar 28, 2022
1 parent 72a56fd commit fec2282
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion routers/private/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func SendEmail(ctx *context.PrivateContext) {
}
} else {
err := user_model.IterateUser(func(user *user_model.User) error {
if len(user.Email) > 0 {
if len(user.Email) > 0 && user.IsActive {
emails = append(emails, user.Email)
}
return nil
Expand Down
12 changes: 8 additions & 4 deletions services/mailer/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func SendActivateEmailMail(u *user_model.User, email *user_model.EmailAddress) {

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

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

langMap := make(map[string][]*user_model.User)
for _, user := range recipients {
if !user.IsActive {
// don't send emails to inactive users
continue
}
langMap[user.Language] = append(langMap[user.Language], user)
}

Expand Down
4 changes: 4 additions & 0 deletions services/mailer/mail_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *repo_mode

langMap := make(map[string][]string)
for _, user := range users {
if !user.IsActive {
// don't send emails to inactive users
continue
}
langMap[user.Language] = append(langMap[user.Language], user.Email)
}

Expand Down

0 comments on commit fec2282

Please sign in to comment.