melib/jmap: do not serialize server-set fields in Set create

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/458/head
Manos Pitsidianakis 3 months ago
parent e6877e89c2
commit 8481294147
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -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)]

@ -605,6 +605,9 @@ impl<OBJ: Object + Serialize + std::fmt::Debug> Serialize for Set<OBJ> {
let mut v = serde_json::json!(v);
if let Some(ref mut obj) = v.as_object_mut() {
obj.remove("id");
for f in <OBJ as Object>::SERVER_SET_FIELDS {
obj.remove(*f);
}
}
(k, v)
})

@ -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)]

@ -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::<mailbox::MailboxObject>::new(None)
.account_id(account_id.into())
.create(Some({
let id: Id<mailbox::MailboxObject> = 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"
]
}},
);
}

Loading…
Cancel
Save