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
feat: enhance tag logic to support NOT condition in batch mail processing Remove the restrictions on IP addresses for unsubscribing
lotkb6303572b387
diff --git a/core/api/batch_mail/v1/batch_mail.go b/core/api/batch_mail/v1/batch_mail.goindex 36e533d7..1c9d6014 100644--- a/core/api/batch_mail/v1/batch_mail.go+++ b/core/api/batch_mail/v1/batch_mail.go@@ -3,6 +3,7 @@ package v1import ("billionmail-core/internal/model/entity""billionmail-core/utility/types/api_v1"+"github.com/gogf/gf/v2/frame/g")@@ -44,7 +45,7 @@ type EmailTask struct {GroupName string `json:"group_name" dc:"Group Name"`Tags []TagInfo `json:"tags" dc:"Task Tags"`UseTagFilter int `json:"use_tag_filter" dc:"Whether to use tag filter (1: yes, 0: no)"`- TagLogic string `json:"tag_logic" dc:"Tag logic (AND: must have all tags, OR: have any tag)"`+ TagLogic string `json:"tag_logic" dc:"Tag logic (AND: must have all tags, OR: have any tag, NOT)"`TagIdsRaw string `json:"-" dc:"Tag IDs raw data for internal processing"`}@@ -153,7 +154,7 @@ type CreateTaskReq struct {Remark string `json:"remark" dc:"remark"`TagIds []int `json:"tag_ids" dc:"tag ids for filtering contacts"`- TagLogic string `json:"tag_logic" v:"in:AND,OR" dc:"tag logic (AND: must have all tags, OR: have any tag)" default:"AND"`+ TagLogic string `json:"tag_logic" v:"in:AND,OR,NOT" dc:"tag logic (AND: must have all tags, OR: have any tag, NOT)" default:"AND"`}type CreateTaskRes struct {@@ -279,7 +280,7 @@ type UpdateTaskInfoReq struct {Threads int `json:"threads" v:"min:0" dc:"threads"`StartTime int `json:"start_time" dc:"start time"`TagIds []int `json:"tag_ids" dc:"tag ids for filtering contacts"`- TagLogic string `json:"tag_logic" v:"in:AND,OR" dc:"tag logic (AND: must have all tags, OR: have any tag)"`+ TagLogic string `json:"tag_logic" v:"in:AND,OR,NOT" dc:"tag logic (AND: must have all tags, OR: have any tag, NOT)"`}type UpdateTaskInfoRes struct {api_v1.StandardResdiff --git a/core/api/contact/v1/contact.go b/core/api/contact/v1/contact.goindex ea703eb5..bdaa31ec 100644--- a/core/api/contact/v1/contact.go+++ b/core/api/contact/v1/contact.go@@ -2,6 +2,7 @@ package v1import ("billionmail-core/utility/types/api_v1"+"github.com/gogf/gf/v2/frame/g")@@ -322,7 +323,7 @@ type GetSingleGroupTagContactCountReq struct {Authorization string `json:"authorization" dc:"Authorization" in:"header"`GroupId int `json:"group_id" v:"required" dc:"Group ID"`TagIds []int `json:"tag_ids" dc:"Tag IDs"`- TagLogic string `json:"tag_logic" v:"required|in:AND,OR" dc:"Tag Logic (AND/OR)"`+ TagLogic string `json:"tag_logic" v:"required|in:AND,OR,NOT" dc:"Tag Logic (AND/OR/NOT)"`}type GetSingleGroupTagContactCountRes struct {diff --git a/core/internal/controller/batch_mail/batch_mail_v1_create_task.go b/core/internal/controller/batch_mail/batch_mail_v1_create_task.goindex 89f47190..3313683a 100644--- a/core/internal/controller/batch_mail/batch_mail_v1_create_task.go+++ b/core/internal/controller/batch_mail/batch_mail_v1_create_task.go@@ -5,6 +5,7 @@ import ("billionmail-core/internal/service/batch_mail""billionmail-core/internal/service/public""context"+"github.com/gogf/gf/v2/errors/gerror""billionmail-core/api/batch_mail/v1"@@ -57,8 +58,8 @@ func validateCreateTaskRequest(req *v1.CreateTaskReq) error {}if len(req.TagIds) > 0 {- if req.TagLogic != "" && req.TagLogic != "AND" && req.TagLogic != "OR" {- return gerror.New("Tag logic must be AND or OR")+ if req.TagLogic != "" && req.TagLogic != "AND" && req.TagLogic != "OR" && req.TagLogic != "NOT" {+ return gerror.New("Tag logic must be AND or OR or NOT")}if req.TagLogic == "" {diff --git a/core/internal/controller/batch_mail/batch_mail_v1_update_task_info.go b/core/internal/controller/batch_mail/batch_mail_v1_update_task_info.goindex 58526508..0d7bd731 100644--- a/core/internal/controller/batch_mail/batch_mail_v1_update_task_info.go+++ b/core/internal/controller/batch_mail/batch_mail_v1_update_task_info.go@@ -5,6 +5,7 @@ import ("billionmail-core/internal/service/batch_mail""billionmail-core/internal/service/public""context"+"github.com/gogf/gf/v2/errors/gerror""github.com/gogf/gf/v2/frame/g"@@ -76,7 +77,7 @@ func (c *ControllerV1) UpdateTaskInfo(ctx context.Context, req *v1.UpdateTaskInfif len(req.TagIds) > 0 {updateData["tag_ids"] = req.TagIds}- if req.TagLogic == "AND" || req.TagLogic == "OR" {+ if req.TagLogic == "AND" || req.TagLogic == "OR" || req.TagLogic == "NOT" {updateData["tag_logic"] = req.TagLogic}if len(updateData) == 0 {diff --git a/core/internal/controller/contact/contact_v1_get_single_group_tag_contact_count.go b/core/internal/controller/contact/contact_v1_get_single_group_tag_contact_count.goindex d0ef33c5..3555dd1b 100644--- a/core/internal/controller/contact/contact_v1_get_single_group_tag_contact_count.go+++ b/core/internal/controller/contact/contact_v1_get_single_group_tag_contact_count.go@@ -6,10 +6,11 @@ import ("billionmail-core/internal/service/public""context""fmt"- "github.com/gogf/gf/v2/frame/g""strconv""strings"+ "github.com/gogf/gf/v2/frame/g"+"github.com/gogf/gf/v2/errors/gerror")@@ -48,7 +49,7 @@ func (c *ControllerV1) GetSingleGroupTagContactCount(ctx context.Context, req *vfmt.Sprintf("c.id = %s.contact_id AND %s.tag_id = %d", alias, alias, tagId),)}- } else {+ } else if req.TagLogic == "OR" {// OR logic: contact must have at least one of the tagsvar inValues []stringfor _, tagId := range req.TagIds {@@ -59,6 +60,17 @@ func (c *ControllerV1) GetSingleGroupTagContactCount(ctx context.Context, req *vstrings.Join(inValues, ","),)model = model.InnerJoin(subQuery, "c.id = ct.contact_id")+ } else if req.TagLogic == "NOT" {+ // NOT logic: exclude contacts that have any of the specified tags+ var tagIdStr []string+ for _, tagId := range req.TagIds {+ tagIdStr = append(tagIdStr, strconv.Itoa(tagId))+ }++ subQuery := g.DB().Model("bm_contact_tags").+ Fields("DISTINCT contact_id").+ WhereIn("tag_id", req.TagIds)+ model = model.WhereNotIn("c.id", subQuery)}}diff --git a/core/internal/controller/middleware/ip_whitelist.go b/core/internal/controller/middleware/ip_whitelist.goindex f4ca9455..dfc71d41 100644--- a/core/internal/controller/middleware/ip_whitelist.go+++ b/core/internal/controller/middleware/ip_whitelist.go@@ -3,10 +3,11 @@ package middlewareimport ("billionmail-core/internal/service/public""context"+ "strings"+"github.com/gogf/gf/v2/frame/g""github.com/gogf/gf/v2/net/ghttp""github.com/gogf/gf/v2/os/gfile"- "strings")// Paths excluded from IP whitelist verification@@ -15,9 +16,10 @@ var ExcludedPaths = map[string]struct{}{"/robots.txt": {},"/unsubscribe.html": {},"/unsubscribe_new.html": {},+ "/api/languages/get": {},"/api/unsubscribe/user_group": {},"/api/unsubscribe": {},- "api/unsubscribe_new": {},+ "/api/unsubscribe_new": {},"/api/batch_mail/api/send": {},"/api/batch_mail/api/batch_send": {},"/api/subscribe/submit": {},@@ -26,7 +28,8 @@ var ExcludedPaths = map[string]struct{}{"/subscribe_confirm.html": {},"/subscribe_form.html": {},"/subscribe_success.html": {},- // other+ "/unsubscribe_success.html": {},+ "/subscribe_form_code.html": {},}func isExcludedPath(path string) bool {diff --git a/core/internal/controller/overview/overview_v1_overview.go b/core/internal/controller/overview/overview_v1_overview.goindex 5926985e..be84786f 100644--- a/core/internal/controller/overview/overview_v1_overview.go+++ b/core/internal/controller/overview/overview_v1_overview.go@@ -5,9 +5,10 @@ import ("billionmail-core/internal/service/public""context""fmt"- "github.com/gogf/gf/v2/util/gconv""time"+ "github.com/gogf/gf/v2/util/gconv"+"billionmail-core/api/overview/v1")diff --git a/core/internal/model/entity/batch_mail.go b/core/internal/model/entity/batch_mail.goindex 1d2ea05c..0e229307 100644--- a/core/internal/model/entity/batch_mail.go+++ b/core/internal/model/entity/batch_mail.go@@ -88,7 +88,7 @@ type EmailTask struct {GroupId int `json:"group_id" dc:"Group ID"`TagIdsRaw string `json:"-" dc:"Tag IDs (JSON string - internal use)" orm:"tag_ids"`TagIds []int `json:"tag_ids" dc:"Tag IDs (parsed array)"`- TagLogic string `json:"tag_logic" dc:"Tag Logic (AND/OR)"`+ TagLogic string `json:"tag_logic" dc:"Tag Logic (AND/OR/NOT)"`UseTagFilter int `json:"use_tag_filter" dc:"Use Tag Filter (0: no, 1: yes)"`}diff --git a/core/internal/service/batch_mail/batch_mail.go b/core/internal/service/batch_mail/batch_mail.goindex 59471db4..b72dd11a 100644--- a/core/internal/service/batch_mail/batch_mail.go+++ b/core/internal/service/batch_mail/batch_mail.go@@ -8,15 +8,16 @@ import ("billionmail-core/internal/service/warmup""context""fmt"+ "strconv"+ "strings"+ "sync/atomic"+ "time"+"github.com/gogf/gf/v2/database/gdb""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"- "strconv"- "strings"- "sync/atomic"- "time")var (@@ -363,7 +364,7 @@ func GetFilteredContacts(ctx context.Context, filter ContactFilter) ([]*entity.C"c.id = "+alias+".contact_id AND "+alias+".tag_id = "+g.NewVar(tagId).String(),)}- } else {+ } else if filter.TagLogic == "OR" {// ORvar inValues []stringfor _, tagId := range filter.TagIds {@@ -380,6 +381,12 @@ func GetFilteredContacts(ctx context.Context, filter ContactFilter) ([]*entity.CsubQuery,"c.id = ct.contact_id",)+ } else if filter.TagLogic == "NOT" {+ // NOT: contact must not have any of the selected tags+ subQuery := g.DB().Model("bm_contact_tags").+ Fields("DISTINCT contact_id").+ WhereIn("tag_id", filter.TagIds)+ model = model.WhereNotIn("c.id", subQuery)}}