Commit Graph
23 Commits
Author SHA1 Message Date
Daniel Eggert dd881edcce 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.
2026-11-03 14:59:37 +01:00
AnthonyandDaniel Eggert d456d32908 Accept the responses a server may send during IDLE (#855)
Co-authored-by: Daniel Eggert <deggert@apple.com>
2026-10-13 17:08:26 +02:00
Christian 1c7076fab6 Fix framing of zero-length literals (#851) 2026-09-14 14:13:19 -07:00
Léon Simmons 79c4237b5c docs: fix typo in AuthenticationStateMachine comment (#832)
authentiction → authentication
2026-07-03 16:33:52 +02:00
Daniel Eggert 0eaa07f877 Fix cr-lf handling in FramingParser (#830) 2026-06-22 08:10:24 -04:00
Daniel Eggert efc0bfe244 Allow receiving untagged responses while appending (#799) 2025-06-11 13:52:48 -04:00
Daniel Eggert ae9498d7dd Fix receiving untagged responses during APPEND (#787) 2025-04-14 09:00:33 -07:00
Daniel Eggert 1b3dc9e1cd FramingParser can crash when single CR is inside DQUOTE string (#779) 2025-02-12 14:07:40 +01:00
Daniel Eggert a0441a53d3 FramingParser: Allow un-matched DQUOTE in lines (#776) 2024-12-18 08:45:59 +01: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
Matt Diephouse 7d0f2cf799 Mark final set of types as Sendable (#771) 2024-09-18 15:06:30 +02:00
Daniel Eggert c041371b50 Fix for receiving untagged response during SASL auth (#743) 2023-06-27 18:03:12 +02:00
Daniel Eggert 4fdfe749c8 Need to allow Response.fetch while in IDLE (#718) 2022-10-07 08:03:02 -07:00
Daniel Eggert d4597194eb FramingParser needs to handle “quoted” strings. (#704) 2022-08-26 17:21:28 +02:00
David Evans 69f15a10ba Convert line length limit to 8192 (#666)
Resolves #663

Convert the default limits from 1000 to 8192 octets, as per RFC 7162.
2021-12-23 13:36:54 +00:00
Daniel Eggert 737a79e04d FramingParser additions (#667)
Support appending a `UnsafeRawBufferPointer`. This is useful when the input is `Data` or `DispatchData`.

Add `inputBufferByteCount: Int` property -- which is useful for logging and tests.

Add `testTwoCommandsAcrossMultipleBuffers()` test case.
2021-12-23 14:23:34 +01:00
David Evans fd7cef174d Implement a new framing parser case while inside a literal (#646) 2021-12-09 16:45:03 +00:00
David Evans 1615507941 Implement FramingResult (#622)
This introduces FramingResult, which signals either a "complete" frame, "incomplete", or "invalid".

If a frame is incomplete then the minimum number of required bytes to make a complete frame are sent.

if a frame is invalid or complete then you are provided with the bytes in that frame.

Invalid frames are forwarded onto the user via user events.

It doesn't have many bells and whistles yet, but it handles a lot of use cases we'll see in the wild, and you'll probably still find it useful

Given the command A1 LOG it will delivered .incompleteFrame(2) to signal that this frame is incomplete, and that we need at least 2 more bytes (in this case the CR and LF) to complete the frame (this is because it doesn't have the ability to understand the login command fully as it's only used to build frames).

Given the command A1 LOGIN {3}\r\na it will deliver 2 frames:

.complete("A1 LOGIN {3}\r\n
.complete("a") this is a "complete" frame because we're streaming a literal, so need to forward all bytes as soon as possible
Finally a case of invalid, A1 LOGIN {a will deliver 1 frame containing the data, including the byte where we detected the issue: .invalid("A1 LOGIN {a")
2021-12-09 11:09:09 +00:00
David EvansandCory Benfield 275a907a86 Implement the beginnings of a framing parser (#614)
* Boilerplate

* Add extremely simple tests cases

* Basic literal support

* Add literal+, literal-, and binary support

* Fix backtracking

* Start some integration tests

* A few type renames

* Make the framer throwing

* Soundness

* Address some of Cory's comments

* More graceful handling or CRs and LFs

* Apple Cory suggestions part 2

* Swallow LF

* Make it all work

* Refactor

* Define LineFeedStrategy enum

* Refactor integer parsing and add frame status

* Digit constants

* Refactor adjusting frame length

* Defend against infinite size

* Fix literal bugs

* Soundness

* Add some docs

* Update Sources/NIOIMAP/Client/FramingParser.swift

Co-authored-by: Cory Benfield <lukasa@apple.com>

* Prefer () over break

* Use UInt64 where appropriate

* Implement a stepback function

* Fix FrameSatus typo

* Don't allocate 2 buffers

* Rename LiteralSubstate to LiteralHeaderState

* Use Float64

* Remove frame debugging function

* Fix empty frame logic

* Discard empty bytes

* Fix handing optional LF in a literal

* Soundness

* Remove random Darwin import

* Cory nits

* Discard when we've read over half the buffer

* Read at least 1KB before cleaning

* Soundness

* Fix precondition

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-09-15 16:38:03 +01:00
David Evans 59a57ee70b New client state machine (#610)
The client state machine has now been fully rewritten, and encapsulates the miniature state machines implemented in previous PRs.

I've extracted the state machine from IMAPClientHandler and moved it into ClientStateMachine, hence all the code deletion.

The state machine receives a command, response, or continuation request from the IMAPClientHandler and returns an array of Chunk/EventLoopPromise pairs that the client handler should then write to the network.

Also we didn't previously queue Append commands like we did for others, however it's now become apparent that all commands types should be queued, so we do that now.

A lot of tests have been added to make sure everything works.

Note that a lot of sendCommand tests have been deleted as we now precondition on user errors instead of throwing.
2021-09-10 13:45:11 +01:00
David Evans 9484279fe6 Add Append support to new client state machine (#595)
Identical pattern to that used for IDLE and AUTHENTICATE. The main ClientStateMachine detects the append command being sent, and switches state to contain a sub-machine that is dedicated to validating the lifecycle of an append command.

We support "standard" message appends, as well as catenation, and continuation requests for both.
2021-07-28 17:18:53 +01:00
David Evans d49bbc1968 New state machine authentication flow (#587)
Add support for authentication to the new client state machine, with a typical workflow test, and a test to show that attempting to send another command while authenticating will result in an error.
2021-07-20 13:30:40 +01:00
David Evans d7db35c768 New state machine with boilerplate for IDLE command (#586)
NOTE: The many defaults used when switching over things is just because this is an example. If we're happy with how this looks, I'll remove them and handle properly.

This is a basic demonstrative implementation of the new client state machine that shows how the IDLE command is supported.

For an idle state to be established, the client needs to send the idleStart command, and the server needs to respond with a continuationRequest, at which point the state is idle.
2021-07-19 14:58:44 +01:00