mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-24 04:38:04 +00:00
39 lines
1.3 KiB
Swift
39 lines
1.3 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2026 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import NIOIMAP
|
|
|
|
// MARK: - Fixed `[UIDRange]` strategy
|
|
//
|
|
// Used when the caller passes `FetchQuery.uids(_)` to `makeBatches(...)` on a server
|
|
// without RFC 9394 `PARTIAL` support. The requested UIDs are split into ranges of
|
|
// at most `batchSize` UIDs each, preserving the UID ordering.
|
|
|
|
/// Splits the given UIDs into `UIDRange`s with at most `batchSize` UIDs each.
|
|
func splitUIDsIntoRanges(
|
|
uids: UIDSet,
|
|
batchSize: BatchSize
|
|
) -> [UIDRange] {
|
|
var ranges: [UIDRange] = []
|
|
var remaining = uids
|
|
while !remaining.isEmpty {
|
|
guard
|
|
let next = UIDSetNonEmpty(set: remaining.suffix(batchSize.count))
|
|
else { break }
|
|
ranges.append(next.min()...next.max())
|
|
remaining.subtract(UIDSet(next.min()...UID.max))
|
|
}
|
|
return ranges
|
|
}
|