(when (nnimap-change-group group server)
(with-current-buffer (nnimap-buffer)
(erase-buffer)
- (let ((ranges (gnus-compress-sequence articles t))
- sequence)
- ;; If we have a lot of ranges, split them up to avoid
- ;; generating too-long lines. (The limit is 8192 octects,
- ;; and this should guarantee that it's (much) shorter than
- ;; that.)
- (while ranges
- (setq sequence
- (nnimap-send-command
- "UID FETCH %s %s"
- (nnimap-article-ranges
- (seq-take ranges nnimap--max-retrieve-headers))
- (nnimap-header-parameters)))
- (setq ranges (nthcdr nnimap--max-retrieve-headers ranges)))
- ;; Wait for the final one.
- (nnimap-wait-for-response sequence t))
+ ;; If we have a lot of ranges, split them up to avoid
+ ;; generating too-long lines. (The limit is 8192 octects,
+ ;; and this should guarantee that it's (much) shorter than
+ ;; that.) We don't stream the requests, since the server
+ ;; may respond to the requests out-of-order:
+ ;; https://datatracker.ietf.org/doc/html/rfc3501#section-5.5
+ (dolist (ranges (seq-split (gnus-compress-sequence articles t)
+ nnimap--max-retrieve-headers))
+ (nnimap-wait-for-response
+ (nnimap-send-command
+ "UID FETCH %s %s"
+ (nnimap-article-ranges ranges)
+ (nnimap-header-parameters))
+ t))
(unless (process-live-p (get-buffer-process (current-buffer)))
(error "IMAP server %S closed connection" nnimap-address))
(nnimap-transform-headers)