mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-27 05:04:23 +00:00
53 lines
1.5 KiB
Swift
53 lines
1.5 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2020 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 struct NIO.ByteBuffer
|
|
|
|
extension NIOIMAP {
|
|
|
|
public struct FetchModifier: Equatable {
|
|
public var name: String
|
|
public var value: TaggedExtensionValue?
|
|
|
|
public static func name(_ name: String, value: TaggedExtensionValue?) -> Self {
|
|
return Self(name: name, value: value)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Encoding
|
|
extension ByteBuffer {
|
|
|
|
@discardableResult mutating func writeFetchModifiers(_ array: [NIOIMAP.FetchModifier]) -> Int {
|
|
guard array.count > 0 else {
|
|
return 0
|
|
}
|
|
|
|
return
|
|
self.writeSpace() +
|
|
self.writeArray(array) { (param, self) -> Int in
|
|
self.writeFetchModifier(param)
|
|
}
|
|
}
|
|
|
|
@discardableResult mutating func writeFetchModifier(_ param: NIOIMAP.FetchModifier) -> Int {
|
|
self.writeFetchModifierName(param.name) +
|
|
self.writeIfExists(param.value) { (value) -> Int in
|
|
self.writeSpace() +
|
|
self.writeTaggedExtensionValue(value)
|
|
}
|
|
}
|
|
|
|
}
|