From d3236e79fd1d9a12ada5eee62a829905d61b56ea Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 8 May 2023 10:59:15 +0000 Subject: [PATCH] fix: fetch at most 100 existing messages even if EXISTS was not received According to RFC 3501, EXISTS must always be sent in response to SELECT. But if the server does not send it for some reason, async-imap uses the default value, so we will essentially fetch `1:*` and downloading all messages may take a long time. --- CHANGELOG.md | 1 + src/imap.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d834be66..586dbffe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ### Fixes - Make the bots automatically accept group chat contact requests. #4377 +- Fetch at most 100 existing messages even if EXISTS was not received. #4383 ### Fixes - jsonrpc: typescript client: fix types of events in event emitter diff --git a/src/imap.rs b/src/imap.rs index a82b45a0a..332e51545 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -1324,8 +1324,8 @@ impl Imap { // Fetch last DC_FETCH_EXISTING_MSGS_COUNT (100) messages. // Sequence numbers are sequential. If there are 1000 messages in the inbox, // we can fetch the sequence numbers 900-1000 and get the last 100 messages. - let first = cmp::max(1, exists - DC_FETCH_EXISTING_MSGS_COUNT); - let set = format!("{first}:*"); + let first = cmp::max(1, exists - DC_FETCH_EXISTING_MSGS_COUNT + 1); + let set = format!("{first}:{exists}"); let mut list = session .fetch(&set, PREFETCH_FLAGS) .await