34 Commits
Author SHA1 Message Date
Daniel Eggert b2c94a8bce Only skip an orphaned LF after a response-ending CR (#882) 2026-11-10 17:49:13 +01:00
Daniel Eggert 4606da62d2 Validate response text, command tags and namespace delimiters (#866)
* Reject invalid response text when writing

`.no(.init(text: "No mailbox x\r\n* BYE pwned"))` was written verbatim,
injecting an untagged response; likewise tagged, BYE, PREAUTH and
continuation responses.

RFC 9051: `text = 1*(TEXT-CHAR / UTF8-2 / UTF8-3 / UTF8-4)`. `writeText`
now asserts no NUL, CR or LF. Empty stays valid. The parser now accepts
UTF-8 text.

* Add Command.Tag for command and response tags

`TaggedCommand(tag: "A1 NOOP\r\nA2 DELETE INBOX\r\nA3", command: .noop)`
was written verbatim, injecting a command; likewise `APPEND` start.
`TaggedResponse(tag: "* BYE x\r\nA1", …)` injected a response.

RFC 3501: `tag = 1*<any ASTRING-CHAR except "+">`. New `Command.Tag`
replaces the `String` in `TaggedCommand`, `TaggedResponse`, `Response`,
`CommandStreamPart`, `AppendCommand`, `BadCommand` and NIOIMAP's state
machine errors; `init?(_:)` validates, literals trap. The parser already
enforces the production. IMAPCommands converts its numeric tags.

* Validate and escape namespace delimiters

`NamespaceDescription(string: "x", char: "\r\n", …)` wrote a raw CRLF
inside `"…"`, injecting a response. `"\""` encoded as `"""`, and `"\\"`
as `"\"` (unterminated); non-ASCII was accepted.

RFC 2342: `DQUOTE QUOTED-CHAR DQUOTE / nil`. `init(string:delimiter:
responseExtensions:)` (was `char:`) throws `InvalidDelimiterError` for
non-ASCII, CR, LF, NUL; the delimiter is stored as a byte, read-only.
Quoted-specials are escaped on write and parsed when escaped.

* Gate a capturing exit test on Swift 6.3
2026-11-04 17:41:52 +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
Daniel Eggert e466da1b68 Inbound buffer split (#812) 2026-03-09 08:50:04 -04:00
Franz Busch 2cd1c5582a [CI] Adopt GitHub Actions (#775)
* [CI] Adopt GitHub Actions

# Motivation

We want to adopt GitHub actions in all of our Swift repositories to replace our current Jenkins CI.

# Modification

This PR adopts the reusable workflows from NIO and the swiftlang organization to ensure soundness and test coverage. Additionally, this PR enables a sematic label check and adds a `release.yml` to make releasing this package easy.

# Result

Modern CI and release flow.
2024-10-30 13:24:35 +00:00
Daniel Eggert fc6524ab8d Allow non-ASCII values in BODYSTRUCTURE parameters (#739) 2023-04-19 18:26:48 +02:00
carolinacass cab8fef8a7 Use #fileID/#filePath instead of #file (#722)
Motivation:

Modifications:

Changed #file to #filePath or #fileID depending on situation
2022-11-03 15:50:37 +00:00
Daniel Eggert 692f4ed85d Fix stack exhaustion due to recursion (#698) 2022-05-18 15:25:54 +02:00
Daniel Eggert a0e9de1952 Allow single CR to be a newline (#670) 2022-01-03 10:35:56 +01: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 3719201015 New failable String.init for validating if bytes are valid UTF8 (#563)
We use String(buffer: ByteBuffer) quite a lot. This isn't ideal as it may crash if the bytes are not valid UTF-8. This PR addresses that problem by providing a failable initialiser on String that will handle invalid UTF8 bytes gracefully by returning nil.
2021-05-21 12:23:53 +01:00
David Evans 10bdc22671 Replace KeyValues with OrderedDictionary from swift-collections (#546)
* Add swift-collections

* Delete KeyValues

* Soundness

* Fix comment
2021-04-14 10:05:06 +01:00
David Evans 38b4ceda9a More performance improvements (#515)
* parseTaggedResponseState

* parseUntaggedResponseStatus

* parseMessageAttribute

* Fix

* Soundness

* Uncomment tests

* Soundness
2021-04-07 11:50:14 +01:00
David Evans 22b38c56ed Parser cleanup (implement shortcut methods, use new parse oneOf) (#509) 2021-03-31 11:21:34 +01:00
David Evans 94e3fb42f5 Update dependencies (#493)
* Update packages

* Run swift format

* Update
2021-03-23 17:21:41 +00:00
8b9c01a6ba Servers now can send authentication challenges (#505)
* Servers now can send authentication challenges

* Soundness

* Fix tests

* Change to use Response

* Docs

* Soundness

* work around SR-14394

* Update Sources/NIOIMAPCore/Grammar/Response/Response.swift

Co-authored-by: Daniel Eggert <daniel.eggert@hoerbuch.dk>

* Fix compile on 5.2

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
Co-authored-by: Daniel Eggert <daniel.eggert@hoerbuch.dk>
2021-03-23 16:33:36 +00:00
David Evans f1e7faa75f Propagate command tag on parsing error (#500)
* Propagate command tag on parsing error

* Soundness

* Docs

* Fix tests
2021-03-23 10:04:16 +00:00
David Evans a486ea30d4 Support parsing an extra space after flags (#481)
* Support parsing an extra space

* Move to parseFixedString

* Soundness

* Oops, wrong place

* Rename space

* Soundness
2021-03-16 13:18:11 +00:00
Johannes Weiss be9c737a29 restore separation of parser & parser library (#468) 2021-03-11 16:56:08 +00:00
David Evans 33d6060046 Final key value refactor (#432)
* Remove a load of parameter types

* Remove NameSpaceResponseExtension

* Remove SearchModificationSequenceExtension

* Remove SearchReturnDataExtension

* Remove SearchReturnOptionExtension

* Soundness
2021-02-05 12:09:00 +00:00
David Evans f056b14fa6 Refactor out ID parameter and replace with new KeyValues type (#424)
* Add conveniences

* Make iteratable

* Add ID example

* Add docs

* Converting backing to KeyValue struct

* Fix soundness
2021-02-01 18:12:12 +00:00
David Evans 135f473bf6 Documentation PR part 5 (#383)
* 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

* PR review

* Fix sanity

* Document FullDate
2020-12-10 12:37:05 +00:00
David EvansandGeorge Barnett 78b55555bf Add some documentation (#341)
* Fix documentation

* Remove link to NIO http 2

* Document TooDeep error

* Remove ParsingError

* Make GrammarParser non-public

* Better UTF7 errors

* Document Access

* Document CommandStream types

* Partially document `Command`

* Document date

* Document Access

* Update Sources/NIOIMAPCore/Grammar/Date/Date.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* Update Sources/NIOIMAPCore/Grammar/Access.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* Update Sources/NIOIMAPCore/Grammar/Command/CommandStream.swift

Co-authored-by: George Barnett <gbarnett@apple.com>

* Fix typo

Co-authored-by: George Barnett <gbarnett@apple.com>
2020-10-26 09:54:46 +00:00
David Evans 1f9658005f Refactor parsing (#321)
* Refactor parse space

* Refactor parse fixed string

* Refactor parseOneOf

* Refactor parseOptional

* Refactor parseComposite

* Refactor parseNewline

* Fix sanity

* Rebase fixes
2020-09-28 13:22:10 +01:00
Cory Benfield 0198813b9c Add support for Gmail extensions (#312)
Motivation:

Gmail has a couple of common extensions to the IMAP specification for
Gmail specific features. It'd be good to support them. This patch adds
support for the most important three: Gmail message ID, Gmail thread ID,
and the Gmail label functionality.

Modifications:

- Added new Fetch and Message attributes for the three Gmail extensions.
- Added parsing and serialization support.

Result:

Users can interact with Gmail-specific features.
2020-09-16 17:30:12 +01:00
David Evans fd3e16ad49 Implement RFC 6154 SPECIAL-USE (#303)
* Implement

* Tests for new types

* Tests

* Fix

* Fix tests

* Fix sanity

* Fix warnings

* Silence warnings
2020-09-08 11:25:48 +01:00
David Evans 6716144eb4 Be more lenient when parsing spaces (#238)
* Update space parser

* Remove typo

* Extra tests

* Fix parsing spaces

* Re-add missing tests

* Fix sanity
2020-07-06 18:55:55 +01:00
Daniel Eggert 7bb7916a1a Allow space before newline (for CAPABILITY). (#233)
See also: #232
2020-06-30 11:23:11 +01:00
David Evans a06b3898aa Hide incomplete message errors (#135)
* Hide incomplete message errors

* Fix sanity

* Throw error

* Fix rebase

* Refactor

* Log not throw

* Improve roundtrip handler

* Fix sanity

* Update comments

* Remove error case

* Logging

* PR review

* Simplify loop

* Use NIOSinglestep...

* Fix sanity

* Even more efficiency

* Fix sanity
2020-05-28 13:49:11 +01:00
David EvansandJohannes Weiss 042d11fe17 Add B2MD tests for most commands/responses (#125)
* Move tests to dedicated file

* Add NOOP tests

* Add capability tests

* Add logout tests

* Add starttls tests

* Add select tests

* Add examine tests

* Fix sanity

* Add create tests

* Add delete tests

* Fix sanity

* Add subscribe tests

* Add unsubscribe tests

* Add missing test file header

* Add check tests

* Fix sanity

* Rebase

* Add list tests

* Add LSUB tests

* Add status tests

* Add append tests

* Setup response tests

* Allow response parse mode override

* Temp remove append

* Conditional state tests

* Bye tests

* Capability tests

* Flags tests

* Exists tests

* Recent tests

* Expunge tests

* Tagged response tests

* List, LSUB, and status tests

* Comment everything

* Make tests use synchronizing literals

* Replace CRLF

* Test fetch responses

* Fix sanity

* Assert

* Refactor error catching

* Test that breaks synchronising literals

* fix some stuff

* Fix sanity

* Fix all the things

* Fix sanity

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-05-20 17:40:56 +01:00
David Evans 28225ece7d Remove NIOIMAP namespace 2020-05-09 14:46:42 +01:00
tomer doron 53efab1d95 standardize format (#80)
motivation: use standard format across all of our projects

changes:
* add .swiftformat settings based on what we use in other projects
* validate format in the sanity script
* format
2020-04-24 12:05:17 +01:00
David Evans 19ecdb9576 Seperate module (#61) 2020-04-20 12:41:39 +01:00