feat(mail): give free members a webmail password at join@

The gateway opens mailboxes via the Dovecot master user (no member password),
but webmail (Roundcube) needs the member to have a password. join@ now sets a
fresh, readable webmail password via the Mailu API and shows it with the webmail
URL + login, so free members can use webmail at mail.profullstack.com.

- mailu: SetPassword (PATCH /user/<email> raw_password) + test.
- main.go: setWebmailPassword + readablePassword; join@ displays url/login/password.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-06-23 09:57:46 +00:00
parent 1cc6a9c89e
commit 7a6e466977
3 changed files with 92 additions and 1 deletions

View file

@ -168,6 +168,26 @@ func (c *Client) EnsureUser(ctx context.Context, localPart, domain string) error
return fmt.Errorf("mailu create user %s: %s: %s", email, resp.Status, strings.TrimSpace(string(b)))
}
// SetPassword sets the mailbox password (so the member can log into webmail).
// The gateway opens mailboxes via the Dovecot master user and never needs this,
// but webmail (Roundcube) requires the member to have a known password.
func (c *Client) SetPassword(ctx context.Context, localPart, domain, password string) error {
if !c.Configured() {
return fmt.Errorf("mailu not configured")
}
email := localPart + "@" + domain
resp, err := c.do(ctx, http.MethodPatch, "/user/"+email, map[string]any{"raw_password": password})
if err != nil {
return err
}
defer resp.Body.Close()
b, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
return nil
}
return fmt.Errorf("mailu set password %s: %s: %s", email, resp.Status, strings.TrimSpace(string(b)))
}
func randomPassword() (string, error) {
var b [24]byte
if _, err := rand.Read(b[:]); err != nil {

View file

@ -99,3 +99,26 @@ func TestEnsureUserUnconfigured(t *testing.T) {
t.Fatal("expected error when unconfigured")
}
}
func TestSetPassword(t *testing.T) {
var method, path string
var body map[string]any
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
method, path = r.Method, r.URL.Path
b, _ := io.ReadAll(r.Body)
_ = json.Unmarshal(b, &body)
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
c := New(Config{BaseURL: srv.URL, Token: "t"})
if err := c.SetPassword(context.Background(), "alice", "bbs.profullstack.com", "hunter2"); err != nil {
t.Fatal(err)
}
if method != http.MethodPatch || path != "/api/v1/user/alice@bbs.profullstack.com" {
t.Fatalf("got %s %s", method, path)
}
if body["raw_password"] != "hunter2" {
t.Fatalf("raw_password = %v", body["raw_password"])
}
}