Skip to content

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

Remove the Spintax grammar

lotkaade9bc9adca
diff --git a/core/internal/service/batch_mail/spintax.go b/core/internal/service/batch_mail/spintax.go
index 5e419070..2337bbb6 100644
--- a/core/internal/service/batch_mail/spintax.go
+++ b/core/internal/service/batch_mail/spintax.go
@@ -23,35 +23,36 @@ func NewSpintaxParser() *SpintaxParser {
// Supported format: {option1|option2|option3}
// Example: "Hello {{FirstName}}, I {want|thought|hope} to contact you..."
func (p *SpintaxParser) ParseSpintax(content string) string {
- // Match {option1|option2|option3} format
- spintaxRegex := regexp.MustCompile(`\{([^}]+)\}`)
-
- return spintaxRegex.ReplaceAllStringFunc(content, func(match string) string {
- // Extract content inside braces
- optionsStr := match[1 : len(match)-1]
-
- options := strings.Split(optionsStr, "|")
-
- for i, option := range options {
- options[i] = strings.TrimSpace(option)
- }
-
- validOptions := make([]string, 0)
- for _, option := range options {
- if option != "" {
- validOptions = append(validOptions, option)
- }
- }
-
- // If no valid options exist, return the original text
- if len(validOptions) == 0 {
- return match
- }
-
- // Randomly select an option
- selectedIndex := p.random.Intn(len(validOptions))
- return validOptions[selectedIndex]
- })
+ return content
+ //// Match {option1|option2|option3} format
+ //spintaxRegex := regexp.MustCompile(`\{([^}]+)\}`)
+ //
+ //return spintaxRegex.ReplaceAllStringFunc(content, func(match string) string {
+ // // Extract content inside braces
+ // optionsStr := match[1 : len(match)-1]
+ //
+ // options := strings.Split(optionsStr, "|")
+ //
+ // for i, option := range options {
+ // options[i] = strings.TrimSpace(option)
+ // }
+ //
+ // validOptions := make([]string, 0)
+ // for _, option := range options {
+ // if option != "" {
+ // validOptions = append(validOptions, option)
+ // }
+ // }
+ //
+ // // If no valid options exist, return the original text
+ // if len(validOptions) == 0 {
+ // return match
+ // }
+ //
+ // // Randomly select an option
+ // selectedIndex := p.random.Intn(len(validOptions))
+ // return validOptions[selectedIndex]
+ //})
}
// ParseSpintaxWithSeed Parse Spintax with a specified seed (used for testing or reproducible results)
diff --git a/core/internal/service/batch_mail/task_executor.go b/core/internal/service/batch_mail/task_executor.go
index 99914e58..02694fe0 100644
--- a/core/internal/service/batch_mail/task_executor.go
+++ b/core/internal/service/batch_mail/task_executor.go
@@ -15,6 +15,7 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/panjf2000/ants/v2"
+ "regexp"
"strings"
"sync"
"sync/atomic"
@@ -994,17 +995,17 @@ func (e *TaskExecutor) personalizeEmail(ctx context.Context, content string, tas
}
// Restore the erroneous variable
- //renderedContent = e.restoreErrorVariables(renderedContent)
- //renderedSubject = e.restoreErrorVariables(renderedSubject)
+ renderedContent = e.restoreErrorVariables(renderedContent)
+ renderedSubject = e.restoreErrorVariables(renderedSubject)
return renderedContent, renderedSubject
}
-//// restoreErrorVariables 恢复 [__变量__] 为 {{变量}}
-//func (e *TaskExecutor) restoreErrorVariables(content string) string {
-// re := regexp.MustCompile(`\[__([^_]+)__\]`)
-// return re.ReplaceAllString(content, "{{$1}}")
-//}
+// restoreErrorVariables 恢复 [__变量__] 为 {{变量}}
+func (e *TaskExecutor) restoreErrorVariables(content string) string {
+ re := regexp.MustCompile(`\[__([^_]+)__\]`)
+ return re.ReplaceAllString(content, "{{$1}}")
+}
// sendEmail send email
func (e *TaskExecutor) sendEmail(ctx context.Context, task *entity.EmailTask, recipient *entity.RecipientInfo, content string) *SendResult {
diff --git a/core/internal/service/batch_mail/template_render.go b/core/internal/service/batch_mail/template_render.go
index 3cf30796..94234ba9 100644
--- a/core/internal/service/batch_mail/template_render.go
+++ b/core/internal/service/batch_mail/template_render.go
@@ -144,8 +144,8 @@ func (e *TemplateEngine) RenderEmailTemplateWithAPI(ctx context.Context, content
"API": apiAttribs,
}
- // use template engine to render
- result, err := e.view.ParseContent(ctx, content, templateData)
+ // use template engine to render with error recovery
+ result, err := e.renderWithErrorRecovery(ctx, content, templateData)
if err != nil {
return "", err
}
@@ -165,13 +165,13 @@ func (e *TemplateEngine) renderWithErrorRecovery(ctx context.Context, content st
return result, nil
}
- //// Rendering failed. Uninitialized variables were encountered during cleanup.
- //cleanedContent := e.cleanUndefinedVariables(content)
- //result, err = e.view.ParseContent(ctx, cleanedContent, templateData)
- //if err != nil {
- //
- // return content, nil
- //}
+ // Rendering failed. Uninitialized variables were encountered during cleanup.
+ cleanedContent := e.cleanUndefinedVariables(content)
+ result, err = e.view.ParseContent(ctx, cleanedContent, templateData)
+ if err != nil {
+
+ return content, nil
+ }
return result, nil
}