11 Commits
Author SHA1 Message Date
Daniel Eggert 9f61149d6d Validate IMAP URL components (#867)
* Validate percent-encoded IMAP URL components

`EncodedMailbox(mailbox: "x] x\r\n* BYE")` was written verbatim inside
the bare URL of `[REFERRAL …]`, injecting a response; likewise
`EncodedUser`, `EncodedAuthenticationType`, `EncodedSearch`,
`EncodedSection`.

RFC 5092: `enc-user`/`enc-auth-type = 1*achar`, `enc-mailbox`/
`enc-search`/`enc-section = 1*bchar`. Each type's public `var` and
labelled init become `init?(_:)`, literals trap, `String.init` reads.
One helper validates by character class and `pct-encoded` triplet, and
uppercases hex digits as the parser does, so values round-trip.

* Validate URLAUTH tokens

`EncodedAuthenticatedURL(data: "x\r\n* BYE")` was written verbatim at the
end of a URLAUTH URL, injecting a response.

RFC 4467: `enc-urlauth = 32*HEXDIG`. `init(data:)` and the public `var`
become `init?(_:)`; literals trap; `String.init` reads. The parser read
exactly 32 digits, so longer tokens didn't round-trip; it now reads all.

* Add IMAPServer.Host and keep IP-literal brackets

`IMAPServer(host: "h] x\r\n* BYE")` was written verbatim in the bare URL
of `[REFERRAL …]`, injecting a response. `imap://[::1]/` parsed as host
`::1` and re-encoded as `imap://::1/`. A negative port encoded as `:-1`.

RFC 3986: `host = IP-literal / IPv4address / reg-name`. New nested
`IMAPServer.Host` replaces the `String`: `init?(_:)` validates IPv6,
IPvFuture and reg-name (IPv4 is a subset), literals trap. The parser
keeps the brackets, accepts all of reg-name, and validates via `init?`;
its unreachable IPv4 branch is gone. `port` is now `UInt16?`.

* Don't parenthesize URLFETCH responses

`.urlFetch([.init(url: "url", data: nil)])` encoded as
`URLFETCH("url" NIL)`, which our parser rejects.

RFC 4467: `urlfetch-data = "URLFETCH" 1*(SP url-full SP nstring)`. Write
each pair after a space, unparenthesized. Fix fixtures that enshrined
the old output.

* Remove dead URL and date writers

`writeAuthIMAPURLRump`, `writeAuthIMAPURLFull`, `writeRelativeIMAPURL`,
`writeURLFetchType`, `writeInternetMessageDate` and
`writeListSelectBaseOptionQuoted` had no callers outside their own
encode tests, nor did the writers only they reached
(`writeAuthenticatedURL(NetworkMessagePath)`, `writeNetworkPath`,
`writeAbsoluteMessagePath`, `writeIUIDOnly`,
`writeURLMessageSectionOnly`, `writeMessagePathByteRangeOnly`). Delete
them and those tests; parse tests stay.

* Keep a section's trailing slash unless a partial follows

`imap://h/INBOX/;UID=1/;SECTION=1/` parsed with section `1`, so
`EncodedSection("1/")` didn't round-trip: the parser dropped the `/`
even when no `;PARTIAL=` followed it. Drop it only when one does.

* Reject `*` as a URL authentication type

`.type("*")` encoded as `;AUTH=*`, which parses as `.any`; `.type("*x")`
failed to parse, since `*` matched first.

RFC 5092: `iauth = ";AUTH=" ( "*" / enc-auth-type )`. `init?(_:)`
rejects `*`; the parser tries the longer `enc-auth-type` first.
2026-11-04 17:41:53 +00:00
Daniel Eggert 34883bcba6 Update style in documentation (#822) 2026-04-28 18:06:43 +02:00
Daniel Eggert 871d0122c9 Better docc comments (#815) 2026-04-16 09:20:29 -07:00
Matt Diephouse bffac522bd Make types Sendable (#767) 2024-09-02 13:56:13 +02:00
David Evans fe03b16eb1 Fix Hashable implementations across all types (#648)
Resolves #634

The majority of types that were Equatable are now Hashable.

Anywhere that we had a custom == and the type was also Hashable we also now have custom hash functions.
2021-12-10 13:58:41 +00:00
David Evans a66eeb228b Use SPI to remove underscored members (#567)
Resolves #556

We've talked quite a bit offline, and decided that for now @_spi is the way to go, as it avoids build system issues. The goal is to remove the number of underscored public types and fields.
2021-06-02 19:21:47 +01:00
David Evans ff1b31f5f3 Remove superfluous underscores. (#548)
Way too many things were underscored that really didn't need to be.
2021-04-13 10:48:34 +01:00
David Evans 53c2eefe72 Disable modification on protected fields after initialisation (#495)
* Use lets

* Fix warnings

* Warnings
2021-03-23 12:31:17 +00:00
David Evans 81c8e9158d Underscore EncodeBuffer (#479)
* Underscore

* Underscore everything

* Add soundness self insert
2021-03-18 11:25:05 +00:00
David Evans b1a1d7350c Documentation PR part 6 (#387)
* Document UseAttribute

* Document URLRumpMechanism

* Document URLFetchData

* Document UAuthMechanism

* Document StoreModifier

* Document SortData

* Document SequenceMatchData

* Document QResyncParameter

* Document SelectParameter

* Document SectionSpecifier

* Document SectionSpecifier.Part

* Document SectionSpecifier.Kind

* Document ResponseEncodingOptions

* Document ResponseEncodeBuffer

* Document EncodeBuffer

* Document EncodeBuffer.Chunk

* Document EncodeBuffer more.

* Document CommandEncodeBuffer

* Document ParserError

* Document ResponseParser

* Document CommandParser

* Document SynchronisingLiteralParser

* Remove public where it isn't needed

* Document write CommandStream

* Document write TaggedCommand

* Remove public from write functions

* Document FetchAttribute

* Document top-level Capability

* Documents Capability subtypes

* Document FullDateTime

* Document FullDate

* Document FullTime

* Document ContinuationRequest

* Document ListSelectOptions

* Document ResponseOrContinuationRequest

* Document Response

* Document FetchResponse

* Document StreamingKind

* Document ResponseText

* Document ResponseTextCode

* Document TaggedResponse

* Document TaggedResponseState

* Remove docs

* Document UntaggedStatus

* Document ScopeOption

* Document ReturnOption

* Document IServer

* Document InitialClientResponse

* Document AttributeFlag

* Document UIDValidity

* Document UIDSet

* Document UID

* Document EncodedAuthenticationType

* Document EncodedMailbox

* Document EncodedSearch

* Document EncodedSection

* Document EncodedURLAuth

* Document EncodedUser

* Document ResponseCodeAppend

* Document ResponsePayload

* Document SequenceNumber

* Document OptionValueComp

* Document QuotaLimit

* Document QuotaResource

* Document OptionVendorTag

* Document IPartial and remove IPartialOnly

* Document QuotaRoot

* Document ESearchResponse

* Document SearchCorrelator

* Document Address

* Document UIDRange

* Document IUID

* Document SearchModificationSequence

* Document SearchModificationSequenceExtension

* Document SearchReturnData

* Document SearchReturnDataExtension

* Document SearchReturnOption

* Document SearchReturnOptionExtension

* Document SequenceRange

* Document SequenceRangeSet

* Fix compile

* Document SequenceSet

* Document ParameterValue

* Define TaggedExtension

* Document AuthIMAPURL

* Document AuthIMAPURLFull

* Document AuthIMAPURLRump

* Document ChangedSinceModifier

* Document UnchangedSinceModifier

* Document CreateParameter

* Document EntryValue

* Document Expire

* Document FetchModifier

* Document FetchModificationResponse

* Document IAbsolutePath

* Document IAuth

* Document ICommand

* Document IMailboxReference

* Document MetadataValue

* Document IMAPURL

* Document MetadataOption

* Document MetadataResponse

* Document RelativeIMAPURL

* Document INetworkPath

* Document MechanismBase64

* Document IMessageList

* Document IMessageOrPartial

* Document IMessagePart

* Document IPathQuery

* Document ISection

* Document IRelativePath

* Document IUAVerifier

* Document IURLAuthRump

* Document IURLAuthRump

* Document IUserInfo

* Fix missing documentation

* Document CommandEncoder

* Fix sanity

* Update CommandDecoder.swift

* PR reviews
2020-12-11 17:14:37 +00:00
David Evans bf2067efd3 Implement IMAP URL (#326)
* Define UIDValidity

* IUID and PartialRange

* PartialRange parsing

* Implement IPartial types

* Parse UChar

* Support parsing various character types

* Define EncodedSection

* Define EncodedUser

* Define ISection

* Implement IMailboxReference

* Define Expire

* Define Access

* Define IURLAuthRump

* Define EncodedURLAuth

* Define IAuth

* Define IUserInfo

* Define IMessageList

* Define IMessagePart

* Define IServer

* Define UAuthMechanism

* Define IUAVerifier

* Define IUrlAuth

* Define AuthImapUrl

* Define Auth types and ICommand

* Define IAbsolutePath

* Define IPathQuery

* Define ImapUrl

* Define INetworkPath

* Define Imessage or partial

* Define IRelativePath

* Define ImapUrlRel

* Fix sanity

* PR review comments

* More PR review comments

* PR comments

* Final comments

* Fix sanity

* Throw is UID is 0

* Pr reviews

* Fix sanity

* Add month/day validation

* Fix preconditions
2020-10-07 21:11:56 +01:00