mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-27 05:04:23 +00:00
* Reject invalid URLAUTH mechanisms
`.resetKey(mailbox: .inbox, mechanisms: [.init("X\r\nA2 DELETE INBOX")])`
was written verbatim, injecting a command into RESETKEY / GENURLAUTH.
RFC 4467: `mechanism = "INTERNAL" / 1*(ALPHA / DIGIT / "-" / ".")`.
`init(_:)` becomes `init?(_:)`; literals trap on invalid input. The
parser already enforces the production.
* Reject invalid mailbox attributes
`MailboxInfo.Attribute("\\X)\r\n* BYE")` was written verbatim, injecting
an untagged response into LIST. It also feeds CREATE … USE via
`UseAttribute(_:)`.
RFC 3501: `mbx-list-flag` is `"\" atom` in every branch. `init(_:)`
becomes `init?(_:)`; literals trap on invalid input. Constants become
`static let` literals; storage is `let`. Fix the `String.init` doc,
which claimed lowercase storage.
* Reject invalid use attributes
`UseAttribute("\\All))\r\nA2 DELETE INBOX\r\nA3 NOOP ((")` was written
verbatim, injecting a command into CREATE … (USE (…)). It also feeds
`GmailLabel(useAttribute:)`.
RFC 6154: `use-attr-ext = "\" atom`. `init(_:)` becomes `init?(_:)`;
literals trap on invalid input. `init(_: MailboxInfo.Attribute)` stays
non-failable: same production. Fix docs that claimed lowercase storage.
* Reject invalid attribute flags
`AttributeFlag("x\" all 1\r\nA2 DELETE INBOX\r\nA3 NOOP \"")` was
written verbatim inside SEARCH MODSEQ "/flags/…", injecting a command.
RFC 7162: `attr-flag = "\\" atom / atom`, where `"\\"` is two literal
backslashes (the stored form is already escaped). `init(_:)` becomes
`init?(_:)`, validating after lowercasing; literals trap on invalid
input. Fix docs that claimed casing is preserved.
* Add FilterName for SEARCH FILTER
`.filter("x\r\nA2 DELETE INBOX")` was written verbatim, injecting a
command into SEARCH.
RFC 5466: `filter-name = 1*<any ATOM-CHAR except "/">`. New `FilterName`
type replaces the `String` payload of `SearchKey.filter`; `init?(_:)`
validates, literals trap on invalid input.
* Reject invalid compression kinds
`.compress(.init("DEFLATE\r\nA2 DELETE INBOX"))` was written verbatim,
injecting a command after COMPRESS.
RFC 4978: `algorithm = "DEFLATE"`, an atom. `init(_:)` becomes
`init?(_:)`, validating after uppercasing; literals trap on invalid
input. Add `String.init(_:)`.
* Reject invalid capabilities
`Capability("X\r\nA2 DELETE INBOX")` was written verbatim, injecting a
command into ENABLE, or (`"X\r\n* OK [ALERT] hi"`) a response into
CAPABILITY / ENABLED. Same for the kinds a capability is built from,
e.g. `.context(.init("X\r\n…"))`.
RFC 3501: `capability = ("AUTH=" auth-type) / atom`. `init(_:)` becomes
`init?(_:)` for `Capability` and each kind (kinds validate after
uppercasing); literals trap on invalid input. Storage is `let`. Add
`String.init(_:)` for the kinds.
* Add validated LIST option tag types
`.standard("X)\r\nA2 DELETE INBOX\r\nA3 LIST (")` was written verbatim,
injecting a command into LIST select/return options. Same for
`.vendor(KeyValue<String, String>)`.
RFC 5258: `option-standard-tag = atom`, `option-vendor-tag =
vendor-token "-" atom`. New `OptionExtensionKind.Standard` and
`.Vendor` replace the payloads; `init?(_:)` validates, literals trap.
`Vendor` stores `ACME-SORT` and derives `token` / `name`.
* Add CharacterSetName for SEARCH, SORT, and BADCHARSET
`.sort(…, charset: "UTF-8 ALL\r\nA2 DELETE INBOX\r\nA3 SEARCH", …)` was
written verbatim, injecting a command into SORT / SEARCH / ESEARCH.
`.badCharset(["a)] x\r\n* BYE"])` injected a response. Quoted names
also didn't round-trip: `"a b"` parsed, then encoded bare.
RFC 3501: `charset = atom / quoted`. New `CharacterSetName` replaces
`String`; valid = non-empty `TEXT-CHAR`. Written as an atom where it is
one (`CHARSET UTF-8` unchanged), quoted otherwise, never a literal. The
parser rejects quoted names it couldn't write back.
* Assert keyword validity when writing a flag keyword
`writeFlagKeyword` wrote verbatim with no check. `writeAtom` would be
wrong: Gmail keywords contain `]`, which no atom does. Assert the
keyword's own production instead; test that a `]` keyword encodes.
* Hoist a #require the compiler flagged as redundant
875 lines
38 KiB
Swift
875 lines
38 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2021 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
|
|
|
|
/// A capability advertised by a server to indicate supported functionality.
|
|
///
|
|
/// A server advertises its capabilities in response to a CAPABILITY command or automatically in greeting and
|
|
/// response codes. Each capability name indicates a feature or extension that the server supports. Clients must not assume
|
|
/// a capability is present unless explicitly advertised by the server.
|
|
///
|
|
/// Capabilities may be simple (like `STARTTLS`) or configurable (like `AUTH=GSSAPI`). Configurable capabilities
|
|
/// contain an equals sign separating the capability name from its configuration value. Use the name and value
|
|
/// properties to parse these components.
|
|
///
|
|
/// ### Example
|
|
///
|
|
/// ```
|
|
/// S: * CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI XPIG-LATIN
|
|
/// ```
|
|
///
|
|
/// The server response advertises capabilities: `IMAP4rev1` (simple), `STARTTLS` (simple), `AUTH=GSSAPI`
|
|
/// (configurable with name `AUTH` and value `GSSAPI`), and `XPIG-LATIN` (custom vendor extension).
|
|
///
|
|
/// ## Validity
|
|
///
|
|
/// A capability, and each of the kinds it is built from (such as ``ContextKind``), is written to
|
|
/// the wire verbatim, so anything that isn't an `atom` is rejected: `init(_:)` returns `nil`,
|
|
/// `init(stringLiteral:)` traps.
|
|
///
|
|
/// - SeeAlso: [RFC 3501 Section 7.2.1](https://datatracker.ietf.org/doc/html/rfc3501#section-7.2.1)
|
|
/// - SeeAlso: <doc:SupportedExtensions>
|
|
public struct Capability: Hashable, Sendable {
|
|
/// The raw string value of the capability.
|
|
let rawValue: String
|
|
private let splitIndex: String.Index?
|
|
|
|
/// The name of the capability. For simple capabilities such as `STARTTLS`, the value
|
|
/// will simply be `STARTTLS`. For configurable capabilities such as `AUTH=GSSAPI`, the value
|
|
/// will be `AUTH`.
|
|
public var name: String {
|
|
guard let index = self.splitIndex else {
|
|
return self.rawValue
|
|
}
|
|
return String(self.rawValue[..<index])
|
|
}
|
|
|
|
/// If the capability is _simple_, for example `STARTTLS`, the value is `nil`.
|
|
/// Otherwise, if the capability is configurable such as `AUTH=GSSAPI`, the value
|
|
/// is `GSSAPI`.
|
|
public var value: String? {
|
|
guard var index = self.splitIndex else {
|
|
return nil
|
|
}
|
|
index = self.rawValue.index(after: index)
|
|
|
|
return String(self.rawValue[index...])
|
|
}
|
|
|
|
/// Creates a capability from a `String`, if it is an `atom`, and parses any configuration if
|
|
/// present.
|
|
///
|
|
/// A string literal resolves to ``init(stringLiteral:)`` instead, which traps rather than
|
|
/// returning `nil`.
|
|
///
|
|
/// - parameter value: The raw `String` value of the capability, for example `STARTTLS` or `AUTH=GSSAPI`.
|
|
/// - returns: A new capability, or `nil` if `value` is not an `atom`.
|
|
public init?(_ value: String) {
|
|
guard Self.isValidCapability(value) else { return nil }
|
|
self.init(unchecked: value)
|
|
}
|
|
|
|
init(unchecked value: String) {
|
|
assert(Self.isValidCapability(value))
|
|
self.rawValue = value
|
|
self.splitIndex = self.rawValue.firstIndex(of: "=")
|
|
}
|
|
|
|
/// Whether the given string is a `capability`
|
|
/// ([RFC 3501 Section 9](https://datatracker.ietf.org/doc/html/rfc3501#section-9)):
|
|
/// ```
|
|
/// capability = ("AUTH=" auth-type) / atom
|
|
/// ```
|
|
/// `"AUTH=" auth-type` is itself an `atom`.
|
|
static func isValidCapability(_ string: String) -> Bool {
|
|
string.isIMAPAtom
|
|
}
|
|
}
|
|
|
|
// MARK: - Convenience Types
|
|
|
|
extension Capability {
|
|
/// Wraps the context type component of extended search and sort capabilities.
|
|
///
|
|
/// Context kinds indicate which protocol extension is being used for search operations. These are used in combination
|
|
/// with context(_:) to form capabilities like `CONTEXT=SEARCH` or `CONTEXT=SORT`.
|
|
///
|
|
/// - SeeAlso: [RFC 4731 ESEARCH Extension](https://datatracker.ietf.org/doc/html/rfc4731)
|
|
/// - SeeAlso: [RFC 5256 SORT Extension](https://datatracker.ietf.org/doc/html/rfc5256)
|
|
public struct ContextKind: Hashable, Sendable {
|
|
/// Extended search context (RFC 4731).
|
|
public static let search: Self = "SEARCH"
|
|
|
|
/// Extended sort context (RFC 5256).
|
|
public static let sort: Self = "SORT"
|
|
|
|
/// The raw string value of the context kind.
|
|
let rawValue: String
|
|
|
|
/// Creates a context kind from a string, if the uppercased string is an `atom`.
|
|
///
|
|
/// The provided value is uppercased for consistency with IMAP protocol conventions.
|
|
///
|
|
/// A string literal resolves to ``init(stringLiteral:)`` instead, which traps rather than
|
|
/// returning `nil`.
|
|
///
|
|
/// - parameter value: The context kind as a string (for example, SEARCH or SORT).
|
|
/// - returns: A new kind, or `nil` if the uppercased `value` is not an `atom`.
|
|
public init?(_ value: String) {
|
|
let normalized = value.uppercased()
|
|
guard normalized.isIMAPAtom else { return nil }
|
|
self.rawValue = normalized
|
|
}
|
|
|
|
/// Uppercases, like ``init(_:)``.
|
|
init(unchecked value: String) {
|
|
let normalized = value.uppercased()
|
|
assert(normalized.isIMAPAtom)
|
|
self.rawValue = normalized
|
|
}
|
|
}
|
|
|
|
/// Wraps sort algorithm variants supported by a `SORT` extension.
|
|
///
|
|
/// Sort kinds indicate specific sort capabilities. A server supporting `SORT=DISPLAY` supports
|
|
/// the `DISPLAYFROM` and `DISPLAYTO` sort criteria in addition to base `SORT` criteria.
|
|
///
|
|
/// - SeeAlso: [RFC 5256 SORT Extension](https://datatracker.ietf.org/doc/html/rfc5256)
|
|
public struct SortKind: Hashable, Sendable {
|
|
/// Display sort kind supporting DISPLAYFROM and DISPLAYTO criteria (RFC 5256).
|
|
public static let display: Self = "DISPLAY"
|
|
|
|
/// The raw string value of the sort kind.
|
|
let rawValue: String
|
|
|
|
/// Creates a sort kind from a string, if the uppercased string is an `atom`.
|
|
///
|
|
/// The provided value is uppercased for consistency with IMAP protocol conventions.
|
|
///
|
|
/// A string literal resolves to ``init(stringLiteral:)`` instead, which traps rather than
|
|
/// returning `nil`.
|
|
///
|
|
/// - parameter value: The sort kind as a string (for example, DISPLAY).
|
|
/// - returns: A new kind, or `nil` if the uppercased `value` is not an `atom`.
|
|
public init?(_ value: String) {
|
|
let normalized = value.uppercased()
|
|
guard normalized.isIMAPAtom else { return nil }
|
|
self.rawValue = normalized
|
|
}
|
|
|
|
/// Uppercases, like ``init(_:)``.
|
|
init(unchecked value: String) {
|
|
let normalized = value.uppercased()
|
|
assert(normalized.isIMAPAtom)
|
|
self.rawValue = normalized
|
|
}
|
|
}
|
|
|
|
/// Wraps thread algorithm variants supported by a `THREAD` extension.
|
|
///
|
|
/// Thread kinds specify the algorithm used to group related messages together. Different algorithms
|
|
/// use different criteria to establish parent-child relationships.
|
|
///
|
|
/// - SeeAlso: [RFC 5256 THREAD Extension](https://datatracker.ietf.org/doc/html/rfc5256)
|
|
public struct ThreadKind: Hashable, Sendable {
|
|
/// ORDEREDSUBJECT threading groups messages by base subject and date (RFC 5256).
|
|
public static let orderedSubject: Self = "ORDEREDSUBJECT"
|
|
|
|
/// REFERENCES threading groups messages by in-reply-to relationships (RFC 5256).
|
|
public static let references: Self = "REFERENCES"
|
|
|
|
/// The raw string value of the thread kind.
|
|
let rawValue: String
|
|
|
|
/// Creates a thread kind from a string, if the uppercased string is an `atom`.
|
|
///
|
|
/// The provided value is uppercased for consistency with IMAP protocol conventions.
|
|
///
|
|
/// A string literal resolves to ``init(stringLiteral:)`` instead, which traps rather than
|
|
/// returning `nil`.
|
|
///
|
|
/// - parameter value: The thread kind as a string (for example, ORDEREDSUBJECT or REFERENCES).
|
|
/// - returns: A new kind, or `nil` if the uppercased `value` is not an `atom`.
|
|
public init?(_ value: String) {
|
|
let normalized = value.uppercased()
|
|
guard normalized.isIMAPAtom else { return nil }
|
|
self.rawValue = normalized
|
|
}
|
|
|
|
/// Uppercases, like ``init(_:)``.
|
|
init(unchecked value: String) {
|
|
let normalized = value.uppercased()
|
|
assert(normalized.isIMAPAtom)
|
|
self.rawValue = normalized
|
|
}
|
|
}
|
|
|
|
/// Wraps additional `STATUS` response item types supported by a `STATUS` extension.
|
|
///
|
|
/// Status kinds specify which additional mailbox status attributes a server can provide beyond
|
|
/// the base RFC 3501 `MESSAGES`, `RECENT`, `UIDNEXT`, `UIDVALIDITY`, and `UNSEEN` attributes.
|
|
///
|
|
/// - SeeAlso: [RFC 8438 Status Response Extension](https://datatracker.ietf.org/doc/html/rfc8438)
|
|
public struct StatusKind: Hashable, Sendable {
|
|
/// SIZE status kind allows retrieving total mailbox storage size (RFC 8438).
|
|
public static let size: Self = "SIZE"
|
|
|
|
/// The raw string value of the status kind.
|
|
let rawValue: String
|
|
|
|
/// Creates a status kind from a string, if the uppercased string is an `atom`.
|
|
///
|
|
/// The provided value is uppercased for consistency with IMAP protocol conventions.
|
|
///
|
|
/// A string literal resolves to ``init(stringLiteral:)`` instead, which traps rather than
|
|
/// returning `nil`.
|
|
///
|
|
/// - parameter value: The status kind as a string (for example, SIZE).
|
|
/// - returns: A new kind, or `nil` if the uppercased `value` is not an `atom`.
|
|
public init?(_ value: String) {
|
|
let normalized = value.uppercased()
|
|
guard normalized.isIMAPAtom else { return nil }
|
|
self.rawValue = normalized
|
|
}
|
|
|
|
/// Uppercases, like ``init(_:)``.
|
|
init(unchecked value: String) {
|
|
let normalized = value.uppercased()
|
|
assert(normalized.isIMAPAtom)
|
|
self.rawValue = normalized
|
|
}
|
|
}
|
|
|
|
/// Wraps UTF-8 encoding support variants.
|
|
///
|
|
/// UTF-8 kinds specify the level of UTF-8 support offered by the server. When a client enables
|
|
/// a UTF-8 capability, it informs the server that it will send and can receive UTF-8-encoded
|
|
/// strings instead of modified UTF-7 encoding.
|
|
///
|
|
/// - SeeAlso: [RFC 6855 IMAP Support for UTF-8](https://datatracker.ietf.org/doc/html/rfc6855)
|
|
public struct UTF8Kind: Hashable, Sendable {
|
|
/// ACCEPT UTF-8 kind allows server to send UTF-8-encoded strings (RFC 6855).
|
|
public static let accept: Self = "ACCEPT"
|
|
|
|
/// The raw string value of the UTF-8 kind.
|
|
let rawValue: String
|
|
|
|
/// Creates a UTF-8 kind from a string, if the uppercased string is an `atom`.
|
|
///
|
|
/// The provided value is uppercased for consistency with IMAP protocol conventions.
|
|
///
|
|
/// A string literal resolves to ``init(stringLiteral:)`` instead, which traps rather than
|
|
/// returning `nil`.
|
|
///
|
|
/// - parameter value: The UTF-8 kind as a string (for example, ACCEPT).
|
|
/// - returns: A new kind, or `nil` if the uppercased `value` is not an `atom`.
|
|
public init?(_ value: String) {
|
|
let normalized = value.uppercased()
|
|
guard normalized.isIMAPAtom else { return nil }
|
|
self.rawValue = normalized
|
|
}
|
|
|
|
/// Uppercases, like ``init(_:)``.
|
|
init(unchecked value: String) {
|
|
let normalized = value.uppercased()
|
|
assert(normalized.isIMAPAtom)
|
|
self.rawValue = normalized
|
|
}
|
|
}
|
|
|
|
/// Wraps access control right sets supported by the `ACL` extension.
|
|
///
|
|
/// Rights kinds specify permission sets for mailbox access control lists. Each rights code is
|
|
/// a combination of letter codes representing different allowed operations.
|
|
///
|
|
/// - SeeAlso: [RFC 4314 Section 4 ACL Extension](https://datatracker.ietf.org/doc/html/rfc4314#section-4)
|
|
public struct RightsKind: Hashable, Sendable {
|
|
/// TEKX rights kind represents a common permission set (RFC 4314).
|
|
public static let tekx: Self = "TEKX"
|
|
|
|
/// The raw string value of the rights kind.
|
|
let rawValue: String
|
|
|
|
/// Creates a rights kind from a string, if the uppercased string is an `atom`.
|
|
///
|
|
/// The provided value is uppercased for consistency with IMAP protocol conventions.
|
|
///
|
|
/// A string literal resolves to ``init(stringLiteral:)`` instead, which traps rather than
|
|
/// returning `nil`.
|
|
///
|
|
/// - parameter value: The rights kind as a string (for example, TEKX).
|
|
/// - returns: A new kind, or `nil` if the uppercased `value` is not an `atom`.
|
|
public init?(_ value: String) {
|
|
let normalized = value.uppercased()
|
|
guard normalized.isIMAPAtom else { return nil }
|
|
self.rawValue = normalized
|
|
}
|
|
|
|
/// Uppercases, like ``init(_:)``.
|
|
init(unchecked value: String) {
|
|
let normalized = value.uppercased()
|
|
assert(normalized.isIMAPAtom)
|
|
self.rawValue = normalized
|
|
}
|
|
}
|
|
|
|
/// Wraps compression algorithm support types.
|
|
///
|
|
/// Compression kinds indicate the compression algorithms supported by a server's `COMPRESS` extension.
|
|
/// Clients can enable compression to reduce bandwidth usage on the connection.
|
|
///
|
|
/// - SeeAlso: [RFC 4978 IMAP Compression](https://datatracker.ietf.org/doc/html/rfc4978)
|
|
public struct CompressionKind: Hashable, Sendable {
|
|
/// DEFLATE compression algorithm (RFC 1951).
|
|
public static let deflate: Self = "DEFLATE"
|
|
|
|
/// The raw string value of the compression kind.
|
|
let rawValue: String
|
|
|
|
/// Creates a compression kind from a string, if the uppercased string is an `atom`.
|
|
///
|
|
/// The provided value is uppercased for consistency with IMAP protocol conventions.
|
|
///
|
|
/// A string literal resolves to ``init(stringLiteral:)`` instead, which traps rather than
|
|
/// returning `nil`.
|
|
///
|
|
/// - parameter value: The compression kind as a string (for example, DEFLATE).
|
|
/// - returns: A new kind, or `nil` if the uppercased `value` is not an `atom`.
|
|
public init?(_ value: String) {
|
|
let normalized = value.uppercased()
|
|
guard normalized.isIMAPAtom else { return nil }
|
|
self.rawValue = normalized
|
|
}
|
|
|
|
/// Uppercases, like ``init(_:)``.
|
|
init(unchecked value: String) {
|
|
let normalized = value.uppercased()
|
|
assert(normalized.isIMAPAtom)
|
|
self.rawValue = normalized
|
|
}
|
|
}
|
|
|
|
/// The `ACL` capability indicates the server supports access control lists for mailbox permissions.
|
|
///
|
|
/// - SeeAlso: [RFC 2086](https://datatracker.ietf.org/doc/html/rfc2086)
|
|
public static let acl = Self(unchecked: "ACL")
|
|
|
|
/// The `ANNOTATE-EXPERIMENT-1` capability indicates experimental support for message annotations and metadata.
|
|
///
|
|
/// - SeeAlso: [RFC 5257](https://datatracker.ietf.org/doc/html/rfc5257)
|
|
public static let annotateExperiment1 = Self(unchecked: "ANNOTATE-EXPERIMENT-1")
|
|
|
|
/// The `BINARY` capability indicates the server supports sending binary message data without encoding.
|
|
///
|
|
/// - SeeAlso: [RFC 3516](https://datatracker.ietf.org/doc/html/rfc3516)
|
|
public static let binary = Self(unchecked: "BINARY")
|
|
|
|
/// The `CATENATE` capability indicates the server supports creating messages by combining new and existing message data.
|
|
///
|
|
/// - SeeAlso: [RFC 4469](https://datatracker.ietf.org/doc/html/rfc4469)
|
|
public static let catenate = Self(unchecked: "CATENATE")
|
|
|
|
/// The `CHILDREN` capability indicates the server can determine whether a mailbox has children without listing them.
|
|
///
|
|
/// - SeeAlso: [RFC 3348](https://datatracker.ietf.org/doc/html/rfc3348)
|
|
public static let children = Self(unchecked: "CHILDREN")
|
|
|
|
/// The `CONDSTORE` capability indicates the server maintains modification sequence values for tracking changes.
|
|
///
|
|
/// - SeeAlso: [RFC 7162](https://datatracker.ietf.org/doc/html/rfc7162)
|
|
/// - SeeAlso: ``qresync``
|
|
public static let condStore = Self(unchecked: "CONDSTORE")
|
|
|
|
/// The `CREATE-SPECIAL-USE` capability indicates the server supports creating mailboxes with special-use attributes.
|
|
///
|
|
/// - SeeAlso: [RFC 6154](https://datatracker.ietf.org/doc/html/rfc6154)
|
|
/// - SeeAlso: ``specialUse``
|
|
public static let createSpecialUse = Self(unchecked: "CREATE-SPECIAL-USE")
|
|
|
|
/// The `ENABLE` capability indicates the server supports the `ENABLE` command for capability negotiation.
|
|
///
|
|
/// - SeeAlso: [RFC 5161](https://datatracker.ietf.org/doc/html/rfc5161)
|
|
public static let enable = Self(unchecked: "ENABLE")
|
|
|
|
/// The `ESEARCH` capability indicates the server supports the ESEARCH command (RFC 4731).
|
|
///
|
|
/// This capability indicates server support for the `SEARCH` command with extended result options
|
|
/// (like `RETURN (MIN MAX COUNT ALL)`), as defined in RFC 4731. Note: This capability is **not**
|
|
/// about the ESEARCH response format itself. The `ESEARCH` response format can be returned by
|
|
/// RFC 7377 MULTIMAILBOX SEARCH commands even without this capability.
|
|
///
|
|
/// - SeeAlso: [RFC 4731](https://datatracker.ietf.org/doc/html/rfc4731) - ESEARCH Command Extension
|
|
/// - SeeAlso: [RFC 7377](https://datatracker.ietf.org/doc/html/rfc7377) - MULTIMAILBOX SEARCH (may return `ESEARCH` responses without requiring this capability)
|
|
public static let extendedSearch = Self(unchecked: "ESEARCH")
|
|
|
|
/// The `ESORT` capability indicates the server supports extended sort result forms.
|
|
///
|
|
/// - SeeAlso: [RFC 7377](https://datatracker.ietf.org/doc/html/rfc7377)
|
|
public static let esort = Self(unchecked: "ESORT")
|
|
|
|
/// The `FILTERS` capability indicates the server supports persistent server-side searches.
|
|
///
|
|
/// - SeeAlso: [RFC 5466](https://datatracker.ietf.org/doc/html/rfc5466)
|
|
public static let filters = Self(unchecked: "FILTERS")
|
|
|
|
/// The `ID` capability indicates the server supports the ID command for exchanging implementation information.
|
|
///
|
|
/// - SeeAlso: [RFC 2971](https://datatracker.ietf.org/doc/html/rfc2971)
|
|
public static let id = Self(unchecked: "ID")
|
|
|
|
/// The `IDLE` capability indicates the server supports the `IDLE` command for real-time message notifications.
|
|
///
|
|
/// - SeeAlso: [RFC 2177](https://datatracker.ietf.org/doc/html/rfc2177)
|
|
public static let idle = Self(unchecked: "IDLE")
|
|
|
|
/// The `IMAP4rev1` capability indicates the server implements IMAP protocol version 4 revision 1.
|
|
///
|
|
/// - SeeAlso: [RFC 3501](https://datatracker.ietf.org/doc/html/rfc3501)
|
|
public static let imap4rev1 = Self(unchecked: "IMAP4rev1")
|
|
|
|
/// The `IMAP4` capability is a legacy identifier that servers may advertise. Use `IMAP4rev1` instead.
|
|
///
|
|
/// - SeeAlso: [RFC 3501](https://datatracker.ietf.org/doc/html/rfc3501)
|
|
public static let imap4 = Self(unchecked: "IMAP4")
|
|
|
|
/// The `JMAPACCESS` capability indicates the server provides access to JMAP resources via IMAP.
|
|
///
|
|
/// - SeeAlso: [RFC 9698](https://datatracker.ietf.org/doc/html/rfc9698)
|
|
public static let jmapAccess = Self(unchecked: "JMAPACCESS")
|
|
|
|
/// The `LANGUAGE` capability indicates the server supports the LANGUAGE command for selecting response language.
|
|
///
|
|
/// - SeeAlso: [RFC 5255](https://datatracker.ietf.org/doc/html/rfc5255)
|
|
public static let language = Self(unchecked: "LANGUAGE")
|
|
|
|
/// The `LIST-STATUS` capability indicates the server supports returning mailbox status in LIST responses.
|
|
///
|
|
/// - SeeAlso: [RFC 5819](https://datatracker.ietf.org/doc/html/rfc5819)
|
|
public static let listStatus = Self(unchecked: "LIST-STATUS")
|
|
|
|
/// The `LIST-EXTENDED` capability indicates the server supports the extended LIST command with additional options.
|
|
///
|
|
/// - SeeAlso: [RFC 5258](https://datatracker.ietf.org/doc/html/rfc5258)
|
|
public static let listExtended = Self(unchecked: "LIST-EXTENDED")
|
|
|
|
/// The `LOGINDISABLED` capability indicates the server does not support the LOGIN command (use AUTHENTICATE instead).
|
|
///
|
|
/// - SeeAlso: [RFC 3501](https://datatracker.ietf.org/doc/html/rfc3501)
|
|
public static let loginDisabled = Self(unchecked: "LOGINDISABLED")
|
|
|
|
/// The `LOGIN-REFERRALS` capability indicates the server may redirect clients to an alternate IMAP server.
|
|
///
|
|
/// - SeeAlso: [RFC 2221](https://datatracker.ietf.org/doc/html/rfc2221)
|
|
public static let loginReferrals = Self(unchecked: "LOGIN-REFERRALS")
|
|
|
|
/// The `APPENDLIMIT` capability advertises the maximum size of messages that can be appended to the mailbox.
|
|
///
|
|
/// - SeeAlso: [RFC 7889](https://datatracker.ietf.org/doc/html/rfc7889)
|
|
/// - SeeAlso: ``appendLimit(_:)``
|
|
public static let mailboxSpecificAppendLimit = Self(unchecked: "APPENDLIMIT")
|
|
|
|
/// The `METADATA` capability indicates the server supports storing and retrieving user and server annotations.
|
|
///
|
|
/// - SeeAlso: [RFC 5464](https://datatracker.ietf.org/doc/html/rfc5464)
|
|
/// - SeeAlso: ``metadataServer``
|
|
public static let metadata = Self(unchecked: "METADATA")
|
|
|
|
/// The `METADATA-SERVER` capability indicates the server supports server-level (not per-mailbox) annotations.
|
|
///
|
|
/// - SeeAlso: [RFC 5464](https://datatracker.ietf.org/doc/html/rfc5464)
|
|
/// - SeeAlso: ``metadata``
|
|
public static let metadataServer = Self(unchecked: "METADATA-SERVER")
|
|
|
|
/// The `MOVE` capability indicates the server supports the `MOVE` command for atomic message relocation.
|
|
///
|
|
/// - SeeAlso: [RFC 6851](https://datatracker.ietf.org/doc/html/rfc6851)
|
|
public static let move = Self(unchecked: "MOVE")
|
|
|
|
/// The `MULTISEARCH` capability indicates the server supports searching across multiple mailboxes in one command.
|
|
///
|
|
/// - SeeAlso: [RFC 7377](https://datatracker.ietf.org/doc/html/rfc7377)
|
|
public static let multiSearch = Self(unchecked: "MULTISEARCH")
|
|
|
|
/// The `NAMESPACE` capability indicates the server supports the `NAMESPACE` command for accessing multiple mailbox namespaces.
|
|
///
|
|
/// - SeeAlso: [RFC 2342](https://datatracker.ietf.org/doc/html/rfc2342)
|
|
public static let namespace = Self(unchecked: "NAMESPACE")
|
|
|
|
/// The `OBJECTID` capability indicates the server supports object identifiers for messages and mailboxes.
|
|
///
|
|
/// - SeeAlso: [RFC 8474](https://datatracker.ietf.org/doc/html/rfc8474)
|
|
public static let objectID = Self(unchecked: "OBJECTID")
|
|
|
|
/// The `OBJECTID+` capability indicates the server supports the compound `OBJECTID` response
|
|
/// format, the `ACCOUNTID` identifier, and identifier-based mailbox selection.
|
|
///
|
|
/// `OBJECTID+` obsoletes ``objectID`` (RFC 8474), though a server may advertise both for
|
|
/// backward compatibility.
|
|
///
|
|
/// - SeeAlso: `draft-ietf-mailmaint-imap-objectid-bis`
|
|
public static let objectIDPlus = Self(unchecked: "OBJECTID+")
|
|
|
|
/// The `QRESYNC` capability indicates the server supports quick resynchronization for mailbox reconciliation.
|
|
///
|
|
/// - SeeAlso: [RFC 7162](https://datatracker.ietf.org/doc/html/rfc7162)
|
|
/// - SeeAlso: ``condStore``
|
|
public static let qresync = Self(unchecked: "QRESYNC")
|
|
|
|
/// The `QUOTA` capability indicates the server supports resource quota management for mailboxes.
|
|
///
|
|
/// - SeeAlso: [RFC 2087](https://datatracker.ietf.org/doc/html/rfc2087)
|
|
public static let quota = Self(unchecked: "QUOTA")
|
|
|
|
/// The `SASL-IR` capability indicates the server supports initial response data with the `AUTHENTICATE` command.
|
|
///
|
|
/// - SeeAlso: [RFC 4959](https://datatracker.ietf.org/doc/html/rfc4959)
|
|
public static let saslIR = Self(unchecked: "SASL-IR")
|
|
|
|
/// The `SEARCHRES` capability indicates the server supports the `$` reference to the last search result.
|
|
///
|
|
/// - SeeAlso: [RFC 5182](https://datatracker.ietf.org/doc/html/rfc5182)
|
|
public static let searchRes = Self(unchecked: "SEARCHRES")
|
|
|
|
/// The `SPECIAL-USE` capability indicates the server supports special-use mailbox attributes like Drafts and Sent.
|
|
///
|
|
/// - SeeAlso: [RFC 6154](https://datatracker.ietf.org/doc/html/rfc6154)
|
|
/// - SeeAlso: ``createSpecialUse``
|
|
public static let specialUse = Self(unchecked: "SPECIAL-USE")
|
|
|
|
/// The `STARTTLS` capability indicates the server supports the `STARTTLS` command to upgrade to an encrypted connection.
|
|
///
|
|
/// - SeeAlso: [RFC 3501](https://datatracker.ietf.org/doc/html/rfc3501)
|
|
public static let startTLS = Self(unchecked: "STARTTLS")
|
|
|
|
/// The `UIDPLUS` capability indicates the server supports UIDPLUS extensions for UID responses and UID EXPUNGE.
|
|
///
|
|
/// - SeeAlso: [RFC 4315](https://datatracker.ietf.org/doc/html/rfc4315)
|
|
public static let uidPlus = Self(unchecked: "UIDPLUS")
|
|
|
|
/// The `UIDBATCHES` capability indicates the server supports partitioning messages into evenly-sized UID batches.
|
|
///
|
|
/// - SeeAlso: [RFC 10022](https://datatracker.ietf.org/doc/html/rfc10022)
|
|
public static let uidBatches = Self(unchecked: "UIDBATCHES")
|
|
|
|
/// The `UNSELECT` capability indicates the server supports the `UNSELECT` command to close without expunging.
|
|
///
|
|
/// - SeeAlso: [RFC 3691](https://datatracker.ietf.org/doc/html/rfc3691)
|
|
public static let unselect = Self(unchecked: "UNSELECT")
|
|
|
|
/// The `URL-PARTIAL` capability indicates the server supports partial IMAP URLs in `CATENATE` and `URLAUTH` extensions.
|
|
///
|
|
/// - SeeAlso: [RFC 5092](https://datatracker.ietf.org/doc/html/rfc5092)
|
|
public static let partialURL = Self(unchecked: "URL-PARTIAL")
|
|
|
|
/// The `PARTIAL` capability indicates the server supports paged `SEARCH` and `FETCH` results.
|
|
///
|
|
/// - SeeAlso: [RFC 9394](https://datatracker.ietf.org/doc/html/rfc9394)
|
|
public static let partial = Self(unchecked: "PARTIAL")
|
|
|
|
/// The `URLAUTH` capability indicates the server supports IMAP URLs with authorization data.
|
|
///
|
|
/// - SeeAlso: [RFC 4467](https://datatracker.ietf.org/doc/html/rfc4467)
|
|
public static let authenticatedURL = Self(unchecked: "URLAUTH")
|
|
|
|
/// The `WITHIN` capability indicates the server supports the `OLDER` and `YOUNGER` search criteria.
|
|
///
|
|
/// - SeeAlso: [RFC 5032](https://datatracker.ietf.org/doc/html/rfc5032)
|
|
public static let within = Self(unchecked: "WITHIN")
|
|
|
|
/// The `X-GM-EXT-1` capability indicates the server supports Gmail-specific IMAP extensions.
|
|
///
|
|
/// - SeeAlso: [Gmail IMAP Extensions](https://developers.google.com/gmail/imap/imap-extensions)
|
|
public static let gmailExtensions = Self(unchecked: "X-GM-EXT-1")
|
|
|
|
/// The `XYMHIGHESTMODSEQ` capability indicates the server tracks the highest modification sequence for Yahoo Mail.
|
|
///
|
|
/// - SeeAlso: [Yahoo Mail IMAP](https://help.yahoo.com/kb/SLN6556.html)
|
|
public static let yahooMailHighestModificationSequence = Self(unchecked: "XYMHIGHESTMODSEQ")
|
|
|
|
/// The `LITERAL+` capability indicates the server supports non-synchronizing literals for efficient transmission.
|
|
///
|
|
/// - SeeAlso: [RFC 7888](https://datatracker.ietf.org/doc/html/rfc7888)
|
|
/// - SeeAlso: ``literalMinus``
|
|
public static let literalPlus = Self(unchecked: "LITERAL+")
|
|
|
|
/// The `LITERAL-` capability indicates the server supports literal minus for selective synchronizing.
|
|
///
|
|
/// - SeeAlso: [RFC 7888](https://datatracker.ietf.org/doc/html/rfc7888)
|
|
/// - SeeAlso: ``literalPlus``
|
|
public static let literalMinus = Self(unchecked: "LITERAL-")
|
|
|
|
/// The `PREVIEW` capability indicates the server can generate server-side message preview text.
|
|
///
|
|
/// - SeeAlso: [RFC 8970](https://datatracker.ietf.org/doc/html/rfc8970)
|
|
public static let preview = Self(unchecked: "PREVIEW")
|
|
|
|
/// The `UIDONLY` capability indicates the server does not return message sequence numbers when enabled.
|
|
///
|
|
/// - SeeAlso: [RFC 9586](https://datatracker.ietf.org/doc/html/rfc9586)
|
|
/// - SeeAlso: ``saveLimit(_:)``
|
|
public static let uidOnly = Self(unchecked: "UIDONLY")
|
|
|
|
/// Creates an `APPENDLIMIT=<count>` capability advertising the maximum message size for the mailbox.
|
|
///
|
|
/// - SeeAlso: [RFC 7889](https://datatracker.ietf.org/doc/html/rfc7889)
|
|
public static func appendLimit(_ count: Int) -> Self {
|
|
Self(unchecked: "APPENDLIMIT=\(count)")
|
|
}
|
|
|
|
/// Creates a `MESSAGELIMIT=<count>` capability advertising the maximum message count for operations.
|
|
///
|
|
/// - SeeAlso: [RFC 9738](https://datatracker.ietf.org/doc/html/rfc9738)
|
|
public static func messageLimit(_ count: Int) -> Self {
|
|
Self(unchecked: "MESSAGELIMIT=\(count)")
|
|
}
|
|
|
|
/// Creates a `SAVELIMIT=<count>` capability advertising the maximum message count for SAVE operations.
|
|
///
|
|
/// - SeeAlso: [RFC 9586](https://datatracker.ietf.org/doc/html/rfc9586)
|
|
/// - SeeAlso: ``uidOnly``
|
|
public static func saveLimit(_ count: Int) -> Self {
|
|
Self(unchecked: "SAVELIMIT=\(count)")
|
|
}
|
|
|
|
/// Creates an `AUTH=<mechanism>` capability for the specified SASL mechanism.
|
|
///
|
|
/// - SeeAlso: [RFC 4959](https://datatracker.ietf.org/doc/html/rfc4959)
|
|
public static func authenticate(_ type: AuthenticationMechanism) -> Self {
|
|
Self(unchecked: "AUTH=\(String(type))")
|
|
}
|
|
|
|
/// Creates a `CONTEXT=<kind>` capability for the specified search or sort context.
|
|
///
|
|
/// - SeeAlso: [RFC 4731](https://datatracker.ietf.org/doc/html/rfc4731)
|
|
public static func context(_ type: ContextKind) -> Self {
|
|
Self(unchecked: "CONTEXT=\(type.rawValue)")
|
|
}
|
|
|
|
/// Creates a `SORT` or `SORT=<kind>` capability for the specified sort algorithm.
|
|
///
|
|
/// - SeeAlso: [RFC 5256](https://datatracker.ietf.org/doc/html/rfc5256)
|
|
public static func sort(_ type: SortKind?) -> Self {
|
|
guard let type = type else {
|
|
return Self(unchecked: "SORT")
|
|
}
|
|
return Self(unchecked: "SORT=\(type.rawValue)")
|
|
}
|
|
|
|
/// Creates a `UTF8=<kind>` capability for the specified UTF-8 support level.
|
|
///
|
|
/// - SeeAlso: [RFC 6855](https://datatracker.ietf.org/doc/html/rfc6855)
|
|
public static func utf8(_ type: UTF8Kind) -> Self {
|
|
Self(unchecked: "UTF8=\(type.rawValue)")
|
|
}
|
|
|
|
/// Creates a `THREAD=<kind>` capability for the specified threading algorithm.
|
|
///
|
|
/// - SeeAlso: [RFC 5256](https://datatracker.ietf.org/doc/html/rfc5256)
|
|
public static func thread(_ type: ThreadKind) -> Self {
|
|
Self(unchecked: "THREAD=\(type.rawValue)")
|
|
}
|
|
|
|
/// Creates a `STATUS=<kind>` capability for the specified status attribute type.
|
|
///
|
|
/// - SeeAlso: [RFC 8438](https://datatracker.ietf.org/doc/html/rfc8438)
|
|
public static func status(_ type: StatusKind) -> Self {
|
|
Self(unchecked: "STATUS=\(type.rawValue)")
|
|
}
|
|
|
|
/// Creates a `RIGHTS=<kind>` capability for the specified access control right set.
|
|
///
|
|
/// - SeeAlso: [RFC 4314](https://datatracker.ietf.org/doc/html/rfc4314)
|
|
public static func rights(_ type: RightsKind) -> Self {
|
|
Self(unchecked: "RIGHTS=\(type.rawValue)")
|
|
}
|
|
|
|
/// Creates a `COMPRESS=<kind>` capability for the specified compression algorithm.
|
|
///
|
|
/// - SeeAlso: [RFC 4978](https://datatracker.ietf.org/doc/html/rfc4978)
|
|
public static func compression(_ type: CompressionKind) -> Self {
|
|
Self(unchecked: "COMPRESS=\(type.rawValue)")
|
|
}
|
|
}
|
|
|
|
// MARK: - Capability to String conversion
|
|
|
|
extension Capability: ExpressibleByStringLiteral {
|
|
/// Creates a capability from a string literal.
|
|
///
|
|
/// A literal is written by the programmer, so an invalid one is a bug to be caught on first
|
|
/// run rather than handled. Use ``init(_:)`` for anything else.
|
|
///
|
|
/// - parameter value: The string literal.
|
|
/// - Precondition: `value` is an `atom`; this traps if it isn't.
|
|
public init(stringLiteral value: String) {
|
|
precondition(Self.isValidCapability(value), "Invalid capability: \(String(reflecting: value))")
|
|
self.init(unchecked: value)
|
|
}
|
|
}
|
|
|
|
extension Capability.ContextKind: ExpressibleByStringLiteral {
|
|
/// Creates a context kind from a string literal, uppercased.
|
|
///
|
|
/// A literal is written by the programmer, so an invalid one is a bug to be caught on first
|
|
/// run rather than handled. Use ``init(_:)`` for anything else.
|
|
///
|
|
/// - parameter value: The string literal.
|
|
/// - Precondition: the uppercased `value` is an `atom`; this traps if it isn't.
|
|
public init(stringLiteral value: String) {
|
|
precondition(value.uppercased().isIMAPAtom, "Invalid context kind: \(String(reflecting: value))")
|
|
self.init(unchecked: value)
|
|
}
|
|
}
|
|
|
|
extension Capability.SortKind: ExpressibleByStringLiteral {
|
|
/// Creates a sort kind from a string literal, uppercased.
|
|
///
|
|
/// A literal is written by the programmer, so an invalid one is a bug to be caught on first
|
|
/// run rather than handled. Use ``init(_:)`` for anything else.
|
|
///
|
|
/// - parameter value: The string literal.
|
|
/// - Precondition: the uppercased `value` is an `atom`; this traps if it isn't.
|
|
public init(stringLiteral value: String) {
|
|
precondition(value.uppercased().isIMAPAtom, "Invalid sort kind: \(String(reflecting: value))")
|
|
self.init(unchecked: value)
|
|
}
|
|
}
|
|
|
|
extension Capability.ThreadKind: ExpressibleByStringLiteral {
|
|
/// Creates a thread kind from a string literal, uppercased.
|
|
///
|
|
/// A literal is written by the programmer, so an invalid one is a bug to be caught on first
|
|
/// run rather than handled. Use ``init(_:)`` for anything else.
|
|
///
|
|
/// - parameter value: The string literal.
|
|
/// - Precondition: the uppercased `value` is an `atom`; this traps if it isn't.
|
|
public init(stringLiteral value: String) {
|
|
precondition(value.uppercased().isIMAPAtom, "Invalid thread kind: \(String(reflecting: value))")
|
|
self.init(unchecked: value)
|
|
}
|
|
}
|
|
|
|
extension Capability.StatusKind: ExpressibleByStringLiteral {
|
|
/// Creates a status kind from a string literal, uppercased.
|
|
///
|
|
/// A literal is written by the programmer, so an invalid one is a bug to be caught on first
|
|
/// run rather than handled. Use ``init(_:)`` for anything else.
|
|
///
|
|
/// - parameter value: The string literal.
|
|
/// - Precondition: the uppercased `value` is an `atom`; this traps if it isn't.
|
|
public init(stringLiteral value: String) {
|
|
precondition(value.uppercased().isIMAPAtom, "Invalid status kind: \(String(reflecting: value))")
|
|
self.init(unchecked: value)
|
|
}
|
|
}
|
|
|
|
extension Capability.UTF8Kind: ExpressibleByStringLiteral {
|
|
/// Creates a UTF-8 kind from a string literal, uppercased.
|
|
///
|
|
/// A literal is written by the programmer, so an invalid one is a bug to be caught on first
|
|
/// run rather than handled. Use ``init(_:)`` for anything else.
|
|
///
|
|
/// - parameter value: The string literal.
|
|
/// - Precondition: the uppercased `value` is an `atom`; this traps if it isn't.
|
|
public init(stringLiteral value: String) {
|
|
precondition(value.uppercased().isIMAPAtom, "Invalid UTF-8 kind: \(String(reflecting: value))")
|
|
self.init(unchecked: value)
|
|
}
|
|
}
|
|
|
|
extension Capability.RightsKind: ExpressibleByStringLiteral {
|
|
/// Creates a rights kind from a string literal, uppercased.
|
|
///
|
|
/// A literal is written by the programmer, so an invalid one is a bug to be caught on first
|
|
/// run rather than handled. Use ``init(_:)`` for anything else.
|
|
///
|
|
/// - parameter value: The string literal.
|
|
/// - Precondition: the uppercased `value` is an `atom`; this traps if it isn't.
|
|
public init(stringLiteral value: String) {
|
|
precondition(value.uppercased().isIMAPAtom, "Invalid rights kind: \(String(reflecting: value))")
|
|
self.init(unchecked: value)
|
|
}
|
|
}
|
|
|
|
extension Capability.CompressionKind: ExpressibleByStringLiteral {
|
|
/// Creates a compression kind from a string literal, uppercased.
|
|
///
|
|
/// A literal is written by the programmer, so an invalid one is a bug to be caught on first
|
|
/// run rather than handled. Use ``init(_:)`` for anything else.
|
|
///
|
|
/// - parameter value: The string literal.
|
|
/// - Precondition: the uppercased `value` is an `atom`; this traps if it isn't.
|
|
public init(stringLiteral value: String) {
|
|
precondition(value.uppercased().isIMAPAtom, "Invalid compression kind: \(String(reflecting: value))")
|
|
self.init(unchecked: value)
|
|
}
|
|
}
|
|
|
|
extension String {
|
|
public init(_ capability: Capability) {
|
|
self = capability.rawValue
|
|
}
|
|
|
|
/// Creates a `String` from a ``Capability/ContextKind``.
|
|
public init(_ other: Capability.ContextKind) {
|
|
self = other.rawValue
|
|
}
|
|
|
|
/// Creates a `String` from a ``Capability/SortKind``.
|
|
public init(_ other: Capability.SortKind) {
|
|
self = other.rawValue
|
|
}
|
|
|
|
/// Creates a `String` from a ``Capability/ThreadKind``.
|
|
public init(_ other: Capability.ThreadKind) {
|
|
self = other.rawValue
|
|
}
|
|
|
|
/// Creates a `String` from a ``Capability/StatusKind``.
|
|
public init(_ other: Capability.StatusKind) {
|
|
self = other.rawValue
|
|
}
|
|
|
|
/// Creates a `String` from a ``Capability/UTF8Kind``.
|
|
public init(_ other: Capability.UTF8Kind) {
|
|
self = other.rawValue
|
|
}
|
|
|
|
/// Creates a `String` from a ``Capability/RightsKind``.
|
|
public init(_ other: Capability.RightsKind) {
|
|
self = other.rawValue
|
|
}
|
|
|
|
/// Creates a `String` from a ``Capability/CompressionKind``, for example `DEFLATE`.
|
|
public init(_ other: Capability.CompressionKind) {
|
|
self = other.rawValue
|
|
}
|
|
}
|
|
|
|
// MARK: - Encoding
|
|
|
|
extension EncodeBuffer {
|
|
@discardableResult mutating func writeCapability(_ capability: Capability) -> Int {
|
|
self.writeAtom(capability.rawValue)
|
|
}
|
|
|
|
@discardableResult mutating func writeCapabilityData(_ data: [Capability]) -> Int {
|
|
self.writeString("CAPABILITY")
|
|
+ self.writeArray(data, prefix: " ", parenthesis: false) { (capability, self) -> Int in
|
|
self.writeCapability(capability)
|
|
}
|
|
}
|
|
}
|