fix(clients): match non-ASCII capitals in the shared-email checks

The checks that decide whether a client_traffics row is still used by
another inbound, whether an email is already taken under another subId,
and which depleted rows a scoped delete may drop compared a Go-lowered
email with LOWER(clients.email), which SQLite folds for ASCII only. An
email such as Иван was never seen as attached elsewhere, so the node
sweep deleted the usage row of a client the master's own inbound still
served and the client outlived its expiry and quota.

Each check now matches the lowered or the stored spelling and keys the
result in Go, so ASCII behaviour is unchanged.
This commit is contained in:
MHSanaei
2026-11-01 08:37:01 +01:00
parent 2024d34928
commit bd36053356
4 changed files with 216 additions and 51 deletions
+5 -14
View File
@@ -616,29 +616,20 @@ func (s *InboundService) GetAllEmails() ([]string, error) {
// checked. One clients row owns an email's identity, so the answer no longer
// needs a scan of every inbound's settings JSON (#6252).
func (s *InboundService) emailSubIDsForClients(clients []model.Client) (map[string]string, error) {
want := make(map[string]struct{}, len(clients))
emails := make([]string, 0, len(clients))
for i := range clients {
if email := strings.ToLower(strings.TrimSpace(clients[i].Email)); email != "" {
want[email] = struct{}{}
}
}
result := make(map[string]string, len(want))
if len(want) == 0 {
return result, nil
}
lowered := make([]string, 0, len(want))
for email := range want {
lowered = append(lowered, email)
emails = append(emails, clients[i].Email)
}
result := make(map[string]string, len(emails))
db := database.GetDB()
for _, batch := range chunkStrings(lowered, sqlInChunk) {
for _, batch := range chunkStrings(emailSpellings(emails), sqlInChunk) {
var rows []struct {
Email string
SubID string `gorm:"column:sub_id"`
}
err := db.Model(&model.ClientRecord{}).
Select("email, sub_id").
Where("LOWER(email) IN ?", batch).
Where("LOWER(email) IN ? OR email IN ?", batch, batch).
Scan(&rows).Error
if err != nil {
return nil, err