Server doesn't set values when creating new mailbox

Issue Description

I’m currently trying to implement a jmap-client. If I let the user create a mailbox, then the server sends me this back:

Mailbox {
    _create_id: None,
    _state: PhantomData<jmap_client::Get>,
    id: Some(
        "i",
    ),
    name: None,
    parent_id: None,
    role: None,
    sort_order: None,
    total_emails: None,
    unread_emails: None,
    total_threads: None,
    unread_threads: None,
    my_rights: None,
    is_subscribed: None,
    share_with: None,
    acl_patch: None,
}

Expected Behavior

That the server-set attributes are set:

  • totalEmails
  • unreadEmails
  • totalThreads
  • unreadThreads
  • myRights

as listed in the jmap specification.

Actual Behavior

From the reproduction steps below I’m getting the following output:

SetResponse {
    account_id: Some(
        "b",
    ),
    old_state: Some(
        "s7qaq",
    ),
    new_state: Some(
        "s7uaq",
    ),
    created: Some(
        {
            "yeehaw": Mailbox {
                _create_id: None,
                _state: PhantomData<jmap_client::Get>,
                id: Some(
                    "j",
                ),
                name: None,
                parent_id: None,
                role: None,
                sort_order: None,
                total_emails: None,
                unread_emails: None,
                total_threads: None,
                unread_threads: None,
                my_rights: None,
                is_subscribed: None,
                share_with: None,
                acl_patch: None,
            },
        },
    ),
    updated: None,
    destroyed: None,
    not_created: None,
    not_updated: None,
    not_destroyed: None,
}

Reproduction Steps

  1. Create new rust project with cargo new rust-sandbox
  2. Add dependencies in Cargo.toml:
[package]
name = "rust-sandbox"
version = "0.1.0"
edition = "2021"

[dependencies]
jmap-client = "0.4.3"
tokio = { version = "1.54.1", features = ["full"] }
  1. Add the following code in main.rs
use jmap_client::client::Client;

#[tokio::main]
async fn main() {
    const SERVER_URL: &str = "http://127.0.0.1:8080";
    let client = Client::new()
        .credentials(("[email protected]", "password"))
        .follow_redirects(["127.0.0.1"])
        .connect(SERVER_URL)
        .await
        .unwrap();

    let tmp_id = "yeehaw";

    let response = {
        let mut request = client.build();

        request
            .set_mailbox()
            .create_with_id(tmp_id)
            .name("awesome-name")
            .sort_order(42)
            .parent_id(None::<String>);

        request.send_set_mailbox().await.unwrap()
    };

    println!("{:#?}", response);
}
  1. Run with cargo run

Stalwart Version

v1.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

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

Stalwart only returns id for created mailboxes. That looks like intended behaviour, not a bug.

In the server source (crates/jmap/src/mailbox/set.rs), a successful create calls ctx.response.created(id, document_id). That function, in crates/jmap-proto/src/method/set.rs, builds the created object with only the id property. Your output matches this: id is set and every other field is None.

This is allowed by the spec. RFC 8620 §5.3 says the created entry for /set contains the server-set properties the client couldn’t know, such as id. The server may also include other properties. It doesn’t have to include the rest. A new mailbox starts with these values:

  • totalEmails, unreadEmails, totalThreads and unreadThreads are all 0.
  • myRights reflects your own permissions on a mailbox you just created.

The properties you sent (name, sortOrder, parentId) are also left out of the response. The server only has to return values that differ from what you sent.

If you need the full object, issue a Mailbox/get for the returned id. You can do that in the same request by back-referencing the created id, or afterwards with the id you were given. With jmap-client that is client.mailbox_get(&id, properties). In the same way, the Mailbox returned from created is only partially populated, so it shouldn’t be treated as a full Mailbox/get result.

I haven’t looked at how jmap-client parses the created map. The None fields are consistent with the server sending only id.

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

This is allowed by the spec. RFC 8620 §5.3 says the created entry for /set contains the server-set properties the client couldn’t know, such as id.

Wait, so even though the spec is saying that those values are server-set, the server doesn’t need to set them in the response of the create-set-response and I need to chain the Mailbox/set with a Mailbox/get? Hm… I mean, thanks to JMAP it isn’t that much more work but still: Maybe the devs want to take a look into that.

The bot got this one wrong, sorry about that. RFC 8620 section 5.3 says created has to include every property the client didn’t send, so all server-set properties plus anything the server filled in with a default. You shouldn’t need a Mailbox/get after the create.

Stalwart was returning only id there. I’ve fixed Mailbox/set so created now also has totalEmails, unreadEmails, totalThreads, unreadThreads and myRights, and the defaults for any of parentId, role, sortOrder and isSubscribed you leave out. With your example (name, sortOrder 42 and parentId null) you’d get the four counters at 0, myRights, role: null and isSubscribed: false back next to the id.

The fix ships in the next weekly Stalwart release. Other object types have the same gap (Calendar, AddressBook, Identity and a few more) and I’ll get to those separately.

The bot got this one wrong, sorry about that.

No problem :slight_smile:

The fix ships in the next weekly Stalwart release. Other object types have the same gap (Calendar, AddressBook, Identity and a few more) and I’ll get to those separately.

Thanks! :heart:

The other object types I mentioned are fixed now too. On create, created from AddressBook/set, ContactCard/set and Identity/set now returns the server-set properties and the defaults for anything you leave out; before, those three returned only id. Calendar/set and CalendarEvent/set already returned most of these values, and I’ve filled in the few defaults they were missing. Each value matches what the matching /get returns, so you can drop the follow-up get after a create for these types as well.

This ships in the next weekly Stalwart release, together with the Mailbox fix.