From c875dda4960e5688b17176ba82ad1e5da38b883b Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 13 Aug 2023 14:29:00 +0300 Subject: [PATCH] melib/jmap: add last_method_response field to Connection For book keeping. Signed-off-by: Manos Pitsidianakis --- melib/src/jmap/connection.rs | 2 ++ melib/src/jmap/mod.rs | 4 ++-- melib/src/jmap/protocol.rs | 9 ++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/melib/src/jmap/connection.rs b/melib/src/jmap/connection.rs index 80845e5d..5ba81cce 100644 --- a/melib/src/jmap/connection.rs +++ b/melib/src/jmap/connection.rs @@ -33,6 +33,7 @@ pub struct JmapConnection { pub client: Arc, pub server_conf: JmapServerConf, pub store: Arc, + pub last_method_response: Option, } impl JmapConnection { @@ -73,6 +74,7 @@ impl JmapConnection { client: Arc::new(client), server_conf, store, + last_method_response: None, }) } diff --git a/melib/src/jmap/mod.rs b/melib/src/jmap/mod.rs index f74523c1..69925472 100644 --- a/melib/src/jmap/mod.rs +++ b/melib/src/jmap/mod.rs @@ -325,7 +325,7 @@ impl MailBackend for JmapType { let mut fetch_state = protocol::EmailFetchState::Start { batch_size }; loop { let res = fetch_state.fetch( - &conn, + &mut conn, &store, mailbox_hash, ).await?; @@ -383,7 +383,7 @@ impl MailBackend for JmapType { let mut conn = connection.lock().await; conn.connect().await?; if store.mailboxes.read().unwrap().is_empty() { - let new_mailboxes = debug!(protocol::get_mailboxes(&conn).await)?; + let new_mailboxes = debug!(protocol::get_mailboxes(&mut conn).await)?; *store.mailboxes.write().unwrap() = new_mailboxes; } diff --git a/melib/src/jmap/protocol.rs b/melib/src/jmap/protocol.rs index 2890741c..841d6559 100644 --- a/melib/src/jmap/protocol.rs +++ b/melib/src/jmap/protocol.rs @@ -78,7 +78,7 @@ impl Request { } } -pub async fn get_mailboxes(conn: &JmapConnection) -> Result> { +pub async fn get_mailboxes(conn: &mut JmapConnection) -> Result> { let seq = get_request_no!(conn.request_no); let res_text = conn .send_request(serde_json::to_string(&json!({ @@ -96,6 +96,7 @@ pub async fn get_mailboxes(conn: &JmapConnection) -> Result { list, account_id, .. } = m; + conn.last_method_response = Some(res_text); // Is account set as `personal`? (`isPersonal` property). Then, even if // `isSubscribed` is false on a mailbox, it should be regarded as // subscribed. @@ -167,7 +168,7 @@ pub async fn get_mailboxes(conn: &JmapConnection) -> Result Result>> { let email_call: EmailQuery = EmailQuery::new( @@ -198,6 +199,7 @@ pub async fn get_message_list( *conn.store.online_status.lock().await = (std::time::Instant::now(), Ok(())); let m = QueryResponse::::try_from(v.method_responses.remove(0))?; let QueryResponse:: { ids, .. } = m; + conn.last_method_response = Some(res_text); Ok(ids) } @@ -268,7 +270,7 @@ impl EmailFetchState { pub async fn fetch( &mut self, - conn: &JmapConnection, + conn: &mut JmapConnection, store: &Store, mailbox_hash: MailboxHash, ) -> Result> { @@ -325,6 +327,7 @@ impl EmailFetchState { let e = GetResponse::::try_from(v.method_responses.pop().unwrap())?; let GetResponse:: { list, state, .. } = e; + conn.last_method_response = Some(res_text); if self.must_update_state(conn, mailbox_hash, state).await? { *self = Self::Start { batch_size };