-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix: Clear stale relay mappings and remove config block when disabled #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -440,6 +440,11 @@ func SyncRelayConfigsToPostfix(ctx context.Context) error { | |||||
| } else { | ||||||
|
|
||||||
| activeConfigs = []*entity.BmRelayConfig{} | ||||||
| // Clear stale relay transport mappings to ensure fallback to original SMTP | ||||||
| _, err = g.DB().Model("bm_domain_smtp_transport").Where("atype", "relay").Delete() | ||||||
| if err != nil { | ||||||
| g.Log().Warningf(ctx, "Failed to clear relay transport mappings: %v", err) | ||||||
| } | ||||||
| g.Log().Info(ctx, "No active relay to domain mappings, relay functionality will be disabled") | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -800,6 +805,21 @@ sender_dependent_default_transport_maps = pgsql:/etc/postfix/sql/pgsql_sender_tr | |||||
| } | ||||||
| modified = true | ||||||
| } | ||||||
| } else { | ||||||
| // Remove the configuration block when relay is disabled | ||||||
| if hasConfigBlock { | ||||||
| blockEnd := endIndex + len(endMarker) | ||||||
| // Include trailing newline if present | ||||||
| if blockEnd < len(content) && (content[blockEnd] == '\n' || content[blockEnd] == '\r') { | ||||||
| blockEnd++ | ||||||
| if blockEnd < len(content) && content[blockEnd] == '\n' { | ||||||
|
||||||
| if blockEnd < len(content) && content[blockEnd] == '\n' { | |
| if blockEnd < len(content) && (content[blockEnd] == '\n' || content[blockEnd] == '\r') { |
Copilot
AI
Dec 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context parameter inconsistency: The logging call uses nil for the context parameter, but the pattern used elsewhere in this file when context is unavailable is context.Background() (see lines 705, 747, 756, 758). Using context.Background() instead of nil is more idiomatic and consistent with the rest of the codebase.
| g.Log().Info(nil, "Removed relay configuration block from main.cf") | |
| g.Log().Info(context.Background(), "Removed relay configuration block from main.cf") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling inconsistency: Similar database delete operation at line 863 returns an error when the delete fails, but here it only logs a warning. This inconsistency could mask database issues. Consider returning the error instead of just logging it to maintain consistent error handling behavior throughout the function.