mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-24 04:38:04 +00:00
Implement OBJECTID+ extension (#840)
This commit is contained in:
1 parent
fbec780de3
commit
f5fa7d3691
28 files changed
+756
-33
No files matched your search
@@ -197,6 +197,7 @@ extension FetchAttribute {
|
||||
.internalDate,
|
||||
.modificationSequence,
|
||||
.modificationSequenceValue,
|
||||
.objectID,
|
||||
.preview,
|
||||
.rfc822Size,
|
||||
.threadID,
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A server-assigned identifier for the account that owns a mailbox.
|
||||
///
|
||||
/// An `AccountID` identifies the account to which a mailbox belongs. When used alongside
|
||||
/// ``MailboxID``, it fully disambiguates mailboxes in environments where multiple accounts
|
||||
/// are accessible through a single IMAP session (for example, shared mailboxes or "Other
|
||||
/// Users" namespaces).
|
||||
///
|
||||
/// Valid `AccountID` values are 1-255 alphanumeric characters, hyphens, or underscores.
|
||||
/// The server MUST return the same `AccountID` for all mailboxes that belong to the same
|
||||
/// account, and MUST NOT return the same `AccountID` for mailboxes belonging to different
|
||||
/// accounts.
|
||||
///
|
||||
/// **Requires server capability:** ``Capability/objectIDPlus``
|
||||
///
|
||||
/// - SeeAlso: ``CompoundObjectID``
|
||||
public struct AccountID: Hashable, Sendable {
|
||||
fileprivate var objectID: ObjectID
|
||||
|
||||
/// Creates an `AccountID` from an `ObjectID`.
|
||||
init(_ objectID: ObjectID) {
|
||||
self.objectID = objectID
|
||||
}
|
||||
|
||||
/// Creates an `AccountID` from a `String`.
|
||||
///
|
||||
/// Valid account IDs are 1-255 alphanumeric or `-` or `_` characters.
|
||||
///
|
||||
/// - Parameter rawValue: A candidate account ID string value
|
||||
/// - Returns: An `AccountID` if the string is valid, or `nil` if it fails validation
|
||||
public init?(_ rawValue: String) {
|
||||
guard let objectID = ObjectID(rawValue) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.init(objectID)
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
public init(_ accountID: AccountID) {
|
||||
self = String(accountID.objectID)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ExpressibleByStringLiteral
|
||||
|
||||
extension AccountID: ExpressibleByStringLiteral {
|
||||
public init(stringLiteral value: StringLiteralType) {
|
||||
self.init(value)!
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - CustomDebugStringConvertible
|
||||
|
||||
extension AccountID: CustomDebugStringConvertible {
|
||||
/// `value` as a `String`.
|
||||
public var debugDescription: String {
|
||||
"(\(String(self)))"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Encoding
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeAccountID(_ id: AccountID) -> Int {
|
||||
self.writeObjectID(id.objectID)
|
||||
}
|
||||
}
|
||||
@@ -425,6 +425,15 @@ extension Capability {
|
||||
/// - 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)
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A bundle of object identifiers, as introduced by the `OBJECTID+` extension.
|
||||
///
|
||||
/// ``CompoundObjectID`` bundles the identifiers relevant to a given context (a mailbox, or a
|
||||
/// message) into a single value. Every field is optional: a server omits identifiers it does
|
||||
/// not support or that are not applicable, rather than returning a placeholder. A
|
||||
/// ``CompoundObjectID`` with every field `nil` is valid, and is encoded as `OBJECTID ()`.
|
||||
///
|
||||
/// Mailbox contexts (`SELECT`, `EXAMINE`, `CREATE`, `RENAME`, `STATUS`) typically populate
|
||||
/// ``mailboxID`` and ``accountID``. Message contexts (`FETCH`) typically populate ``emailID``
|
||||
/// and ``threadID``.
|
||||
///
|
||||
/// **Requires server capability:** ``Capability/objectIDPlus``
|
||||
///
|
||||
/// - SeeAlso: `draft-ietf-mailmaint-imap-objectid-bis`
|
||||
public struct CompoundObjectID: Hashable, Sendable {
|
||||
/// The identifier for the mailbox, if present and applicable to this context.
|
||||
public var mailboxID: MailboxID?
|
||||
|
||||
/// The identifier for the account that owns the mailbox, if present and applicable to this context.
|
||||
public var accountID: AccountID?
|
||||
|
||||
/// The identifier for the message content, if present and applicable to this context.
|
||||
public var emailID: EmailID?
|
||||
|
||||
/// The identifier for the message's thread, if present and applicable to this context.
|
||||
public var threadID: ThreadID?
|
||||
|
||||
/// Creates a compound of object identifiers.
|
||||
///
|
||||
/// - Parameter mailboxID: The mailbox's identifier, if any
|
||||
/// - Parameter accountID: The owning account's identifier, if any
|
||||
/// - Parameter emailID: The message's identifier, if any
|
||||
/// - Parameter threadID: The message's thread identifier, if any
|
||||
public init(
|
||||
mailboxID: MailboxID? = nil,
|
||||
accountID: AccountID? = nil,
|
||||
emailID: EmailID? = nil,
|
||||
threadID: ThreadID? = nil
|
||||
) {
|
||||
self.mailboxID = mailboxID
|
||||
self.accountID = accountID
|
||||
self.emailID = emailID
|
||||
self.threadID = threadID
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Encoding
|
||||
|
||||
extension EncodeBuffer {
|
||||
@discardableResult mutating func writeCompoundObjectID(_ compound: CompoundObjectID) -> Int {
|
||||
var pairs: [(String, String)] = []
|
||||
if let mailboxID = compound.mailboxID {
|
||||
pairs.append(("MAILBOXID", String(mailboxID)))
|
||||
}
|
||||
if let accountID = compound.accountID {
|
||||
pairs.append(("ACCOUNTID", String(accountID)))
|
||||
}
|
||||
if let emailID = compound.emailID {
|
||||
pairs.append(("EMAILID", String(emailID)))
|
||||
}
|
||||
if let threadID = compound.threadID {
|
||||
pairs.append(("THREADID", String(threadID)))
|
||||
}
|
||||
return self.writeArray(pairs, parenthesis: true) { (pair, buffer) in
|
||||
buffer.writeString("\(pair.0) \(pair.1)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,6 +237,17 @@ public enum FetchAttribute: Hashable, Sendable {
|
||||
///
|
||||
/// - SeeAlso: [RFC 8474](https://datatracker.ietf.org/doc/html/rfc8474)
|
||||
case threadID
|
||||
|
||||
/// A compound bundle of the message's object identifiers (`OBJECTID+` extension).
|
||||
///
|
||||
/// Returns whichever of `EMAILID` and `THREADID` the server chooses to disclose, bundled
|
||||
/// in a single ``CompoundObjectID`` value. Supersedes ``emailID`` and ``threadID``
|
||||
/// (RFC 8474) with this compound format.
|
||||
///
|
||||
/// **Requires server capability:** ``Capability/objectIDPlus``
|
||||
///
|
||||
/// - SeeAlso: `draft-ietf-mailmaint-imap-objectid-bis`
|
||||
case objectID
|
||||
}
|
||||
|
||||
extension Array where Element == FetchAttribute {
|
||||
@@ -330,6 +341,8 @@ extension EncodeBuffer {
|
||||
return self.writeFetchAttribute_emailID()
|
||||
case .threadID:
|
||||
return self.writeFetchAttribute_threadID()
|
||||
case .objectID:
|
||||
return self.writeFetchAttribute_objectID()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,4 +434,8 @@ extension EncodeBuffer {
|
||||
@discardableResult mutating func writeFetchAttribute_threadID() -> Int {
|
||||
return writeString("THREADID")
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeFetchAttribute_objectID() -> Int {
|
||||
return writeString("OBJECTID")
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,15 @@ public enum MailboxAttribute: String, CaseIterable, Sendable {
|
||||
/// **Requires server capability:** ``Capability/objectID``
|
||||
/// See [RFC 8474 Section 3](https://datatracker.ietf.org/doc/html/rfc8474#section-3).
|
||||
case mailboxID = "MAILBOXID"
|
||||
|
||||
/// The `OBJECTID` attribute: a compound bundle of the mailbox's object identifiers.
|
||||
///
|
||||
/// Returns whichever of `MAILBOXID` and `ACCOUNTID` the server chooses to disclose, bundled
|
||||
/// in a single ``CompoundObjectID`` value. Part of the `OBJECTID+` extension, which
|
||||
/// supersedes ``mailboxID`` (RFC 8474) with this compound format.
|
||||
/// **Requires server capability:** ``Capability/objectIDPlus``
|
||||
/// See `draft-ietf-mailmaint-imap-objectid-bis` for details.
|
||||
case objectID = "OBJECTID"
|
||||
}
|
||||
|
||||
/// Information about a mailbox returned by a `STATUS` command.
|
||||
@@ -181,6 +190,13 @@ public struct MailboxStatus: Hashable, Sendable {
|
||||
/// See [RFC 8474 Section 3](https://datatracker.ietf.org/doc/html/rfc8474#section-3).
|
||||
public var mailboxID: MailboxID?
|
||||
|
||||
/// The `OBJECTID` attribute: a compound bundle of the mailbox's object identifiers.
|
||||
///
|
||||
/// `nil` if the `OBJECTID` attribute was not requested or returned.
|
||||
/// **Requires server capability:** ``Capability/objectIDPlus``
|
||||
/// See `draft-ietf-mailmaint-imap-objectid-bis` for details.
|
||||
public var objectID: CompoundObjectID?
|
||||
|
||||
/// Creates a new mailbox status record with optional attribute values.
|
||||
///
|
||||
/// All parameters default to `nil`. Initialize only the attributes that were requested
|
||||
@@ -195,6 +211,7 @@ public struct MailboxStatus: Hashable, Sendable {
|
||||
/// - Parameter highestModificationSequence: The `HIGHESTMODSEQ` value if requested
|
||||
/// - Parameter appendLimit: The `APPENDLIMIT` value if requested
|
||||
/// - Parameter mailboxID: The `MAILBOXID` value if requested
|
||||
/// - Parameter objectID: The `OBJECTID` value if requested
|
||||
public init(
|
||||
messageCount: Int? = nil,
|
||||
recentCount: Int? = nil,
|
||||
@@ -204,7 +221,8 @@ public struct MailboxStatus: Hashable, Sendable {
|
||||
size: Int? = nil,
|
||||
highestModificationSequence: ModificationSequenceValue? = nil,
|
||||
appendLimit: Int? = nil,
|
||||
mailboxID: MailboxID? = nil
|
||||
mailboxID: MailboxID? = nil,
|
||||
objectID: CompoundObjectID? = nil
|
||||
) {
|
||||
self.messageCount = messageCount
|
||||
self.recentCount = recentCount
|
||||
@@ -215,6 +233,7 @@ public struct MailboxStatus: Hashable, Sendable {
|
||||
self.highestModificationSequence = highestModificationSequence
|
||||
self.appendLimit = appendLimit
|
||||
self.mailboxID = mailboxID
|
||||
self.objectID = objectID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,5 +278,10 @@ extension EncodeBuffer {
|
||||
return self.writeArray(array, parenthesis: false) { (element, self) -> Int in
|
||||
self.writeString("\(element.0) \(element.1)")
|
||||
}
|
||||
+ self.writeIfExists(status.objectID) { (compound) -> Int in
|
||||
self.write(if: !array.isEmpty) { self.writeSpace() }
|
||||
+ self.writeString("OBJECTID ")
|
||||
+ self.writeCompoundObjectID(compound)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,24 +51,37 @@ public struct MailboxInfo: Hashable, Sendable {
|
||||
/// the path separator character used to delimit parent/child relationships.
|
||||
public var path: MailboxPath
|
||||
|
||||
/// The object identifiers from the `OBJECTID` extended data item, if the server sent one.
|
||||
///
|
||||
/// The server includes the item when the ``ReturnOption/objectID`` return option was requested,
|
||||
/// and in unsolicited `LIST` responses once `OBJECTID+` is active. An empty `OBJECTID ()`
|
||||
/// yields an empty ``CompoundObjectID``. Unrecognized keys and malformed identifiers are ignored.
|
||||
///
|
||||
/// From [draft-ietf-mailmaint-imap-objectid-bis Section 7.5](https://datatracker.ietf.org/doc/html/draft-ietf-mailmaint-imap-objectid-bis#section-7.5).
|
||||
public var objectID: CompoundObjectID?
|
||||
|
||||
/// Extension parameters for future IMAP extensions.
|
||||
///
|
||||
/// This dictionary provides forward compatibility for new mailbox parameters added
|
||||
/// by future IMAP extensions beyond those standardized in RFC 3501.
|
||||
/// by future IMAP extensions beyond those standardized in RFC 3501. Extended data items
|
||||
/// that the library models, such as ``objectID``, are not included.
|
||||
public var extensions: OrderedDictionary<ByteBuffer, ParameterValue>
|
||||
|
||||
/// Creates a new mailbox information record.
|
||||
///
|
||||
/// - Parameter attributes: An array of ``Attribute`` values describing the mailbox's properties
|
||||
/// - Parameter path: The ``MailboxPath`` including the mailbox name and optional path separator
|
||||
/// - Parameter objectID: The identifiers from the `OBJECTID` extended data item, if any
|
||||
/// - Parameter extensions: Any extension parameters beyond the RFC 3501 base protocol
|
||||
public init(
|
||||
attributes: [Attribute] = [],
|
||||
path: MailboxPath,
|
||||
objectID: CompoundObjectID? = nil,
|
||||
extensions: OrderedDictionary<ByteBuffer, ParameterValue>
|
||||
) {
|
||||
self.attributes = attributes
|
||||
self.path = path
|
||||
self.objectID = objectID
|
||||
self.extensions = extensions
|
||||
}
|
||||
}
|
||||
@@ -251,6 +264,9 @@ extension EncodeBuffer {
|
||||
self.writeMailboxListFlags(flags)
|
||||
} + self.writeString(") ") + self.writeMailboxPathSeparator(list.path.pathSeparator) + self.writeSpace()
|
||||
+ self.writeMailbox(list.path.name)
|
||||
+ self.writeIfExists(list.objectID) { (compound) -> Int in
|
||||
self.writeString(" (\"OBJECTID\" ") + self.writeCompoundObjectID(compound) + self.writeString(")")
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult mutating func writeMailboxListFlags(_ flags: [MailboxInfo.Attribute]) -> Int {
|
||||
|
||||
@@ -236,6 +236,17 @@ public enum MessageAttribute: Hashable, Sendable {
|
||||
///
|
||||
/// - SeeAlso: [RFC 8474 IMAP4 Extension: OBJECTID](https://datatracker.ietf.org/doc/html/rfc8474)
|
||||
case threadID(ThreadID?)
|
||||
|
||||
/// A compound bundle of the message's object identifiers (`OBJECTID+` extension).
|
||||
///
|
||||
/// Contains whichever of `EMAILID` and `THREADID` the server chooses to disclose, bundled
|
||||
/// in a single ``CompoundObjectID`` value. Supersedes ``emailID(_:)`` and ``threadID(_:)``
|
||||
/// (RFC 8474) with this compound format.
|
||||
///
|
||||
/// **Requires server capability:** ``Capability/objectIDPlus``
|
||||
///
|
||||
/// - SeeAlso: `draft-ietf-mailmaint-imap-objectid-bis`
|
||||
case objectID(CompoundObjectID)
|
||||
}
|
||||
|
||||
extension MessageAttribute: CustomDebugStringConvertible {
|
||||
@@ -287,6 +298,8 @@ extension EncodeBuffer {
|
||||
return self.writeMessageAttribute_emailID(id)
|
||||
case .threadID(let id):
|
||||
return self.writeMessageAttribute_threadID(id)
|
||||
case .objectID(let compound):
|
||||
return self.writeString("OBJECTID ") + self.writeCompoundObjectID(compound)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -432,6 +432,14 @@ public indirect enum ResponseTextCode: Hashable, Sendable {
|
||||
/// See [RFC 8474](https://datatracker.ietf.org/doc/html/rfc8474) (OBJECTID Extension) for details.
|
||||
case mailboxID(MailboxID?)
|
||||
|
||||
/// A compound bundle of object identifiers for the selected, created, or renamed mailbox.
|
||||
///
|
||||
/// Contains whichever of `MAILBOXID`, `ACCOUNTID`, `EMAILID`, and `THREADID` the server chooses to
|
||||
/// disclose for the mailbox affected by the command. Part of the `OBJECTID+` extension, which
|
||||
/// supersedes ``mailboxID(_:)`` (RFC 8474) with this compound format.
|
||||
/// See `draft-ietf-mailmaint-imap-objectid-bis` for details.
|
||||
case objectID(CompoundObjectID)
|
||||
|
||||
/// The client must not use message sequence numbers.
|
||||
///
|
||||
/// Indicates that the server does not support the use of message sequence numbers and
|
||||
@@ -555,6 +563,8 @@ extension EncodeBuffer {
|
||||
return self.writeString("MAILBOXID (")
|
||||
+ self.writeIfExists(mailboxID) { self.writeMailboxID($0) }
|
||||
+ self.writeString(")")
|
||||
case .objectID(let compound):
|
||||
return self.writeString("OBJECTID ") + self.writeCompoundObjectID(compound)
|
||||
case .uidRequired:
|
||||
return self.writeString("UIDREQUIRED")
|
||||
}
|
||||
|
||||
@@ -73,6 +73,15 @@ public enum ReturnOption: Hashable, Sendable {
|
||||
/// From [RFC 6154 Section 3](https://datatracker.ietf.org/doc/html/rfc6154#section-3).
|
||||
case specialUse
|
||||
|
||||
/// The `OBJECTID` return option requests the object identifiers of each listed mailbox.
|
||||
///
|
||||
/// **Requires server capability:** ``Capability/objectIDPlus``
|
||||
///
|
||||
/// Each `LIST` response then carries an `OBJECTID` extended data item, available as
|
||||
/// ``MailboxInfo/objectID``. Requesting this option activates `OBJECTID+`.
|
||||
/// From [draft-ietf-mailmaint-imap-objectid-bis Section 7.5](https://datatracker.ietf.org/doc/html/draft-ietf-mailmaint-imap-objectid-bis#section-7.5).
|
||||
case objectID
|
||||
|
||||
/// Catch-all for `LIST` return options defined in future extensions.
|
||||
///
|
||||
/// Supports extension return options not yet defined in the standard.
|
||||
@@ -94,6 +103,8 @@ extension EncodeBuffer {
|
||||
return self.writeOptionExtension(option)
|
||||
case .specialUse:
|
||||
return self.writeString("SPECIAL-USE")
|
||||
case .objectID:
|
||||
return self.writeString("OBJECTID")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,6 +137,22 @@ public enum SelectParameter: Hashable, Sendable {
|
||||
/// - SeeAlso: [RFC 7162 Section 3.1.1](https://datatracker.ietf.org/doc/html/rfc7162#section-3.1.1)
|
||||
/// - SeeAlso: ``UnchangedSinceModifier``, ``ChangedSinceModifier``
|
||||
case condStore
|
||||
|
||||
/// Activate the `OBJECTID+` extension, and optionally select the mailbox by identifier
|
||||
/// rather than by name (draft-ietf-mailmaint-imap-objectid-bis `OBJECTID+` extension).
|
||||
///
|
||||
/// Without arguments (`nil`), this merely activates the extension and requests the compound
|
||||
/// `OBJECTID` response code in place of the `MAILBOXID` response code. With arguments, it
|
||||
/// additionally asks the server to select the mailbox matching the given identifiers,
|
||||
/// regardless of whether the mailbox name given to `SELECT` or `EXAMINE` still refers to it. If
|
||||
/// no mailbox matches, the server falls back to selecting by name.
|
||||
///
|
||||
/// **Requires server capability:** ``Capability/objectIDPlus``
|
||||
///
|
||||
/// - Parameter compound: The identifiers to select by, or `nil` to only activate the extension
|
||||
///
|
||||
/// - SeeAlso: `draft-ietf-mailmaint-imap-objectid-bis`
|
||||
case objectID(CompoundObjectID?)
|
||||
}
|
||||
|
||||
// MARK: - Encoding
|
||||
@@ -162,6 +178,11 @@ extension EncodeBuffer {
|
||||
return self.writeParameter(param)
|
||||
case .condStore:
|
||||
return self.writeString("CONDSTORE")
|
||||
case .objectID(let compound):
|
||||
return self.writeString("OBJECTID")
|
||||
+ self.writeIfExists(compound) { (compound) -> Int in
|
||||
self.writeSpace() + self.writeCompoundObjectID(compound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,7 @@ extension GrammarParser {
|
||||
"PREVIEW": parseFetchAttribute_preview,
|
||||
"EMAILID": { _, _ in .emailID },
|
||||
"THREADID": { _, _ in .threadID },
|
||||
"OBJECTID": { _, _ in .objectID },
|
||||
]
|
||||
|
||||
// try to use the lookup table, however obviously an unknown number
|
||||
|
||||
@@ -207,58 +207,79 @@ extension GrammarParser {
|
||||
try PL.parseOptional(
|
||||
buffer: &buffer,
|
||||
tracker: tracker,
|
||||
parser: { (buffer, tracker) -> OrderedDictionary<ByteBuffer, ParameterValue> in
|
||||
parser: { (buffer, tracker) -> ListExtended in
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
return try self.parseMailboxListExtended(buffer: &buffer, tracker: tracker)
|
||||
}
|
||||
) ?? [:]
|
||||
) ?? ListExtended()
|
||||
return MailboxInfo(
|
||||
attributes: flags,
|
||||
path: try .init(name: mailbox, pathSeparator: character),
|
||||
extensions: listExtended
|
||||
objectID: listExtended.objectID,
|
||||
extensions: listExtended.extensions
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct ListExtended {
|
||||
var objectID: CompoundObjectID?
|
||||
var extensions = OrderedDictionary<ByteBuffer, ParameterValue>()
|
||||
}
|
||||
|
||||
// mbox-list-extended = "(" [mbox-list-extended-item
|
||||
// *(SP mbox-list-extended-item)] ")"
|
||||
func parseMailboxListExtended(
|
||||
buffer: inout ParseBuffer,
|
||||
tracker: StackTracker
|
||||
) throws -> OrderedDictionary<ByteBuffer, ParameterValue> {
|
||||
try PL.composite(buffer: &buffer, tracker: tracker) {
|
||||
buffer,
|
||||
tracker -> OrderedDictionary<ByteBuffer, ParameterValue> in
|
||||
func parseMailboxListExtended(buffer: inout ParseBuffer, tracker: StackTracker) throws -> ListExtended {
|
||||
try PL.composite(buffer: &buffer, tracker: tracker) { buffer, tracker -> ListExtended in
|
||||
try PL.parseFixedString("(", buffer: &buffer, tracker: tracker)
|
||||
let data =
|
||||
try PL.parseOptional(buffer: &buffer, tracker: tracker) {
|
||||
(buffer, tracker) -> OrderedDictionary<ByteBuffer, ParameterValue> in
|
||||
var kvs = OrderedDictionary<ByteBuffer, ParameterValue>()
|
||||
let item = try self.parseMailboxListExtendedItem(buffer: &buffer, tracker: tracker)
|
||||
kvs[item.key] = item.value
|
||||
try PL.parseZeroOrMore(buffer: &buffer, into: &kvs, tracker: tracker) {
|
||||
(buffer, tracker) -> KeyValue<ByteBuffer, ParameterValue> in
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
return try self.parseMailboxListExtendedItem(buffer: &buffer, tracker: tracker)
|
||||
}
|
||||
return kvs
|
||||
} ?? [:]
|
||||
var items: [MailboxListExtendedItem] = []
|
||||
if let first = try PL.parseOptional(
|
||||
buffer: &buffer,
|
||||
tracker: tracker,
|
||||
parser: self.parseMailboxListExtendedItem
|
||||
) {
|
||||
items.append(first)
|
||||
try PL.parseZeroOrMore(buffer: &buffer, into: &items, tracker: tracker) {
|
||||
(buffer, tracker) -> MailboxListExtendedItem in
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
return try self.parseMailboxListExtendedItem(buffer: &buffer, tracker: tracker)
|
||||
}
|
||||
}
|
||||
try PL.parseFixedString(")", buffer: &buffer, tracker: tracker)
|
||||
return data
|
||||
|
||||
var result = ListExtended()
|
||||
for item in items {
|
||||
switch item {
|
||||
case .objectID(let compound):
|
||||
result.objectID = compound
|
||||
case .other(let kv):
|
||||
result.extensions[kv.key] = kv.value
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
enum MailboxListExtendedItem {
|
||||
case objectID(CompoundObjectID)
|
||||
case other(KeyValue<ByteBuffer, ParameterValue>)
|
||||
}
|
||||
|
||||
// mbox-list-extended-item = mbox-list-extended-item-tag SP
|
||||
// tagged-ext-val
|
||||
// objectid-extended-item = "OBJECTID" SP objectid-compound-value
|
||||
// ; the tag may be quoted, per mbox-list-extended-item-tag
|
||||
func parseMailboxListExtendedItem(
|
||||
buffer: inout ParseBuffer,
|
||||
tracker: StackTracker
|
||||
) throws -> KeyValue<ByteBuffer, ParameterValue> {
|
||||
try PL.composite(buffer: &buffer, tracker: tracker) { buffer, tracker -> KeyValue<ByteBuffer, ParameterValue> in
|
||||
) throws -> MailboxListExtendedItem {
|
||||
try PL.composite(buffer: &buffer, tracker: tracker) { buffer, tracker -> MailboxListExtendedItem in
|
||||
let tag = try self.parseAString(buffer: &buffer, tracker: tracker)
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
if String(buffer: tag).uppercased() == "OBJECTID" {
|
||||
return .objectID(try self.parseCompoundObjectID(buffer: &buffer, tracker: tracker))
|
||||
}
|
||||
let val = try self.parseParameterValue(buffer: &buffer, tracker: tracker)
|
||||
return .init(key: tag, value: val)
|
||||
return .other(.init(key: tag, value: val))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,6 +312,7 @@ extension GrammarParser {
|
||||
case highestModifierSequence(ModificationSequenceValue)
|
||||
case appendLimit(Int?)
|
||||
case mailboxID(MailboxID?)
|
||||
case objectID(CompoundObjectID)
|
||||
}
|
||||
|
||||
func parseStatusAttributeValue_messages(buffer: inout ParseBuffer, tracker: StackTracker) throws -> MailboxValue
|
||||
@@ -376,6 +398,14 @@ extension GrammarParser {
|
||||
return .mailboxID(mailboxID)
|
||||
}
|
||||
|
||||
func parseStatusAttributeValue_objectID(
|
||||
buffer: inout ParseBuffer,
|
||||
tracker: StackTracker
|
||||
) throws -> MailboxValue {
|
||||
try PL.parseFixedString("OBJECTID ", buffer: &buffer, tracker: tracker)
|
||||
return .objectID(try self.parseCompoundObjectID(buffer: &buffer, tracker: tracker))
|
||||
}
|
||||
|
||||
func parseStatusAttributeValue(buffer: inout ParseBuffer, tracker: StackTracker) throws -> MailboxValue {
|
||||
try PL.parseOneOf(
|
||||
[
|
||||
@@ -388,6 +418,7 @@ extension GrammarParser {
|
||||
parseStatusAttributeValue_recent,
|
||||
parseStatusAttributeValue_appendLimit,
|
||||
parseStatusAttributeValue_mailboxID,
|
||||
parseStatusAttributeValue_objectID,
|
||||
],
|
||||
buffer: &buffer,
|
||||
tracker: tracker
|
||||
@@ -426,6 +457,8 @@ extension GrammarParser {
|
||||
if let id {
|
||||
status.mailboxID = id
|
||||
}
|
||||
case .objectID(let compound):
|
||||
status.objectID = compound
|
||||
}
|
||||
}
|
||||
return status
|
||||
|
||||
@@ -353,6 +353,12 @@ extension GrammarParser {
|
||||
)
|
||||
}
|
||||
|
||||
func parseMessageAttribute_objectID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> MessageAttribute
|
||||
{
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
return .objectID(try self.parseCompoundObjectID(buffer: &buffer, tracker: tracker))
|
||||
}
|
||||
|
||||
let parsers: [String: (inout ParseBuffer, StackTracker) throws -> MessageAttribute] = [
|
||||
"FLAGS": parseMessageAttribute_flags,
|
||||
"ENVELOPE": parseMessageAttribute_envelope,
|
||||
@@ -372,6 +378,7 @@ extension GrammarParser {
|
||||
"PREVIEW": parseMessageAttribute_preview,
|
||||
"EMAILID": parseMessageAttribute_emailID,
|
||||
"THREADID": parseMessageAttribute_threadID,
|
||||
"OBJECTID": parseMessageAttribute_objectID,
|
||||
]
|
||||
return try self.parseFromLookupTable(buffer: &buffer, tracker: tracker, parsers: parsers)
|
||||
}
|
||||
|
||||
@@ -382,6 +382,11 @@ extension GrammarParser {
|
||||
return .mailboxID(mailboxID)
|
||||
}
|
||||
|
||||
func parseSuffix_objectID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> ResponseTextCode {
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
return .objectID(try parseCompoundObjectID(buffer: &buffer, tracker: tracker))
|
||||
}
|
||||
|
||||
func parseResponseTextCode_atom(buffer: inout ParseBuffer, tracker: StackTracker) throws -> ResponseTextCode {
|
||||
let atom = try self.parseAtom(buffer: &buffer, tracker: tracker)
|
||||
let string = try PL.parseOptional(buffer: &buffer, tracker: tracker) { (buffer, tracker) -> String in
|
||||
@@ -423,6 +428,7 @@ extension GrammarParser {
|
||||
"NONEXISTENT": { _, _ in .nonExistent },
|
||||
"NOPERM": { _, _ in .noPermission },
|
||||
"NOTSAVED": { _, _ in .notSaved },
|
||||
"OBJECTID": parseSuffix_objectID,
|
||||
"OVERQUOTA": { _, _ in .overQuota },
|
||||
"PARSE": { _, _ in .parse },
|
||||
"PERMANENTFLAGS": parseSuffix_permanentFlags,
|
||||
|
||||
@@ -2183,6 +2183,11 @@ extension GrammarParser {
|
||||
.statusOption(try self.parseStatusOption(buffer: &buffer, tracker: tracker))
|
||||
}
|
||||
|
||||
func parseReturnOption_objectID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> ReturnOption {
|
||||
try PL.parseFixedString("OBJECTID", buffer: &buffer, tracker: tracker)
|
||||
return .objectID
|
||||
}
|
||||
|
||||
func parseReturnOption_optionExtension(buffer: inout ParseBuffer, tracker: StackTracker) throws -> ReturnOption
|
||||
{
|
||||
.optionExtension(try self.parseOptionExtension(buffer: &buffer, tracker: tracker))
|
||||
@@ -2193,6 +2198,7 @@ extension GrammarParser {
|
||||
parseReturnOption_subscribed,
|
||||
parseReturnOption_children,
|
||||
parseReturnOption_statusOption,
|
||||
parseReturnOption_objectID,
|
||||
parseReturnOption_optionExtension,
|
||||
],
|
||||
buffer: &buffer,
|
||||
@@ -2413,10 +2419,23 @@ extension GrammarParser {
|
||||
)
|
||||
}
|
||||
|
||||
func parseSelectParameter_objectID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> SelectParameter {
|
||||
try PL.parseFixedString("OBJECTID", buffer: &buffer, tracker: tracker)
|
||||
let compound = try PL.parseOptional(buffer: &buffer, tracker: tracker) {
|
||||
(buffer, tracker) -> CompoundObjectID in
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
return try self.parseCompoundObjectID(buffer: &buffer, tracker: tracker)
|
||||
}
|
||||
return .objectID(compound)
|
||||
}
|
||||
|
||||
return try PL.parseOneOf(
|
||||
parseSelectParameter_qresync,
|
||||
parseSelectParameter_condstore,
|
||||
parseSelectParameter_basic,
|
||||
[
|
||||
parseSelectParameter_objectID,
|
||||
parseSelectParameter_qresync,
|
||||
parseSelectParameter_condstore,
|
||||
parseSelectParameter_basic,
|
||||
],
|
||||
buffer: &buffer,
|
||||
tracker: tracker
|
||||
)
|
||||
@@ -3060,6 +3079,96 @@ extension GrammarParser {
|
||||
return objectID
|
||||
}
|
||||
|
||||
// OBJECTID+
|
||||
// objectid-key = "MAILBOXID" / "ACCOUNTID" / "EMAILID" / "THREADID" / atom
|
||||
// objectid-kvpair = objectid-key SP objectid
|
||||
// objectid-compound = "OBJECTID" SP "(" [objectid-kvpair *(SP objectid-kvpair)] ")"
|
||||
func parseCompoundObjectID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> CompoundObjectID {
|
||||
enum Pair {
|
||||
case mailboxID(MailboxID)
|
||||
case accountID(AccountID)
|
||||
case emailID(EmailID)
|
||||
case threadID(ThreadID)
|
||||
case unknown
|
||||
}
|
||||
|
||||
func parsePair_mailboxID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> Pair {
|
||||
try PL.parseFixedString("MAILBOXID ", buffer: &buffer, tracker: tracker)
|
||||
return .mailboxID(MailboxID(try self.parseObjectID(buffer: &buffer, tracker: tracker)))
|
||||
}
|
||||
|
||||
func parsePair_accountID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> Pair {
|
||||
try PL.parseFixedString("ACCOUNTID ", buffer: &buffer, tracker: tracker)
|
||||
return .accountID(AccountID(try self.parseObjectID(buffer: &buffer, tracker: tracker)))
|
||||
}
|
||||
|
||||
func parsePair_emailID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> Pair {
|
||||
try PL.parseFixedString("EMAILID ", buffer: &buffer, tracker: tracker)
|
||||
return .emailID(EmailID(try self.parseObjectID(buffer: &buffer, tracker: tracker)))
|
||||
}
|
||||
|
||||
func parsePair_threadID(buffer: inout ParseBuffer, tracker: StackTracker) throws -> Pair {
|
||||
try PL.parseFixedString("THREADID ", buffer: &buffer, tracker: tracker)
|
||||
return .threadID(ThreadID(try self.parseObjectID(buffer: &buffer, tracker: tracker)))
|
||||
}
|
||||
|
||||
// Unrecognized keys, and their values, are parsed and discarded. Clients MUST ignore
|
||||
// unrecognized key-value pairs so that future extensions can add new identifier types.
|
||||
func parsePair_unknown(buffer: inout ParseBuffer, tracker: StackTracker) throws -> Pair {
|
||||
_ = try self.parseAtom(buffer: &buffer, tracker: tracker)
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
_ = try self.parseObjectID(buffer: &buffer, tracker: tracker)
|
||||
return .unknown
|
||||
}
|
||||
|
||||
func parsePair(buffer: inout ParseBuffer, tracker: StackTracker) throws -> Pair {
|
||||
try PL.parseOneOf(
|
||||
[
|
||||
parsePair_mailboxID,
|
||||
parsePair_accountID,
|
||||
parsePair_emailID,
|
||||
parsePair_threadID,
|
||||
parsePair_unknown,
|
||||
],
|
||||
buffer: &buffer,
|
||||
tracker: tracker
|
||||
)
|
||||
}
|
||||
|
||||
return try PL.composite(buffer: &buffer, tracker: tracker) { (buffer, tracker) -> CompoundObjectID in
|
||||
try PL.parseFixedString("(", buffer: &buffer, tracker: tracker)
|
||||
|
||||
var pairs: [Pair] = []
|
||||
if let first = try PL.parseOptional(buffer: &buffer, tracker: tracker, parser: parsePair) {
|
||||
pairs.append(first)
|
||||
try PL.parseZeroOrMore(buffer: &buffer, into: &pairs, tracker: tracker) {
|
||||
(buffer, tracker) -> Pair in
|
||||
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
|
||||
return try parsePair(buffer: &buffer, tracker: tracker)
|
||||
}
|
||||
}
|
||||
|
||||
try PL.parseFixedString(")", buffer: &buffer, tracker: tracker)
|
||||
|
||||
var compound = CompoundObjectID()
|
||||
for pair in pairs {
|
||||
switch pair {
|
||||
case .mailboxID(let value):
|
||||
compound.mailboxID = value
|
||||
case .accountID(let value):
|
||||
compound.accountID = value
|
||||
case .emailID(let value):
|
||||
compound.emailID = value
|
||||
case .threadID(let value):
|
||||
compound.threadID = value
|
||||
case .unknown:
|
||||
break
|
||||
}
|
||||
}
|
||||
return compound
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses an object ID leniently: any run of bytes up to a delimiter (space, `)`, `]`, CR, LF) is consumed,
|
||||
/// and `nil` is returned if it isn't a valid ``ObjectID`` rather than failing the parse.
|
||||
func parseObjectIDLeniently(buffer: inout ParseBuffer, tracker: StackTracker) throws -> ObjectID? {
|
||||
|
||||
@@ -562,7 +562,8 @@ extension FetchAttribute {
|
||||
.gmailLabels,
|
||||
.preview,
|
||||
.emailID,
|
||||
.threadID:
|
||||
.threadID,
|
||||
.objectID:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 NIO
|
||||
@_spi(NIOIMAPInternal) @testable import NIOIMAPCore
|
||||
import Testing
|
||||
|
||||
@Suite("AccountID")
|
||||
struct AccountIDTests {
|
||||
@Test(
|
||||
"failable init",
|
||||
arguments: [
|
||||
("abc123", true),
|
||||
("ABC-XYZ_123", true),
|
||||
("a", true),
|
||||
(String(repeating: "a", count: 255), true),
|
||||
("", false),
|
||||
("abc!", false),
|
||||
(String(repeating: "a", count: 256), false),
|
||||
] as [(String, Bool)]
|
||||
)
|
||||
func faillableInit(_ fixture: (String, Bool)) {
|
||||
let result = AccountID(fixture.0)
|
||||
#expect((result != nil) == fixture.1)
|
||||
}
|
||||
|
||||
@Test(
|
||||
"string conversion",
|
||||
arguments: [
|
||||
("abc123", "abc123"),
|
||||
("ABC-XYZ_123", "ABC-XYZ_123"),
|
||||
] as [(String, String)]
|
||||
)
|
||||
func stringConversion(_ fixture: (String, String)) {
|
||||
let id = AccountID(fixture.0)!
|
||||
#expect(String(id) == fixture.1)
|
||||
}
|
||||
|
||||
@Test("string literal init")
|
||||
func stringLiteralInit() {
|
||||
let id: AccountID = "abc123"
|
||||
#expect(String(id) == "abc123")
|
||||
}
|
||||
|
||||
@Test(
|
||||
"debug description",
|
||||
arguments: [
|
||||
("abc123", "(abc123)"),
|
||||
("XYZ-789", "(XYZ-789)"),
|
||||
] as [(String, String)]
|
||||
)
|
||||
func debugDescription(_ fixture: (String, String)) {
|
||||
let id = AccountID(fixture.0)!
|
||||
#expect(id.debugDescription == fixture.1)
|
||||
}
|
||||
|
||||
@Test(
|
||||
"encode",
|
||||
arguments: [
|
||||
EncodeFixture.accountID("abc123", "abc123"),
|
||||
EncodeFixture.accountID("XYZ-789_000", "XYZ-789_000"),
|
||||
]
|
||||
)
|
||||
func encode(_ fixture: EncodeFixture<AccountID>) {
|
||||
fixture.checkEncoding()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Fixtures
|
||||
|
||||
extension EncodeFixture<AccountID> {
|
||||
fileprivate static func accountID(_ rawValue: String, _ expectedString: String) -> Self {
|
||||
EncodeFixture(
|
||||
input: AccountID(rawValue)!,
|
||||
bufferKind: .defaultServer,
|
||||
expectedString: expectedString,
|
||||
encoder: { $0.writeAccountID($1) }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@ struct CapabilityTests {
|
||||
EncodeFixture.capability(.multiSearch, "MULTISEARCH"),
|
||||
EncodeFixture.capability(.namespace, "NAMESPACE"),
|
||||
EncodeFixture.capability(.objectID, "OBJECTID"),
|
||||
EncodeFixture.capability(.objectIDPlus, "OBJECTID+"),
|
||||
EncodeFixture.capability(.partial, "PARTIAL"),
|
||||
EncodeFixture.capability(.partialURL, "URL-PARTIAL"),
|
||||
EncodeFixture.capability(.preview, "PREVIEW"),
|
||||
@@ -151,6 +152,7 @@ struct CapabilityTests {
|
||||
ParseFixture.capability("MULTISEARCH", expected: .success(.multiSearch)),
|
||||
ParseFixture.capability("NAMESPACE", expected: .success(.namespace)),
|
||||
ParseFixture.capability("OBJECTID", expected: .success(.objectID)),
|
||||
ParseFixture.capability("OBJECTID+", expected: .success(.objectIDPlus)),
|
||||
ParseFixture.capability("PARTIAL", expected: .success(.partial)),
|
||||
ParseFixture.capability("PREVIEW", expected: .success(.preview)),
|
||||
ParseFixture.capability("QRESYNC", expected: .success(.qresync)),
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 NIO
|
||||
@_spi(NIOIMAPInternal) @testable import NIOIMAPCore
|
||||
import Testing
|
||||
|
||||
@Suite("CompoundObjectID")
|
||||
struct CompoundObjectIDTests {
|
||||
@Test(
|
||||
"encode",
|
||||
arguments: [
|
||||
EncodeFixture.compoundObjectID(CompoundObjectID(), "()"),
|
||||
EncodeFixture.compoundObjectID(CompoundObjectID(mailboxID: "abc123"), "(MAILBOXID abc123)"),
|
||||
EncodeFixture.compoundObjectID(CompoundObjectID(accountID: "def456"), "(ACCOUNTID def456)"),
|
||||
EncodeFixture.compoundObjectID(CompoundObjectID(emailID: "ghi789"), "(EMAILID ghi789)"),
|
||||
EncodeFixture.compoundObjectID(CompoundObjectID(threadID: "jkl012"), "(THREADID jkl012)"),
|
||||
EncodeFixture.compoundObjectID(
|
||||
CompoundObjectID(mailboxID: "abc123", accountID: "def456", emailID: "ghi789", threadID: "jkl012"),
|
||||
"(MAILBOXID abc123 ACCOUNTID def456 EMAILID ghi789 THREADID jkl012)"
|
||||
),
|
||||
]
|
||||
)
|
||||
func encode(_ fixture: EncodeFixture<CompoundObjectID>) {
|
||||
fixture.checkEncoding()
|
||||
}
|
||||
|
||||
@Test(
|
||||
"parse",
|
||||
arguments: [
|
||||
ParseFixture.compoundObjectID("()", expected: .success(CompoundObjectID())),
|
||||
ParseFixture.compoundObjectID(
|
||||
"(MAILBOXID abc123)",
|
||||
expected: .success(CompoundObjectID(mailboxID: "abc123"))
|
||||
),
|
||||
ParseFixture.compoundObjectID(
|
||||
"(MAILBOXID abc123 ACCOUNTID def456 EMAILID ghi789 THREADID jkl012)",
|
||||
expected: .success(
|
||||
CompoundObjectID(mailboxID: "abc123", accountID: "def456", emailID: "ghi789", threadID: "jkl012")
|
||||
)
|
||||
),
|
||||
ParseFixture.compoundObjectID(
|
||||
"(FOO bar123 MAILBOXID abc123)",
|
||||
expected: .success(CompoundObjectID(mailboxID: "abc123"))
|
||||
),
|
||||
]
|
||||
)
|
||||
func parse(_ fixture: ParseFixture<CompoundObjectID>) {
|
||||
fixture.checkParsing()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
extension EncodeFixture<CompoundObjectID> {
|
||||
fileprivate static func compoundObjectID(_ input: CompoundObjectID, _ expectedString: String) -> Self {
|
||||
EncodeFixture(
|
||||
input: input,
|
||||
bufferKind: .defaultServer,
|
||||
expectedString: expectedString,
|
||||
encoder: { $0.writeCompoundObjectID($1) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension ParseFixture<CompoundObjectID> {
|
||||
fileprivate static func compoundObjectID(
|
||||
_ input: String,
|
||||
_ terminator: String = " ",
|
||||
expected: Expected
|
||||
) -> Self {
|
||||
ParseFixture(
|
||||
input: input,
|
||||
terminator: terminator,
|
||||
expected: expected,
|
||||
parser: GrammarParser().parseCompoundObjectID
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ struct FetchAttributeTests {
|
||||
EncodeFixture.fetchAttribute(.preview(lazy: true), "PREVIEW (LAZY)"),
|
||||
EncodeFixture.fetchAttribute(.emailID, "EMAILID"),
|
||||
EncodeFixture.fetchAttribute(.threadID, "THREADID"),
|
||||
EncodeFixture.fetchAttribute(.objectID, "OBJECTID"),
|
||||
])
|
||||
func encode(_ fixture: EncodeFixture<FetchAttribute>) {
|
||||
fixture.checkEncoding()
|
||||
@@ -95,6 +96,7 @@ struct FetchAttributeTests {
|
||||
ReflectionFixture<FetchAttribute>(sut: .preview(lazy: true), expected: "PREVIEW (LAZY)"),
|
||||
ReflectionFixture<FetchAttribute>(sut: .emailID, expected: "EMAILID"),
|
||||
ReflectionFixture<FetchAttribute>(sut: .threadID, expected: "THREADID"),
|
||||
ReflectionFixture<FetchAttribute>(sut: .objectID, expected: "OBJECTID"),
|
||||
]
|
||||
)
|
||||
func customDebugStringConvertible(_ fixture: ReflectionFixture<FetchAttribute>) {
|
||||
@@ -202,6 +204,7 @@ struct FetchAttributeTests {
|
||||
ParseFixture.fetchAttribute("PREVIEW (LAZY)", " ", expected: .success(.preview(lazy: true))),
|
||||
ParseFixture.fetchAttribute("EMAILID", " ", expected: .success(.emailID)),
|
||||
ParseFixture.fetchAttribute("THREADID", " ", expected: .success(.threadID)),
|
||||
ParseFixture.fetchAttribute("OBJECTID", " ", expected: .success(.objectID)),
|
||||
// Numeric inputs fall back to parseFetchAttribute_modificationSequence
|
||||
ParseFixture.fetchAttribute("0", " ", expected: .success(.modificationSequenceValue(.zero))),
|
||||
ParseFixture.fetchAttribute("42", " ", expected: .success(.modificationSequenceValue(42))),
|
||||
|
||||
@@ -33,6 +33,7 @@ struct ListReturnOptionsTests {
|
||||
@Test(arguments: [
|
||||
ParseFixture.returnOption("SUBSCRIBED", ")", expected: .success(.subscribed)),
|
||||
ParseFixture.returnOption("CHILDREN", ")", expected: .success(.children)),
|
||||
ParseFixture.returnOption("OBJECTID", ")", expected: .success(.objectID)),
|
||||
ParseFixture.returnOption("STATUS (MESSAGES)", " ", expected: .success(.statusOption([.messageCount]))),
|
||||
ParseFixture.returnOption(
|
||||
"MYEXT",
|
||||
|
||||
@@ -36,6 +36,7 @@ struct MailboxAttributeTests {
|
||||
"HIGHESTMODSEQ MESSAGES"
|
||||
),
|
||||
EncodeFixture.mailboxAttributes([MailboxAttribute.mailboxID], "MAILBOXID"),
|
||||
EncodeFixture.mailboxAttributes([MailboxAttribute.objectID], "OBJECTID"),
|
||||
]
|
||||
)
|
||||
func encodeAttributes(_ fixture: EncodeFixture<[MailboxAttribute]>) {
|
||||
@@ -68,6 +69,14 @@ struct MailboxAttributeTests {
|
||||
.init(nextUID: 377_003),
|
||||
"UIDNEXT 377003"
|
||||
),
|
||||
EncodeFixture.mailboxStatus(
|
||||
.init(objectID: CompoundObjectID(mailboxID: "abc123", accountID: "def456")),
|
||||
"OBJECTID (MAILBOXID abc123 ACCOUNTID def456)"
|
||||
),
|
||||
EncodeFixture.mailboxStatus(
|
||||
.init(messageCount: 1, objectID: CompoundObjectID(mailboxID: "abc123")),
|
||||
"MESSAGES 1 OBJECTID (MAILBOXID abc123)"
|
||||
),
|
||||
]
|
||||
)
|
||||
func encodeStatus(_ fixture: EncodeFixture<MailboxStatus>) {
|
||||
@@ -128,6 +137,14 @@ struct MailboxAttributeTests {
|
||||
"MAILBOXID (F2212ea87-6097-4256-9d51-71338625)",
|
||||
expected: .success(.init(mailboxID: "F2212ea87-6097-4256-9d51-71338625"))
|
||||
),
|
||||
ParseFixture.mailboxStatus(
|
||||
"OBJECTID (MAILBOXID abc123 ACCOUNTID def456)",
|
||||
expected: .success(.init(objectID: CompoundObjectID(mailboxID: "abc123", accountID: "def456")))
|
||||
),
|
||||
ParseFixture.mailboxStatus(
|
||||
"OBJECTID ()",
|
||||
expected: .success(.init(objectID: CompoundObjectID()))
|
||||
),
|
||||
ParseFixture.mailboxStatus(
|
||||
"MESSAGES 3 MAILBOXID (bad!id) UNSEEN 1",
|
||||
expected: .success(.init(messageCount: 3, unseenCount: 1))
|
||||
@@ -150,6 +167,7 @@ struct MailboxAttributeTests {
|
||||
expected: .success([.messageCount, .recentCount, .unseenCount])
|
||||
),
|
||||
ParseFixture.statusOption("STATUS (UIDNEXT)", expected: .success([.uidNext])),
|
||||
ParseFixture.statusOption("STATUS (OBJECTID)", expected: .success([.objectID])),
|
||||
ParseFixture.statusOption("", "", expected: .incompleteMessage),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -80,6 +80,15 @@ struct MailboxInfoTests {
|
||||
MailboxInfo(attributes: [], path: try! .init(name: .inbox), extensions: [:]),
|
||||
#"() NIL "INBOX""#
|
||||
),
|
||||
EncodeFixture.mailboxInfo(
|
||||
MailboxInfo(
|
||||
attributes: [],
|
||||
path: try! .init(name: .inbox),
|
||||
objectID: CompoundObjectID(mailboxID: "F1", accountID: "u1"),
|
||||
extensions: [:]
|
||||
),
|
||||
#"() NIL "INBOX" ("OBJECTID" (MAILBOXID F1 ACCOUNTID u1))"#
|
||||
),
|
||||
EncodeFixture.mailboxInfo(
|
||||
MailboxInfo(attributes: [], path: try! .init(name: .inbox, pathSeparator: "/"), extensions: [:]),
|
||||
#"() "/" "INBOX""#
|
||||
@@ -213,6 +222,26 @@ struct MailboxInfoTests {
|
||||
)
|
||||
)
|
||||
),
|
||||
// Extended list — OBJECTID is parsed into `objectID`, not `extensions`
|
||||
ParseFixture.mailboxInfo(
|
||||
#"() "." inbox ("OBJECTID" (MAILBOXID F1 ACCOUNTID u1 X-NEW v) KEY (VAL))"#,
|
||||
"\r",
|
||||
expected: .success(
|
||||
.init(
|
||||
attributes: [],
|
||||
path: try! .init(name: .inbox, pathSeparator: "."),
|
||||
objectID: CompoundObjectID(mailboxID: "F1", accountID: "u1"),
|
||||
extensions: [ByteBuffer(string: "KEY"): .comp(["VAL"])]
|
||||
)
|
||||
)
|
||||
),
|
||||
ParseFixture.mailboxInfo(
|
||||
"() NIL inbox (objectid ())",
|
||||
"\r",
|
||||
expected: .success(
|
||||
.init(attributes: [], path: try! .init(name: .inbox), objectID: CompoundObjectID(), extensions: [:])
|
||||
)
|
||||
),
|
||||
// Extended list — two items: covers parseZeroOrMore additional item path (line 244)
|
||||
ParseFixture.mailboxInfo(
|
||||
"() NIL inbox (KEY1 (VAL1) KEY2 (VAL2))",
|
||||
|
||||
@@ -99,6 +99,11 @@ struct MessageAttributeTests {
|
||||
EncodeFixture.messageAttribute(.emailID(.init("123-456-789")!), "EMAILID (123-456-789)"),
|
||||
EncodeFixture.messageAttribute(.threadID(.init("123-456-789")!), "THREADID (123-456-789)"),
|
||||
EncodeFixture.messageAttribute(.threadID(nil), "THREADID NIL"),
|
||||
EncodeFixture.messageAttribute(.objectID(CompoundObjectID()), "OBJECTID ()"),
|
||||
EncodeFixture.messageAttribute(
|
||||
.objectID(CompoundObjectID(emailID: "m1", threadID: "t1")),
|
||||
"OBJECTID (EMAILID m1 THREADID t1)"
|
||||
),
|
||||
EncodeFixture.messageAttribute(.body(.invalid, hasExtensionData: false), "BODY ()"),
|
||||
EncodeFixture.messageAttribute(.body(.invalid, hasExtensionData: true), "BODYSTRUCTURE ()"),
|
||||
EncodeFixture.messageAttribute(.nilBody(.rfc822Text), "RFC822.TEXT NIL"),
|
||||
@@ -466,6 +471,16 @@ struct MessageAttributeTests {
|
||||
expected: .success(.threadID(.init("123-456-789")!))
|
||||
),
|
||||
ParseFixture.messageAttribute("THREADID NIL", " ", expected: .success(.threadID(nil))),
|
||||
ParseFixture.messageAttribute(
|
||||
"OBJECTID ()",
|
||||
" ",
|
||||
expected: .success(.objectID(CompoundObjectID()))
|
||||
),
|
||||
ParseFixture.messageAttribute(
|
||||
"OBJECTID (EMAILID m1 THREADID t1)",
|
||||
" ",
|
||||
expected: .success(.objectID(CompoundObjectID(emailID: "m1", threadID: "t1")))
|
||||
),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,11 @@ struct ResponseTextCodeTests {
|
||||
EncodeFixture.responseTextCode(.noPermission, "NOPERM"),
|
||||
EncodeFixture.responseTextCode(.nonExistent, "NONEXISTENT"),
|
||||
EncodeFixture.responseTextCode(.notSaved, "NOTSAVED"),
|
||||
EncodeFixture.responseTextCode(.objectID(CompoundObjectID()), "OBJECTID ()"),
|
||||
EncodeFixture.responseTextCode(
|
||||
.objectID(CompoundObjectID(mailboxID: "abc123", accountID: "def456")),
|
||||
"OBJECTID (MAILBOXID abc123 ACCOUNTID def456)"
|
||||
),
|
||||
EncodeFixture.responseTextCode(.other("SOMETHING", nil), "SOMETHING"),
|
||||
EncodeFixture.responseTextCode(.other("some", "thing"), "some thing"),
|
||||
EncodeFixture.responseTextCode(.other("some", nil), "some"),
|
||||
@@ -191,6 +196,11 @@ struct ResponseTextCodeTests {
|
||||
ParseFixture.responseTextCode("NONEXISTENT", expected: .success(.nonExistent)),
|
||||
ParseFixture.responseTextCode("NOPERM", expected: .success(.noPermission)),
|
||||
ParseFixture.responseTextCode("NOTSAVED", expected: .success(.notSaved)),
|
||||
ParseFixture.responseTextCode("OBJECTID ()", expected: .success(.objectID(CompoundObjectID()))),
|
||||
ParseFixture.responseTextCode(
|
||||
"OBJECTID (MAILBOXID abc123 ACCOUNTID def456)",
|
||||
expected: .success(.objectID(CompoundObjectID(mailboxID: "abc123", accountID: "def456")))
|
||||
),
|
||||
ParseFixture.responseTextCode("OVERQUOTA", expected: .success(.overQuota)),
|
||||
ParseFixture.responseTextCode("PARSE", expected: .success(.parse)),
|
||||
ParseFixture.responseTextCode("PERMANENTFLAGS ()", expected: .success(.permanentFlags([]))),
|
||||
|
||||
@@ -24,6 +24,7 @@ struct ReturnOptionTests {
|
||||
EncodeFixture.returnOption(.statusOption([.messageCount]), "STATUS (MESSAGES)"),
|
||||
EncodeFixture.returnOption(.optionExtension(.init(key: .standard("atom"), value: nil)), "atom"),
|
||||
EncodeFixture.returnOption(.specialUse, "SPECIAL-USE"),
|
||||
EncodeFixture.returnOption(.objectID, "OBJECTID"),
|
||||
])
|
||||
func encode(_ fixture: EncodeFixture<ReturnOption>) {
|
||||
fixture.checkEncoding()
|
||||
|
||||
@@ -23,6 +23,14 @@ struct SelectParameterTests {
|
||||
.condStore,
|
||||
"CONDSTORE"
|
||||
),
|
||||
EncodeFixture.selectParameter(
|
||||
.objectID(nil),
|
||||
"OBJECTID"
|
||||
),
|
||||
EncodeFixture.selectParameter(
|
||||
.objectID(CompoundObjectID(mailboxID: "abc123", accountID: "def456")),
|
||||
"OBJECTID (MAILBOXID abc123 ACCOUNTID def456)"
|
||||
),
|
||||
EncodeFixture.selectParameter(
|
||||
.basic(.init(key: "test", value: nil)),
|
||||
"test"
|
||||
@@ -90,6 +98,18 @@ struct SelectParameterTests {
|
||||
"CONDSTORE",
|
||||
expected: .success(.condStore)
|
||||
),
|
||||
ParseFixture.selectParameter(
|
||||
"OBJECTID",
|
||||
expected: .success(.objectID(nil))
|
||||
),
|
||||
ParseFixture.selectParameter(
|
||||
"OBJECTID ()",
|
||||
expected: .success(.objectID(CompoundObjectID()))
|
||||
),
|
||||
ParseFixture.selectParameter(
|
||||
"OBJECTID (MAILBOXID abc123 ACCOUNTID def456)",
|
||||
expected: .success(.objectID(CompoundObjectID(mailboxID: "abc123", accountID: "def456")))
|
||||
),
|
||||
ParseFixture.selectParameter(
|
||||
"QRESYNC (1 1)",
|
||||
expected: .success(
|
||||
|
||||
Reference in new issue
Block a user