Commit Graph
414 Commits
Author SHA1 Message Date
Daniel Eggert e8bb770d00 Only include CHARSET in search when there’s text (#723) 2022-12-09 15:28:23 +01: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 8abe89882e Allow NIL response for a particular body section (#720) 2022-10-27 16:40:58 +02:00
Daniel Eggert 945f0d664c Remove MessageAttribute.binary (#721)
This is (already) being handled by `FetchResponse.streamingBegin` / `StreamingKind`.
2022-10-27 10:24:13 +01:00
Daniel Eggert 25392460d4 Improve documentation for SectionSpecifier.Kind (#719) 2022-10-25 16:52:25 +01:00
Daniel Eggert 4fdfe749c8 Need to allow Response.fetch while in IDLE (#718) 2022-10-07 08:03:02 -07:00
Daniel Eggert fc46347a85 Clean up RFC 2045 “media type” in BodyStructure (#717)
Each “part” in a `BodyStructure` has an RFC 2045 “media type” — which is a combination of “top level type” + “sub-stype”.

But the types that were previously used, were inconsistently used / named. This PR cleans up the use of these and makes them consistent.

Additionally it adds a
```swift
extension BodyStructure {
    public var mediaType: Media.MediaType
}
```
such that it’s easy to get to a part’s media type, regardless of its kind.
2022-10-06 15:49:55 +02:00
Daniel Eggert 6eb8a70b2c More BodyStructure / SectionSpec convenience (#715) 2022-10-04 16:58:35 +01:00
Daniel Eggert 58236520fa Fix BodyStructure’s RandomAccessCollection conformance (#714) 2022-09-12 17:24:26 +02:00
Daniel Eggert ad85d4a0cc Cleanup CustomDebugStringConvertible conformance (#713)
With this PR the implementation of `CustomDebugStringConvertible` generally uses new `makeDescription` convenience methods on the three encode buffers, e.g.:
```swift
extension ResponseEncodeBuffer {
    static func makeDescription(_ closure: (inout ResponseEncodeBuffer) -> Void) -> String
}
```
such that conformance can be implemented as e.g.
```swift
extension Command: CustomDebugStringConvertible {
    public var debugDescription: String {
        CommandEncodeBuffer.makeDescription {
            $0.writeCommand(self)
        }
    }
}
```

This also adds `CustomDebugStringConvertible` to `MessageAttribute` and `StreamingKind`.
2022-09-10 12:35:32 +02:00
Daniel Eggert cc1a03dd73 Use SE0270_RangeSet instead of StandardLibraryPreview (#707) 2022-09-05 09:25:45 +01:00
Daniel Eggert 4319190212 Remove NIOIMAPFormatter (#712)
With #711 the formatter is part of the Docker image.
2022-09-05 09:25:07 +01:00
Yim Lee d3c18350c7 CI updates (#711)
* CI updates

- Add SwiftFormat
- Add CI for Swift nightly
2022-09-05 08:00:34 +02:00
Daniel Eggert d4597194eb FramingParser needs to handle “quoted” strings. (#704) 2022-08-26 17:21:28 +02:00
Daniel Eggert 194947ceb2 “MIME” is not a valid section specifier (without a part) (#703)
Don’t crash. Throw parsing error.
2022-08-24 11:37:28 +02:00
Daniel Eggert 4ab3b2bd0f Fix crash when parsing invalid mod-seq (#702)
Modification sequence numbers need to be in the range 0-Int64.max (63 bit unsiged values). When parsing, use the failing initializer, instead of the one with a `precondition()`.
2022-08-24 10:33:50 +01:00
Daniel Eggert 04d504c533 CommandParser needs to accept single CR as valid newline. (#701)
The `FramingParser` might split a `CRLF` lineline into `CF` only (`LF` in the “next frame”). The `CommandParser` thus needs to be able to parse
```text
A26 UID FETCH 1:10002 (UID FLAGS MODSEQ)\r
```
as a valid and complete command.
2022-08-03 16:26:34 +02:00
Daniel Eggert c2e9712c95 Make ResponseText conform to CustomDebugStringConvertible (#700) 2022-07-06 19:06:49 +02:00
Daniel Eggert 692f4ed85d Fix stack exhaustion due to recursion (#698) 2022-05-18 15:25:54 +02:00
Daniel Eggert 040df6a6c6 Make conversion between MessageIdentifierSet variants public (#697)
This also renames some files and move some code around — to make the UID / SequenceNumber / UnknownMessageIdentifier split clearer.
2022-04-19 18:10:09 +02:00
Daniel Eggert 010167d33e Pre-calculate MailboxName hash value (#696)
Since it’s common to use `MailboxName` as a key in a dictionary and/or compare `MailboxName` for equality, `MailboxName` will pre-calculate its hash value, and store it. As a result `Hashable` (and `Equatable`) performance is very fast.
2022-03-22 11:32:47 +00:00
David Evans db41f78ec4 Fix a crash when parsing envelope address groups (#695)
Found by Mail during the live-on program.

The issue was caused by a "completely nil" address, which we take to mean the end of an envelope group (as per rfc 2822). A completely nil address is valid on its own, without being part of a group, however we assumed that it would always denote the end. If a group hadn't previously been started then we'd crash.

Fix by checking if we have a group on top of the stack when attempting to compile individual addresses into groups.

Also added a test case to prevent regression.
2022-03-21 16:53:55 +00:00
Daniel Eggert 6c256a6baf Add support for encoding custom commands (#693)
This _only_ handles _encoding_ of custom commands.

This simply adds a
```swift
case custom(name: String, payloads: [CustomCommandPayload])
```
such that clients of this library do their own encoding of such commands.

This is related to the discussion in #92
2022-02-20 23:04:36 -08:00
David Evans 82c191e47a Update swift format (#691) 2022-02-19 10:24:55 +01:00
Daniel Eggert 3726eb0fa5 Fix RFC 4731 vs. RFC 3501 style search commands (#688)
The existing code was not able to differentiate between

A1 SEARCH ANSWERED
A1 SEARCH RETURN () ANSWERED
commands. The former is an RFC 3501 style search, the latter an RFC 4731 style search.

RFC 3501 does not allow for any RETURN options.

With this PR, those get mapped to

public enum Command: Hashable {
    ...
    case search(key: SearchKey, charset: String? = nil, returnOptions: [SearchReturnOption] = [])
such that returnOptions are empty for RFC 3501 style searches, wheras RFC 4731 style searches will always contain at least one element.

Note that RETURN () is a shorthand for RETURN (ALL), and as such gets mapped to [.all].

This is called out in the comments for Command.search.

Also

The SearchCorrelator’s tag is now a String to align with TaggedCommand’s tag.

SearchReturnData now uses UnknownMessageIdentifier instead of Int for min and max.
2022-02-18 21:14:22 -08:00
Matt Diephouse 7895f7166f Remove multipart/ from the String value of BodyStructure.MediaSubtypes (#687) 2022-02-14 16:10:36 +01:00
Daniel Eggert 0ccc3a2932 Fix parsing escapes in “quoted” strings (#686) 2022-02-10 17:11:48 +01:00
David Evans 9c2c43f0a3 Add support for nil encoding to address iCloud issues (#685)
Resolves #684

iCloud is sending nil for message encoding types, which isn't allowed according to the spec. That said, we have to support it regardless, so we now support nil for the message encoding.

Also added some body parsing tests as there apparently weren't any "combined" ones like this. Additionally as there are multiple ways of saying "multipart/mixed" and other "multipart/*" subtypes, we now check and merge them.
2022-02-09 16:16:20 +00:00
Daniel Eggert 879c1bff09 Fix Log Redaction of PII (#683) 2022-02-07 17:35:50 +01:00
Daniel Eggert bb0e803d99 UID convenience (#682) 2022-02-04 15:21:13 +01:00
Daniel Eggert 4954dc6bef Make UnknownMessageIdentifier conversion public (#680)
Need to be able to access these.
2022-02-01 10:27:42 +00:00
David Evans 8ac6696b3c Implement encoding logging mode for redaction (#678)
Resolves #662

Command/Response Encoder can be configured using loggingMode. If turned on then user-sensitive strings won't be encoding, but any metadata will.

For example, 1 LOGIN username password becomes 1 LOGIN "" "", thereby hiding the user's information.
2022-01-26 15:50:12 -08:00
David Evans 480785353a Add literal size limit (#671) 2022-01-26 12:07:49 +01:00
David Evans 4e7e11cb3a Use UnknownMessageIdentifier in MailboxData.Search. (#677) 2022-01-25 09:00:45 +01:00
Daniel Eggert 6d7fc4cf25 Always encode non-synchronizing literal with + (#676)
RFC 7888, section 5 says:
> Note that the form of the non-synchronizing literal does not change: it still uses the "+" in the literal itself, even if the applicable extension is LITERAL-.
2022-01-24 19:30:38 +01:00
Daniel Eggert 2caea0cf64 Make MessageIdentifierSet.RangeView conform to RandomAccessCollection (#673) 2022-01-18 16:52:28 +01:00
David Evans 81718846da Implement a string parsing cache (#672)
Resolves #669

Maintaining many versions of the same string can be expensive for strings over a given size (10 bytes), where they become heap-allocated. For example, in IMAP there may be many thousands of messages with the same flags (e.g. deleted, seen, replied).

Here we introduce a user-controllable cache that allows the user to provide a single instances of some strings if they require. Whenever we parse an atom (i.e. a string), that string is passed to the cache (which defaults to just returning the string), which may then return a cached version.
2022-01-10 14:52:33 +00:00
Daniel Eggert a0e9de1952 Allow single CR to be a newline (#670) 2022-01-03 10:35:56 +01:00
David Evans a6f3cd5924 Enable limiting the number of fetch attributes and body size (#665)
Resolves #402

To prevent a massive amount of fetch attributes from being sent maliciously, the parser now supports a configurable limit on how many fetch attributes are allowed. If this limit is exceeded then an error is thrown.

Added some tests to show that this works for both "simple" attributes, and ones that involve streaming.
2021-12-23 13:54:05 +00: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 c4d572029e Make grammar parser non-static (#661)
The static grammar parser has served us well and has been very easy to use. Sadly, however, the time for static to die has arrived, as we now need the parser to be configurable with certain limits (e.g. maximum supported message body size).

This is kind of simple, just remove static from everywhere, and then use instances of the parser instead of calling the static methods.

It is massive though, sorry.
2021-12-17 10:54:34 +00:00
David Evans 4411870711 Use proper store modifiers (#660)
Resolves #656

The UID STORE command takes an OrderedDictionary argument for the modifiers. This is both inconvenient and technically incorrect as it doesn't store the right kind of data.
2021-12-15 15:41:42 +00:00
Daniel Eggert 76a25fa7ff Don’t output empty fetch modifiers. Fixes #658 (#659) 2021-12-14 16:11:33 +01:00
Daniel Eggert c2628c0721 Fix ResponseTextCode.modified convenience init (#657)
Was generating an empty set instead of converting the UID set.
2021-12-14 11:39:16 +00:00
Daniel Eggert 11bff712e2 Make ResponseTextCode indirect (#655)
Without indirect codegen would create very inefficient code that could exhaust the stack.
2021-12-14 10:22:47 +00:00
David Evans 6382eba97e Actually use fetch modifiers (#654)
Resolves #603

We previously defined FetchModifier, but forgot to use them in the fetch command.

Now they're actually used.
2021-12-13 17:30:51 +00:00
David Evans d487e39d8a Add conversions from UnknownMessageIdentifier wrappers to UID/SequenceNumber types (#653)
Resolves #652

MessageIdentifierSet<UnknownMessageIdentifier> <-> MessageIdentifierSet<UID>
MessageIdentifierSet<UnknownMessageIdentifier> <-> MessageIdentifierSet<SequenceNumber>
MessageIdentifierRange<UnknownMessageIdentifier> <-> MessageIdentifierRange<UID>
MessageIdentifierRange<UnknownMessageIdentifier> <-> MessageIdentifierRange<SequenceNumber>
2021-12-13 15:56:40 +00:00
Daniel Eggert 2b3149e4a7 Disallow directo conversion between SequenceNumber and UID (#651)
With this, you’d have to explicitly go through UnknownMessageIdentifier.
2021-12-13 10:33:48 +00:00
Daniel Eggert 17b0f8e467 Add isContiguous to MessageIdentifierSet (#650)
With the recent changes to message identifier set it’s no longer possible to access the range count, but we’d only ever need that to calculate isContiguous. Moving this into NIOIMAPCore seems like the better approach.
2021-12-13 10:33:35 +00:00