feat(cli): configurable send-as From address (flags, TUI, validation)
- tui.ValidFromAddress: exported validator; blank passes, malformed rejects - Fields.FromAddress: new field, round-trips through ToAccount/FieldsFromAccount - Fields.Validate: calls ValidFromAddress before returning nil - TUI form: from_address fieldDef between username and password - send.go: From set via acc.SendFrom() instead of acc.Username - admin.go account add: --from flag with pre-parse validation - admin.go account edit: --from flag; validate before Visit, apply in Visit - USER-MANUAL.md: --from flag added to account add flags table Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -157,3 +157,36 @@ func TestAccountFormCancel(t *testing.T) {
|
||||
t.Fatal("esc should cancel the form")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsBadFromAddress(t *testing.T) {
|
||||
f := validFields()
|
||||
f.FromAddress = "not an address"
|
||||
if err := f.Validate(); err == nil {
|
||||
t.Fatal("malformed from-address should fail validation")
|
||||
}
|
||||
f.FromAddress = "Steve Cliff <me@stevecliff.com>"
|
||||
if err := f.Validate(); err != nil {
|
||||
t.Fatalf("display-name from-address should validate: %v", err)
|
||||
}
|
||||
f.FromAddress = "me@stevecliff.com"
|
||||
if err := f.Validate(); err != nil {
|
||||
t.Fatalf("bare from-address should validate: %v", err)
|
||||
}
|
||||
f.FromAddress = "" // blank ⇒ fall back, always valid
|
||||
if err := f.Validate(); err != nil {
|
||||
t.Fatalf("blank from-address should validate: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFieldsFromToAccountCarriesFromAddress(t *testing.T) {
|
||||
f := validFields()
|
||||
f.FromAddress = "Steve Cliff <me@stevecliff.com>"
|
||||
acc, _ := f.ToAccount()
|
||||
if acc.FromAddress != "Steve Cliff <me@stevecliff.com>" {
|
||||
t.Fatalf("ToAccount lost FromAddress: %q", acc.FromAddress)
|
||||
}
|
||||
back := FieldsFromAccount(acc)
|
||||
if back.FromAddress != "Steve Cliff <me@stevecliff.com>" {
|
||||
t.Fatalf("FieldsFromAccount lost FromAddress: %q", back.FromAddress)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user