MaskedEmail `emailDomain` rejected for accounts with addresses on more than one domain

Issue Description

Creating a masked address with emailDomain fails with forbidden / “The specified domain is not valid for this account.” for every domain, including the domain of the account’s own primary address, when the account has aliases on more than one domain.

Creating without emailDomain works and picks the primary address’s domain.

Reproduction Steps

  1. Account [email protected] with an alias [email protected] (both domains local).

  2. Logged in as that account:

    stalwart-cli create MaskedEmail --field emailDomain=example.com
    

    → forbidden, “The specified domain is not valid for this account.” Same for example.org.

  3. Without the field:

    stalwart-cli create MaskedEmail --field description=test
    

    → created on example.com.

Stalwart Version

v0.16.x

Installation Method

Binary (Linux)

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

crates/jmap/src/registry/mapping/masked_email.rs, around line 78:

.filter(|domain| {
    account
        .addresses
        .iter()
        .all(|addr| addr.domain_id == domain.id)
})

.all() requires every address on the account to be in the requested domain, so any account with addresses on two domains can never pass. The intent looks like “the account has an address on this domain”, which is .any():

        .any(|addr| addr.domain_id == domain.id)

The existing test in tests/src/system/delivery.rs only uses an account whose addresses are all on one domain, so it doesn’t catch this.

Separately (possibly intended)

Creating as an admin with --field accountId=<id> returns invalidForeignKey for a valid account id, so masked addresses can only be created by logging in as the owning account. If admins are meant to be able to create them for other accounts, that looks like a second bug.

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

This confirms the bug: in masked_email.rs the domain validity check uses .all() instead of .any(), so accounts with addresses spanning more than one domain will fail the check for every domain (since no domain can satisfy “all addresses belong to this domain” unless the account only has addresses on one domain). Your fix (.any()) matches the pattern used elsewhere in the codebase for the identical check, e.g. mta.rs’s any(|addr| addr.domain_id == domain.id), confirming the intended semantics are “does the account have an address in this domain.”

This is a genuine bug report rather than a documented/expected behavior, so I can’t point you to docs resolving it. Thanks for the detailed repro and code pointer, a human maintainer will need to review and confirm the fix (including the separate admin accountId creation issue you flagged).

This isn’t covered in the current docs. A community member or staff member will follow up.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

Fixed in v0.16.25 (yet to be released).