Commit Graph
258 Commits
Author SHA1 Message Date
Daniel Eggert b838dc2206 Pass response parser options into IMAPClientHandler.init (#789) 2025-05-06 15:30:31 +02:00
Daniel Eggert a941316af3 Fix parsing of NIL for RFC 7889 APPENDLIMIT (#782) 2025-04-04 11:06:20 -07: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 7328a733b4 Be more lenient about spaces in RFC 2971 ID response (#774) 2024-10-24 09:43:03 -04:00
Matt Diephouse 7d0f2cf799 Mark final set of types as Sendable (#771) 2024-09-18 15:06:30 +02:00
Daniel Eggert 13cf165aaf Implement RFC 7889 “APPENDLIMIT” (#769) 2024-09-03 14:49:41 +02:00
Matt Diephouse bffac522bd Make types Sendable (#767) 2024-09-02 13:56:13 +02:00
Daniel Eggert 2b6d728191 Fix correctly parsing incomplete, invalid BODYSTRUCTURE data (#762) 2024-07-29 10:54:53 -04:00
Matt Diephouse 49af890114 Parse PARTIAL data returned from UID SEARCH (#761) 2024-07-10 09:56:25 -04:00
Daniel Eggert 0040533b67 Add support for MESSAGELIMIT Extension (#760) 2024-06-20 09:04:10 -07:00
Massimo OlivieroandDaniel Eggert b9a6a88f92 Add support for RFC 8970 — Message Preview Generation (#751)
Co-authored-by: Daniel Eggert <deggert@apple.com>
2024-06-10 11:54:40 -07:00
Daniel Eggert 373a95435a Skip BODYSTRUCTURE data when literal size limit is exceeded (#759) 2024-06-10 09:14:08 -04:00
Daniel Eggert 342a2c695f Add support for RFC 9586 “Using and Returning UIDs Only” (aka. UIDONLY) (#758) 2024-06-10 09:55:46 +02:00
Daniel Eggert e45aa3283f Skip invalid BODYSTRUCTURE in server responses (#757) 2024-04-20 19:16:38 +02:00
Daniel Eggert 14ac21ddb9 Include actual and limit values in errors (#754) 2024-04-18 19:27:22 +02:00
Massimo Oliviero c04c4aa3f7 Fix envelope multiple addresses parsing (#752) 2024-04-18 14:18:25 +02:00
Daniel Eggert fe1e2beb15 Fix compiler warnings for Swift 5.9 (#756) 2024-04-17 07:13:17 -04:00
Daniel Eggert 0d951a6d57 IMAP Paged SEARCH & FETCH Support (#746) 2023-07-21 14:22:32 -07:00
Daniel Eggert 39b1902c5d 2nd part of renaming Partial → ByteRange (#745) 2023-07-20 14:31:51 -07:00
Matt Diephouse 9716083dce Fix parser error with continuation responses (#742)
When the response text of a continuation response began with base64 characters, the response would be interpreted as base64. Any remaining characters would cause a parser error.

Rework the parser to only interpret the text as base64 if all of the text is base64 characters.
2023-06-14 08:08:29 -04:00
Daniel Eggert 8851fdb73b Fix for stray + in response. (#740) 2023-05-24 09:22:53 -04:00
Daniel Eggert fc6524ab8d Allow non-ASCII values in BODYSTRUCTURE parameters (#739) 2023-04-19 18:26:48 +02:00
Daniel Eggert 89777af885 Fix parsing Gmail labels as flags (#738) 2023-04-18 14:57:40 +02:00
Daniel Eggert 01577b28be Rename Partial → ByteRange (#736) 2023-03-31 21:03:13 +02:00
Matt Diephouse cc3b72e93f Parse INTERNALDATEs without a leading digit or space (#735) 2023-03-08 16:49:13 +01:00
Daniel Eggert c25047fc0c Use enum for ExtendedSearchResponse UID vs. sequence number (#733) 2023-02-22 19:45:58 +01:00
Daniel Eggert 511d4e799d Fix parsing response codes (#730) 2023-02-19 10:10:12 +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 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 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 692f4ed85d Fix stack exhaustion due to recursion (#698) 2022-05-18 15:25:54 +02: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 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
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
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
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
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
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 433f08bdc2 Rename modificationSequence to modification (#649)
Resolves #604

Rename modificationSequence to just modified as it might not contain SequenceNumbers. Also change the associated type from SequenceSet (aka MessageIdentifierSet<SequenceNumber>) to UnknownIdentifier, which can then be treated as either UIDs or SequenceNumbers depending on what the user is expecting.

(Note this is required as it is impossible to distinguish between SequenceNumbers and UIDs when parsing).
2021-12-10 15:02:57 +00: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