mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-26 04:57:51 +00:00
* Separate LIST from its independent select options
`.listIndependent([.remote], …)` encoded as `LIST(REMOTE) …`.
RFC 5258: `list = "LIST" [SP list-select-opts] SP mailbox SP mbox-or-pat`.
* Keep leading zeros in fractional seconds
`12:34:56.05` parsed as `fraction: 5` and re-encoded as `12:34:56.5`,
changing the value.
RFC 3339: `time-secfrac = "." 1*DIGIT`. `FullTime.fraction` becomes
`FullTime.Fraction`, which stores the digits; `init?(_:)` validates,
literals trap, `String.init` reads.
* Model the RFC 3339 time offset
`;EXPIRE=2025-12-31T23:59:59Z` failed to parse inside a URL: the
parser stopped before `Z`. The encoder never wrote an offset.
RFC 4467: `expire = ";EXPIRE=" date-time`; RFC 3339: `full-time =
partial-time time-offset`, `time-offset = "Z" / time-numoffset`. Adds
the required `FullTime.offset`.
* Encode LIST extended data
`MailboxInfo.extensions` was parsed but never written, so
`* LIST (\Marked) "/" "Fruit" ("CHILDINFO" ("SUBSCRIBED"))` lost
`("CHILDINFO" …)` on re-encode.
RFC 5258: `mailbox-list = … mailbox [SP mbox-list-extended]`.
* Round-trip multi-value LIST option values
`.array(["a", "b"])` encoded as `(("a" "b"))`; the parser rejected both
that and `("a" "b")`: it took the `astring` branch first and could not
backtrack.
RFC 5258: `option-value = "(" option-val-comp ")"`, `option-val-comp =
astring / option-val-comp *(SP option-val-comp) / "(" option-val-comp
")"`. The parser reads a sequence of elements; the encoder writes
several values inside the `option-value` parentheses.
* Validate JMAPACCESS URLs
`.jmapAccess(URL(string: "jmap", relativeTo: base))` encoded as
`JMAPACCESS "jmap -- https://example.com/"` (`URL.description`); `http`
URLs were written though the parser rejects them.
The payload becomes `ResponsePayload.JMAPAccessURL`: `init?(_:)` resolves
against the base and requires `https`, a host, and no escaping inside
`quoted`; `URL.init` reads. The parser uses the same check.
* Make RESETKEY mechanisms require a mailbox
`.resetKey(mailbox: nil, mechanisms: [.internal])` encoded as bare
`RESETKEY`, silently dropping the mechanisms and resetting every key.
RFC 4467: `resetkey = "RESETKEY" [SP mailbox *(SP mechanism)]`. The
payload becomes `Command.ResetKeyScope`: `.allMailboxes` or
`.mailbox(_:mechanisms:)`.
* Hoist a #require the compiler flagged as redundant
* Cite RFC 7162 for SEARCH MODSEQ entry types
The docs described these as RFC 5464 GETMETADATA options, with
GETMETADATA examples. The grammar is RFC 7162 `search-modseq-ext`.
* Fix doc nits
- `ExtendedSearchScopeOptions.content` is a dictionary, not an array.
- `NamespaceDescription` init in the `NamespaceResponse` example needs
`try` and `responseExtensions:`.
- `TaggedExtensionLabel` example: `SELECT INBOX (CONDSTORE)` parses as
`.condStore`; use `RELEVANCY`.
- Stray `’` in a parser hint.
89 lines
3.9 KiB
Swift
89 lines
3.9 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
|
|
|
|
/// A response containing the server's namespace configuration for personal, other users', and shared mailboxes.
|
|
///
|
|
/// Represents the response to a `NAMESPACE` command (RFC 2342), which allows clients to discover
|
|
/// the mailbox namespace structure used by the server. The response contains three namespace categories,
|
|
/// each consisting of zero or more ``NamespaceDescription`` objects. Any category that is not available
|
|
/// on the server will contain an empty array.
|
|
///
|
|
/// The `NAMESPACE` command helps clients automatically determine mailbox prefixes and hierarchy delimiters
|
|
/// without requiring manual user configuration.
|
|
///
|
|
/// ### Example
|
|
///
|
|
/// ```
|
|
/// C: A001 NAMESPACE
|
|
/// S: * NAMESPACE (("" "/")) (("~" "/")) NIL
|
|
/// S: A001 OK NAMESPACE command completed
|
|
/// ```
|
|
///
|
|
/// The response is wrapped as ``NamespaceResponse`` where:
|
|
/// - `userNamespace` is `[try NamespaceDescription(string: "", delimiter: "/", responseExtensions: [:])]`
|
|
/// - `otherUserNamespace` is `[try NamespaceDescription(string: "~", delimiter: "/", responseExtensions: [:])]`
|
|
/// - `sharedNamespace` is `[]` (NIL indicates no shared namespace available)
|
|
///
|
|
/// - SeeAlso: [RFC 2342](https://datatracker.ietf.org/doc/html/rfc2342)
|
|
public struct NamespaceResponse: Hashable, Sendable {
|
|
/// Descriptions of the personal namespace(s) for the authenticated user.
|
|
///
|
|
/// The personal namespace typically contains the user's mailboxes, including the INBOX.
|
|
/// In most cases, there is only one personal namespace, though multiple are possible.
|
|
/// An empty array indicates no personal namespace is available on the server.
|
|
public var userNamespace: [NamespaceDescription]
|
|
|
|
/// Descriptions of other users' namespace(s).
|
|
///
|
|
/// The other users' namespace provides access to mailboxes from other authenticated users
|
|
/// on the server. Accessing these mailboxes requires explicit permissions from the other user.
|
|
/// An empty array indicates the server does not provide access to other users' mailboxes.
|
|
public var otherUserNamespace: [NamespaceDescription]
|
|
|
|
/// Descriptions of shared namespace(s).
|
|
///
|
|
/// Shared namespaces contain mailboxes intended to be used by multiple users and are not
|
|
/// part of any individual user's personal namespace. An empty array indicates no shared
|
|
/// namespaces are available on the server.
|
|
public var sharedNamespace: [NamespaceDescription]
|
|
|
|
/// Creates a new `NamespaceResponse`.
|
|
///
|
|
/// - Parameters:
|
|
/// - userNamespace: Descriptions of the personal namespace(s) for the authenticated user.
|
|
/// - otherUserNamespace: Descriptions of other users' namespace(s).
|
|
/// - sharedNamespace: Descriptions of shared namespace(s).
|
|
public init(
|
|
userNamespace: [NamespaceDescription],
|
|
otherUserNamespace: [NamespaceDescription],
|
|
sharedNamespace: [NamespaceDescription]
|
|
) {
|
|
self.userNamespace = userNamespace
|
|
self.otherUserNamespace = otherUserNamespace
|
|
self.sharedNamespace = sharedNamespace
|
|
}
|
|
}
|
|
|
|
// MARK: - Encoding
|
|
|
|
extension EncodeBuffer {
|
|
@discardableResult mutating func writeNamespaceResponse(_ response: NamespaceResponse) -> Int {
|
|
self.writeString("NAMESPACE ") + self.writeNamespace(response.userNamespace) + self.writeSpace()
|
|
+ self.writeNamespace(response.otherUserNamespace) + self.writeSpace()
|
|
+ self.writeNamespace(response.sharedNamespace)
|
|
}
|
|
}
|