Skip to content

Commit c7a250d

Browse files
committed
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.
1 parent 2701c13 commit c7a250d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/imap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,8 @@ impl Imap {
13241324
// Fetch last DC_FETCH_EXISTING_MSGS_COUNT (100) messages.
13251325
// Sequence numbers are sequential. If there are 1000 messages in the inbox,
13261326
// we can fetch the sequence numbers 900-1000 and get the last 100 messages.
1327-
let first = cmp::max(1, exists - DC_FETCH_EXISTING_MSGS_COUNT);
1328-
let set = format!("{first}:*");
1327+
let first = cmp::max(1, exists - DC_FETCH_EXISTING_MSGS_COUNT + 1);
1328+
let set = format!("{first}:{exists}");
13291329
let mut list = session
13301330
.fetch(&set, PREFETCH_FLAGS)
13311331
.await

0 commit comments

Comments
 (0)