From c1cb6eef08de1b737a6f5127b888b02c5a4e0ffa Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 23 Jul 2023 12:19:50 +0000 Subject: [PATCH 1/3] refactor: improve IMAP logs --- src/imap.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/imap.rs b/src/imap.rs index bb65c5e121..96740a0701 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -611,8 +611,7 @@ impl Imap { if uid_next < old_uid_next { warn!( context, - "The server illegally decreased the uid_next of folder {} from {} to {} without changing validity ({}), resyncing UIDs...", - folder, old_uid_next, uid_next, new_uid_validity, + "The server illegally decreased the uid_next of folder {folder:?} from {old_uid_next} to {uid_next} without changing validity ({new_uid_validity}), resyncing UIDs...", ); set_uid_next(context, folder, uid_next).await?; job::schedule_resync(context).await?; @@ -628,7 +627,7 @@ impl Imap { set_modseq(context, folder, 0).await?; if mailbox.exists == 0 { - info!(context, "Folder \"{}\" is empty.", folder); + info!(context, "Folder {folder:?} is empty."); // set uid_next=1 for empty folders. // If we do not do this here, we'll miss the first message @@ -646,7 +645,7 @@ impl Imap { None => { warn!( context, - "IMAP folder has no uid_next, fall back to fetching" + "IMAP folder {folder:?} has no uid_next, fall back to fetching." ); // note that we use fetch by sequence number // and thus we only need to get exactly the @@ -685,7 +684,7 @@ impl Imap { } info!( context, - "uid/validity change folder {}: new {}/{} previous {}/{}", + "uid/validity change folder {}: new {}/{} previous {}/{}.", folder, new_uid_next, new_uid_validity, @@ -706,17 +705,17 @@ impl Imap { fetch_existing_msgs: bool, ) -> Result { if should_ignore_folder(context, folder, folder_meaning).await? { - info!(context, "Not fetching from {}", folder); + info!(context, "Not fetching from {folder:?}."); return Ok(false); } let new_emails = self .select_with_uidvalidity(context, folder) .await - .with_context(|| format!("failed to select folder {folder}"))?; + .with_context(|| format!("Failed to select folder {folder:?}"))?; if !new_emails && !fetch_existing_msgs { - info!(context, "No new emails in folder {}", folder); + info!(context, "No new emails in folder {folder:?}."); return Ok(false); } @@ -742,7 +741,7 @@ impl Imap { let headers = match get_fetch_headers(fetch_response) { Ok(headers) => headers, Err(err) => { - warn!(context, "Failed to parse FETCH headers: {}", err); + warn!(context, "Failed to parse FETCH headers: {err:#}."); continue; } }; @@ -933,7 +932,7 @@ impl Imap { if let Some(folder) = context.get_config(config).await? { info!( context, - "Fetching existing messages from folder \"{}\"", folder + "Fetching existing messages from folder {folder:?}." ); self.fetch_new_messages(context, &folder, meaning, true) .await From b872953bc510840d2c7feb21c639083764bab3c0 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 23 Jul 2023 19:38:52 +0000 Subject: [PATCH 2/3] fix(deltachat-jsonrpc): make MessageObject.text non-optional This is already non-optional on the `deltachat` crate side since --- deltachat-jsonrpc/src/api/types/message.rs | 4 ++-- deltachat-rpc-client/tests/test_something.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/deltachat-jsonrpc/src/api/types/message.rs b/deltachat-jsonrpc/src/api/types/message.rs index 01a4333004..9e50d90eb4 100644 --- a/deltachat-jsonrpc/src/api/types/message.rs +++ b/deltachat-jsonrpc/src/api/types/message.rs @@ -34,7 +34,7 @@ pub struct MessageObject { quote: Option, parent_id: Option, - text: Option, + text: String, has_location: bool, has_html: bool, view_type: MessageViewtype, @@ -180,7 +180,7 @@ impl MessageObject { from_id: message.get_from_id().to_u32(), quote, parent_id, - text: Some(message.get_text()).filter(|s| !s.is_empty()), + text: message.get_text(), has_location: message.has_location(), has_html: message.has_html(), view_type: message.get_viewtype().into(), diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 72c8630f95..6c2351ecfe 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -101,6 +101,16 @@ async def test_account(acfactory) -> None: assert await alice.get_fresh_messages() assert await alice.get_next_messages() + # Test sending empty message. + assert len(await bob.wait_next_messages()) == 0 + await alice_chat_bob.send_text("") + messages = await bob.wait_next_messages() + assert len(messages) == 1 + message = messages[0] + snapshot = await message.get_snapshot() + assert snapshot.text == "" + await bob.mark_seen_messages([message]) + group = await alice.create_group("test group") await group.add_contact(alice_contact_bob) group_msg = await group.send_message(text="hello") From d52f2883cfac56a8b62ed539aaa3ff4774192200 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 24 Jul 2023 18:40:32 +0000 Subject: [PATCH 3/3] feat(deltachat-rpc-client): add MSG_DELETED constant --- deltachat-rpc-client/src/deltachat_rpc_client/const.py | 1 + 1 file changed, 1 insertion(+) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/const.py b/deltachat-rpc-client/src/deltachat_rpc_client/const.py index 3ca606617c..c17ca86373 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/const.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/const.py @@ -45,6 +45,7 @@ class EventType(str, Enum): MSG_DELIVERED = "MsgDelivered" MSG_FAILED = "MsgFailed" MSG_READ = "MsgRead" + MSG_DELETED = "MsgDeleted" CHAT_MODIFIED = "ChatModified" CHAT_EPHEMERAL_TIMER_MODIFIED = "ChatEphemeralTimerModified" CONTACTS_CHANGED = "ContactsChanged"