Files
swift-nio-imap/Sources/NIOIMAPCore/Grammar/URLFetchData.swift
T
Daniel Eggert 3efffa1dc6 Drop NIO from NIOIMAPCore (mostly scripted)
NIOIMAPCore and its tests no longer depend on swift-nio; NIOIMAP declares
the dependency it was getting transitively. Hand edits: Package.swift and
NIOIMAPCore.md. Everything else is the output of, on the parent
commit (zsh):

  F=($(grep -rlE '^import ((struct|enum|class|protocol) )?NIO(Core|TestUtils)?(\.[A-Za-z]+)?$' \
      Sources/NIOIMAPCore Tests/NIOIMAPCoreTests))
  perl -0pi -e 's/^import (?:(?:struct|enum|class|protocol) )?NIO(?:Core|TestUtils)?(?:\.\w+)?\n//mg;
      s/\n\n\n+/\n\n/g' $F

Public break: depending on NIOIMAPCore no longer provides swift-nio.
2026-11-24 09:48:18 +09:00

88 lines
3.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
//
//===----------------------------------------------------------------------===//
/// A URL and the message data associated with it in a URLFETCH response.
///
/// When a client issues a `URLFETCH` command (RFC 4467) with one or more IMAP URLs (potentially
/// URLAUTH-authorized), the server returns the content of those URLs in a URLFETCH response.
/// Each ``URLFetchData`` represents one URL and its associated message content.
///
/// The response format includes:
/// - The URL (as an IMAP string) that was requested
/// - The message data (as an IMAP string or NIL if unavailable)
///
/// ### Example
///
/// URLFETCH command and response:
/// ```
/// C: a001 URLFETCH "imap://user@example.com/INBOX/;uid=20;urlauth=anonymous:internal:TOKEN"
/// S: * URLFETCH ("imap://user@example.com/INBOX/;uid=20;urlauth=anonymous:internal:TOKEN" {1234}
/// S: message-content-here...)
/// S: a001 OK URLFETCH completed
/// ```
///
/// The server response line `* URLFETCH (url data)` is wrapped as ``Response/untagged(_:)``
/// containing ``MessageData/urlFetch(_:)`` with a list of ``URLFetchData`` items.
///
/// Each item pairs the requested URL with the fetched message data (or NIL if the URL
/// was invalid or the server could not retrieve the data).
///
/// ### URL Format
///
/// The URL is typically returned as it was submitted, including any URLAUTH authorization tokens:
/// ```
/// imap://user@example.com/INBOX/;uid=20;section=1.2;urlauth=anonymous:internal:...
/// ```
///
/// ## Related types
///
/// - ``NetworkMessagePath`` represents the base URL before authorization
/// - ``AuthenticatedURL`` provides URLAUTH verification for the URL
/// - ``URLCommand`` specifies what to fetch
/// - ``Response/untagged(_:)`` wraps the response
/// - ``MessageData/urlFetch(_:)`` contains the URLFETCH data
///
/// - SeeAlso: [RFC 4467 Section 7](https://datatracker.ietf.org/doc/html/rfc4467#section-7) - URLFETCH Command
public struct URLFetchData: Hashable, Sendable {
/// The IMAP URL that was fetched.
///
/// The URL as submitted in the URLFETCH command, typically including
/// URLAUTH authorization information if the URL was authorized.
public var url: [UInt8]
/// The message data associated with the URL, or `nil` if unavailable.
///
/// When `nil`, indicates that the server could not retrieve the message data
/// (for example, because the URL was invalid, authorization failed, or the message was deleted).
/// When present, contains the message content (or partial content if the URL
/// specified a section or byte range).
public var data: [UInt8]?
/// Creates a new URLFETCH response data item.
/// - parameter url: The IMAP URL that was fetched.
/// - parameter data: The message data, or `nil` if unavailable.
public init(url: [UInt8], data: [UInt8]?) {
self.url = url
self.data = data
}
}
// MARK: - Encoding
extension EncodeBuffer {
@discardableResult mutating func writeURLFetchData(_ data: URLFetchData) -> Int {
self.writeIMAPString(data.url) + self.writeSpace() + self.writeNString(data.data)
}
}