mirror of
https://github.com/warmbly/warmbly.git
synced 2026-11-29 08:06:27 +00:00
* feat: fix the six defects reported in issue #439 by mapping the IMAP UNAVAILABLE, INUSE and NONEXISTENT response codes to retry-level errors instead of a critical reconnect prompt, synthesising a stable no-msgid key so one message with no Message-ID header can no longer 400 the internal map endpoint and wedge every later sync pass with its cursors held, adding mailhtml.FromText and HasContent so an API or agent-created step with a plain body stops shipping the composer's empty div placeholder as its text/html part (derived on create and plain-only update, exposed as body_html on update_campaign_step, dropped at send and preview time, and refused at campaign start with empty_step_body), honouring sender_strategy='explicit' in ResolveCampaignSenderPool and ValidateCampaignReady so an emptied explicit pool parks the campaign instead of widening it to every mailbox in the workspace, making the paused_no_accounts auto-pause loud with an error log line, an error-level activity-feed entry and an org-scoped CAMPAIGN_PAUSED realtime pulse, gating the admin sign-in's Turnstile widget on GET /v1/auth/config so a self-host with CAPTCHA_PROVIDER=none is not locked out, and parsing NATS_URL down to its host:port so a credentialed bus URL no longer reports NATS down * feat: act on the self-review of the issue #439 fixes by dropping the campaign wizard's own escapeHtml body_html builder, which entity-escaped the quotes in a conditional and made the template fail to parse at send time, and letting the backend's FromText render that part instead so wizard-written steps also get their bare URLs linked for click tracking, correcting the docs and openapi description that claimed an explicit sender pool never falls back when it still unions its tags as migration 000013 designed, extracting the duplicated blank-HTML-part guard into dropBlankHTMLPart shared by the send path and the preview, and recording why the no-msgid key keeps the folder name despite a RENAME changing it * feat: address the CodeRabbit review on the issue #439 fixes by holding the admin sign-in's Turnstile widget unmounted until /v1/auth/config resolves so an instance with no route to Cloudflare cannot raise a widget error on a screen nobody submitted, failing StartCampaign closed when the sequence read errors rather than skipping both the malformed-template and empty-body refusals, giving TCPCheck the default port its protocol assumes so a portless NATS_URL is no longer reported down, leaving a URL that carries a merge field unanchored because the send path renders bodies with text/template and a quoted contact value would break out of the href, and correcting the sequences guide and the Campaign and CampaignUpdate openapi descriptions that named the wrong tag field
65 lines
2.3 KiB
Go
65 lines
2.3 KiB
Go
package wmail
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/warmbly/warmbly/internal/models"
|
|
)
|
|
|
|
// One message with no Message-ID header used to end every sync pass: the empty
|
|
// string is not a map key, the internal endpoint refuses it with 400, and
|
|
// controlPlaneError holds the cursors, so the same batch came back forever.
|
|
func TestEnsureMessageKeySynthesizesAStableKey(t *testing.T) {
|
|
w := &WMail{SmtpImapData: &SmtpImapData{folderPath: "INBOX", mailbox: 42}}
|
|
|
|
msg := &models.EmailMessageData{UID: 17}
|
|
w.ensureMessageKey(msg)
|
|
if msg.MessageID == "" {
|
|
t.Fatal("a message with no Message-ID still has no key")
|
|
}
|
|
|
|
// Stable: the next pass has to recognise the message as already stored.
|
|
again := &models.EmailMessageData{UID: 17}
|
|
w.ensureMessageKey(again)
|
|
if again.MessageID != msg.MessageID {
|
|
t.Errorf("key is not stable across passes: %q then %q", msg.MessageID, again.MessageID)
|
|
}
|
|
|
|
other := &models.EmailMessageData{UID: 18}
|
|
w.ensureMessageKey(other)
|
|
if other.MessageID == msg.MessageID {
|
|
t.Errorf("two UIDs share the key %q", other.MessageID)
|
|
}
|
|
}
|
|
|
|
func TestEnsureMessageKeyLeavesARealIDAlone(t *testing.T) {
|
|
w := &WMail{SmtpImapData: &SmtpImapData{folderPath: "INBOX"}}
|
|
|
|
msg := &models.EmailMessageData{MessageID: "<real@example.test>", UID: 3}
|
|
w.ensureMessageKey(msg)
|
|
if msg.MessageID != "<real@example.test>" {
|
|
t.Errorf("MessageID = %q, want the header's own value", msg.MessageID)
|
|
}
|
|
|
|
// A header that is present but blank is no more of a key than a missing one.
|
|
blank := &models.EmailMessageData{MessageID: " ", UID: 4}
|
|
w.ensureMessageKey(blank)
|
|
if blank.MessageID == " " {
|
|
t.Error("a whitespace-only Message-ID was kept as the map key")
|
|
}
|
|
}
|
|
|
|
// An In-Reply-To whose entries are blank is the same wedge one step along: the
|
|
// empty parent id would go to the map endpoint as a key.
|
|
func TestThreadParentIDSkipsBlankEntries(t *testing.T) {
|
|
if got := threadParentID(&models.EmailMessageData{InReplyTo: []string{"<a@x>", " "}}); got != "<a@x>" {
|
|
t.Errorf("threadParentID = %q, want the last non-blank id", got)
|
|
}
|
|
if got := threadParentID(&models.EmailMessageData{InReplyTo: []string{"", " "}}); got != "" {
|
|
t.Errorf("threadParentID = %q, want no parent", got)
|
|
}
|
|
if got := threadParentID(nil); got != "" {
|
|
t.Errorf("threadParentID(nil) = %q, want no parent", got)
|
|
}
|
|
}
|