diff --git a/melib/src/jmap/mailbox.rs b/melib/src/jmap/mailbox.rs index f1fa022d..d885b78c 100644 --- a/melib/src/jmap/mailbox.rs +++ b/melib/src/jmap/mailbox.rs @@ -52,6 +52,14 @@ pub struct MailboxObject { impl Object for MailboxObject { const NAME: &'static str = "Mailbox"; + const SERVER_SET_FIELDS: &'static [&'static str] = &[ + "id", + "totalEmails", + "unreadEmails", + "unreadThreads", + "totalThreads", + "myRights", + ]; } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/melib/src/jmap/methods.rs b/melib/src/jmap/methods.rs index ccdb1ad4..34e049c3 100644 --- a/melib/src/jmap/methods.rs +++ b/melib/src/jmap/methods.rs @@ -605,6 +605,9 @@ impl Serialize for Set { let mut v = serde_json::json!(v); if let Some(ref mut obj) = v.as_object_mut() { obj.remove("id"); + for f in ::SERVER_SET_FIELDS { + obj.remove(*f); + } } (k, v) }) diff --git a/melib/src/jmap/objects.rs b/melib/src/jmap/objects.rs index 7e3aa577..0e23f3be 100644 --- a/melib/src/jmap/objects.rs +++ b/melib/src/jmap/objects.rs @@ -37,6 +37,7 @@ impl Object for PatchObject { pub trait Object: Send + Sync { const NAME: &'static str; + const SERVER_SET_FIELDS: &'static [&'static str] = &["id"]; } #[derive(Deserialize, Serialize)] diff --git a/melib/src/jmap/tests.rs b/melib/src/jmap/tests.rs index d7badc2e..c4ca5b49 100644 --- a/melib/src/jmap/tests.rs +++ b/melib/src/jmap/tests.rs @@ -698,3 +698,66 @@ fn test_jmap_session_serde() { .unwrap(), ); } + +#[test] +fn test_jmap_server_set_fields_in_set_create() { + use std::sync::Arc; + + use futures::lock::Mutex as FutureMutex; + use serde_json::json; + + use crate::jmap::{mailbox, methods::Set, objects::Id, protocol::Request}; + let account_id = "blahblah"; + let prev_seq = 33; + let mut req = Request::new(Arc::new(FutureMutex::new(prev_seq))); + let path = "new_mbox"; + + let mailbox_set_call = mailbox::MailboxSet::new( + Set::::new(None) + .account_id(account_id.into()) + .create(Some({ + let id: Id = path.into(); + indexmap! { + id.clone().into() => mailbox::MailboxObject { + id, + name: path.to_string(), + ..mailbox::MailboxObject::default() + } + } + })), + ); + futures::executor::block_on(req.add_call(&mailbox_set_call)); + + assert_eq!( + json! {&req}, + json! {{ + "methodCalls" : [ + [ + "Mailbox/set", + { + "accountId" : account_id, + "create" : { + "new_mbox": { + "isSubscribed": false, + "name": path, + "parentId": null, + "role": null, + "sortOrder": 0, + } + }, + "destroy" : null, + "ifInState" : null, + "onDestroyRemoveEmails": false, + "update" : null + }, + "m33" + ], + ], + "using" : [ + "urn:ietf:params:jmap:core", + "urn:ietf:params:jmap:mail", + "urn:ietf:params:jmap:submission" + ] + }}, + ); +}