feat: store Stalwart numeric account id on provider link#64
Open
jzunigax2 wants to merge 2 commits into
Open
Conversation
Stalwart telemetry webhooks identify mailboxes by the server's internal numeric account id, which provisioning never persisted. Capture the id returned by Account/set, decode it from Stalwart's custom base32 JMAP encoding, and store it on mail_provider_accounts so webhook events can be resolved to a user and network bucket with a single indexed lookup. - AccountProvider.createAccount now returns the decoded internal id - provider link creation moved after Stalwart account creation during provisioning (with undo on failure), so the id is known at insert time - new provider_internal_id column, NOT NULL, unique per provider among non-deleted rows Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The provider now self-describes the identifiers of the account it created: CreateAccountResult carries provider name, external id, and an opaque string internal id. AccountService no longer hardcodes 'stalwart' or assumes the external id equals the address, and the provider_internal_id column is a string so a future provider can use any id format. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
xabg2
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
Groundwork for per-message quota metadata in Bridge (follow-up to the discussion on internxt/bridge#220): Stalwart's
message-ingest.*webhook events identify mailboxes by Stalwart's internal numeric account id, which we never persisted — provisioning only stores the address string asexternal_id. Without this mapping, a webhook consumer cannot resolve events to a user/bucket.What
StalwartAccountProvider.createAccountnow uses the id already returned byAccount/set(previously discarded): decodes it from Stalwart's custom base32 JMAP encoding and returns it through theAccountProviderport.CreateAccountResultcarries{ provider, externalId, internalId }— the adapter self-describes how it identifies the account.AccountServiceno longer hardcodes'stalwart'or assumes the external id equals the address, and the internal id is an opaque string so a future provider can use any id format. All Stalwart specifics (base32 codec, principal-name semantics) stay insideinfrastructure/stalwart/.stalwart-id.codec.ts: decoder for Stalwart's base32 alphabet (abcdefghijklmnopqrstuvwxyz792013, matchingcrates/utils/src/codec/base32_custom.rsin the Stalwart source).mail_provider_accounts.provider_internal_id: newVARCHAR(255) NOT NULLcolumn, unique per(provider, provider_internal_id)among non-deleted rows. NOT NULL with no default is safe — no production data exists yet.addAddressgets the same undo coverage.Tests
stalwart-id.codec.spec.ts: alphabet vectors, positional decoding, error cases (empty, invalid char, overflow).319 tests passing.
🤖 Generated with Claude Code