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
Perform basic email format verification when importing emails or creating marketing tasks
lotkfa3eafde8371
diff --git a/core/internal/controller/contact/contact_v1_import_contacts.go b/core/internal/controller/contact/contact_v1_import_contacts.goindex 656416e8..d75ff8e6 100644--- a/core/internal/controller/contact/contact_v1_import_contacts.go+++ b/core/internal/controller/contact/contact_v1_import_contacts.go@@ -14,6 +14,7 @@ import ("fmt""github.com/gogf/gf/v2/errors/gerror""github.com/gogf/gf/v2/frame/g"+ "github.com/gogf/gf/v2/util/gvalid""io""strings")@@ -134,7 +135,13 @@ func parseCSVContent(ctx context.Context, content string) ([]*entity.Contact, ercontinue}- contact := &entity.Contact{+ // Validate email format+ if err := gvalid.New().Rules("email").Data(email).Run(ctx); err != nil {+ g.Log().Warning(ctx, "Invalid email format in CSV, skipping: %s", email)+ continue+ }++ contact_s := &entity.Contact{Email: email,Active: -1,Attribs: make(map[string]string),@@ -144,9 +151,9 @@ func parseCSVContent(ctx context.Context, content string) ([]*entity.Contact, erif activeIdx, ok := columnIndexes["active"]; ok && len(record) > activeIdx {activeStr := strings.TrimSpace(record[activeIdx])if activeStr == "0" {- contact.Active = 0+ contact_s.Active = 0} else if activeStr == "1" {- contact.Active = 1+ contact_s.Active = 1}}@@ -158,12 +165,12 @@ func parseCSVContent(ctx context.Context, content string) ([]*entity.Contact, erif err != nil {g.Log().Warning(ctx, "Failed to parse attributes for email %s: %v", email, err)} else {- contact.Attribs = attribs+ contact_s.Attribs = attribs}}}- contacts = append(contacts, contact)+ contacts = append(contacts, contact_s)}return contacts, nil@@ -282,6 +289,11 @@ func (c *ControllerV1) ImportContacts(ctx context.Context, req *v1.ImportContactcontactInfo := *ccontactInfo.GroupId = groupId+ if err := gvalid.New().Rules("email").Data(contactInfo.Email).Run(ctx); err != nil {+ g.Log().Warning(ctx, "Invalid email format in CSV, skipping: %s", contactInfo.Email)+ continue+ }+if contactInfo.Active == -1 {contactInfo.Active = req.DefaultActive}diff --git a/core/internal/service/batch_mail/batch_mail.go b/core/internal/service/batch_mail/batch_mail.goindex 493a702d..df39fe92 100644--- a/core/internal/service/batch_mail/batch_mail.go+++ b/core/internal/service/batch_mail/batch_mail.go@@ -12,6 +12,7 @@ import ("github.com/gogf/gf/v2/errors/gerror""github.com/gogf/gf/v2/frame/g""github.com/gogf/gf/v2/util/gconv"+ "github.com/gogf/gf/v2/util/gvalid""strings""sync/atomic""time"@@ -235,8 +236,6 @@ func ImportRecipients(ctx context.Context, taskId int, contacts []*entity.Contacg.Log().Warning(ctx, "Could not get affected rows for batch %d/%d: %v", i+1, totalBatches, err)} else {totalImported += int(affected)- g.Log().Debug(ctx, "Task %d: Batch %d/%d imported %d recipients successfully",- taskId, i+1, totalBatches, affected)}}@@ -346,21 +345,29 @@ func CreateTaskWithRecipients(ctx context.Context, req *v1.CreateTaskReq, addTypcontinue}- // abnormal skip+ // abnormal skip and email format validationfilteredContacts := make([]*entity.Contact, 0, len(contacts))skippedInGroup := 0for _, contact := range contacts {+ // Check if email is in abnormal listif _, exists := abnormalMap[contact.Email]; exists {skippedInGroup++continue}++ // Validate email format+ if err := gvalid.New().Rules("email").Data(contact.Email).Run(ctx); err != nil {+ skippedInGroup+++ g.Log().Debug(ctx, "Skip erroneous email addresses:", contact.Email, " Error:", err)+ continue+ }+filteredContacts = append(filteredContacts, contact)}if skippedInGroup > 0 {totalSkipped += skippedInGroup-}if len(filteredContacts) == 0 {