mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	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 <art27@cantab.net>
This commit is contained in:
		@@ -60,7 +60,7 @@ func SendEmail(ctx *context.PrivateContext) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		err := user_model.IterateUser(func(user *user_model.User) error {
 | 
							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)
 | 
									emails = append(emails, user.Email)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			return nil
 | 
								return nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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.
 | 
					// SendRegisterNotifyMail triggers a notify e-mail by admin created a account.
 | 
				
			||||||
func SendRegisterNotifyMail(u *user_model.User) {
 | 
					func SendRegisterNotifyMail(u *user_model.User) {
 | 
				
			||||||
	if setting.MailService == nil {
 | 
						if setting.MailService == nil || !u.IsActive {
 | 
				
			||||||
		// No mail service configured
 | 
							// No mail service configured OR user is inactive
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	locale := translation.NewLocale(u.Language)
 | 
						locale := translation.NewLocale(u.Language)
 | 
				
			||||||
@@ -176,8 +176,8 @@ func SendRegisterNotifyMail(u *user_model.User) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// SendCollaboratorMail sends mail notification to new collaborator.
 | 
					// SendCollaboratorMail sends mail notification to new collaborator.
 | 
				
			||||||
func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository) {
 | 
					func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository) {
 | 
				
			||||||
	if setting.MailService == nil {
 | 
						if setting.MailService == nil || !u.IsActive {
 | 
				
			||||||
		// No mail service configured
 | 
							// No mail service configured OR the user is inactive
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	locale := translation.NewLocale(u.Language)
 | 
						locale := translation.NewLocale(u.Language)
 | 
				
			||||||
@@ -405,6 +405,10 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	langMap := make(map[string][]*user_model.User)
 | 
						langMap := make(map[string][]*user_model.User)
 | 
				
			||||||
	for _, user := range recipients {
 | 
						for _, user := range recipients {
 | 
				
			||||||
 | 
							if !user.IsActive {
 | 
				
			||||||
 | 
								// don't send emails to inactive users
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		langMap[user.Language] = append(langMap[user.Language], user)
 | 
							langMap[user.Language] = append(langMap[user.Language], user)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,6 +31,10 @@ func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *repo_mode
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		langMap := make(map[string][]string)
 | 
							langMap := make(map[string][]string)
 | 
				
			||||||
		for _, user := range users {
 | 
							for _, user := range users {
 | 
				
			||||||
 | 
								if !user.IsActive {
 | 
				
			||||||
 | 
									// don't send emails to inactive users
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			langMap[user.Language] = append(langMap[user.Language], user.Email)
 | 
								langMap[user.Language] = append(langMap[user.Language], user.Email)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user