BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
ensure mailboxes is lowercase.
Jack426498f540de
diff --git a/core/internal/service/mail_boxes/mail_boxes.go b/core/internal/service/mail_boxes/mail_boxes.goindex ee69fba8..96b63444 100644--- a/core/internal/service/mail_boxes/mail_boxes.go+++ b/core/internal/service/mail_boxes/mail_boxes.go@@ -11,6 +11,7 @@ import ("github.com/gogf/gf/v2/frame/g""math/rand""regexp"+ "strings""time")@@ -26,6 +27,10 @@ func Add(ctx context.Context, mailbox *v1.Mailbox) (err error) {return}+ mailbox.Username = strings.ToLower(mailbox.Username)+ mailbox.LocalPart = strings.ToLower(mailbox.LocalPart)+ mailbox.Domain = strings.ToLower(mailbox.Domain)+now := time.Now().Unix()mailbox.CreateTime = nowmailbox.UpdateTime = now@@ -49,6 +54,11 @@ func Update(ctx context.Context, mailbox *v1.Mailbox) (err error) {mailbox.PasswordEncode = PasswdEncode(ctx, mailbox.Password)}+ mailbox.Username = strings.ToLower(mailbox.Username)+ mailbox.LocalPart = strings.ToLower(mailbox.LocalPart)+ mailbox.Domain = strings.ToLower(mailbox.Domain)+ mailbox.Maildir = fmt.Sprintf("%s@%s/", mailbox.LocalPart, mailbox.Domain)+_, err = g.DB().Model("mailbox").Ctx(ctx).Where("username", mailbox.Username).@@ -270,3 +280,16 @@ func BatchAdd(ctx context.Context, domain, password string, quota int, count intreturn createdEmails, nil}++// NormalizeMailboxes normalizes mailbox usernames, local parts, domains, and maildirs to lowercase.+func NormalizeMailboxes() (err error) {+ // Attempt update mailboxes with uppercase letters in username+ _, err = g.DB().Model("mailbox").Where("username ~ '[A-Z]+'").Update(g.Map{+ "username": gdb.Raw("LOWER(username)"),+ "local_part": gdb.Raw("LOWER(local_part)"),+ "domain": gdb.Raw("LOWER(domain)"),+ "maildir": gdb.Raw("LOWER(maildir)"),+ })++ return+}diff --git a/core/internal/service/timers/timers.go b/core/internal/service/timers/timers.goindex ea3596f7..dfda2d99 100644--- a/core/internal/service/timers/timers.go+++ b/core/internal/service/timers/timers.go@@ -3,6 +3,7 @@ package timersimport ("billionmail-core/internal/service/batch_mail""billionmail-core/internal/service/domains"+ "billionmail-core/internal/service/mail_boxes""billionmail-core/internal/service/maillog_stat""billionmail-core/internal/service/relay""context"@@ -15,6 +16,20 @@ import (func Start(ctx context.Context) (err error) {g.Log().Debug(ctx, "Starting timers...")+ // Normalize mailboxes to lowercase+ gtimer.AddOnce(1*time.Second, func() {+ g.Log().Debug(ctx, "Mailboxes normalization started")++ err = mail_boxes.NormalizeMailboxes()++ if err != nil {+ g.Log().Warning(ctx, "NormalizeMailboxes failed: ", err)+ err = nil // Ignore the error to allow the service to continue+ } else {+ g.Log().Debug(ctx, "Mailboxes normalized successfully")+ }+ })+// Start DNS Records checking// Ensure the DNS records are fresh on startupgtimer.AddOnce(5*time.Second, func() {