Files
swift-nio-imap/Sources/NIOIMAPCore/Grammar/UID/IUID.swift
T
Daniel Eggert 31978d2594 Encode numbers without string interpolation
Add EncodeBuffer.writeByte / writeDecimal / writeLiteralHeader /
writeRedactedByteCount and use them for every numeric interpolation
in encoders. writeString("…\(x)…") sites become separate writeString
calls; quote-wrapped ones ("\"\(x)\"") stay. writeMailboxStatus
writes each attribute directly instead of building (String, String)
pairs. Output unchanged for valid values; avoids String formatting and
allocation. Invalid (negative) FullDate/FullTime fields now pad after
the sign: -0005, not 00-5.

writeLiteralHeader takes LiteralSynchronization (`{n+}`) and
LiteralKind (`~{n}`) enums.
2026-11-20 12:49:09 +01:00

65 lines
2.5 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/// An error indicating that a UID value was invalid (zero or less).
///
/// IMAP UIDs must be greater than zero. This error is raised if an invalid UID value
/// is provided to constructors or validators.
public struct InvalidUID: Error {}
/// A wrapped ``UID`` for use in IMAP URL constructs and CATENATE operations.
///
/// The `IUID` type wraps a ``UID`` and provides encoding compatible with IMAP URL syntax,
/// URLAUTH-authorized URLs, and CATENATE extension syntax. It is used in operations that
/// reference message content by URL-style paths, particularly in RFC 2192/5092 IMAP URL,
/// RFC 4467 URLAUTH, and RFC 4469 CATENATE contexts.
///
/// In IMAP URL/CATENATE format, a UID is encoded as:
/// - `;UID=<uid-value>` (in relative paths or CATENATE operations)
/// - `/;UID=<uid-value>` (in absolute message paths)
///
/// Primarily used internally for IMAP URL constructs, URLAUTH-authorized URL
/// verification, and CATENATE append operations that reference existing messages on the server.
///
/// See [RFC 4467](https://datatracker.ietf.org/doc/html/rfc4467) (URLAUTH Extension)
/// and [RFC 4469](https://datatracker.ietf.org/doc/html/rfc4469) (CATENATE Extension)
/// for details on how IUIDs are used to reference message content.
///
/// ## Related types
///
/// - ``UID`` is the wrapped type containing the actual message identifier
/// - ``MessagePath`` uses ``IUID`` for URL-style message identification
/// - ``NetworkMessagePath`` uses ``MessagePath`` for network-accessible URLs
public struct IUID: Hashable, Sendable {
/// The wrapped ``UID`` value.
///
/// - Returns: The underlying UID for this IUID.
public var uid: UID
/// Creates a new `IUID` from a ``UID``.
///
/// - parameter uid: The `UID` to wrap.
public init(uid: UID) {
self.uid = uid
}
}
// MARK: - Encoding
extension EncodeBuffer {
@discardableResult mutating func writeIUID(_ data: IUID) -> Int {
self.writeString("/;UID=") + self.writeMessageIdentifier(data.uid)
}
}