feat(imap): complete decoding for IMAP headers#280
feat(imap): complete decoding for IMAP headers#280toddheasley wants to merge 10 commits intothunderbird:mainfrom
Conversation
* Switch from custom scanning decoder; transpose to percent encoding, then use built in `NSString` decoding * Support multiple-encodings in same header
There was a problem hiding this comment.
Fetch attributes were scattered all over the floor; tidying into two canned presets:
[FetchAttribute].completefetches the complete message, including body and attachments.headerfetches all message headers, excluding body and attachments
There was a problem hiding this comment.
With the new presets for [FetchAttribute] sets, we can streamline the IMAPClient public fetching interface
| .threadID, | ||
| .uid | ||
| ]) | ||
| let messages: MessageSet = try await client.fetch() |
There was a problem hiding this comment.
Switch test to use [FetchAttribute] defaults
| return string | ||
| } | ||
|
|
||
| func decodingQuotedPrintable(to encoding: Encoding = .utf8) throws -> Self { |
There was a problem hiding this comment.
Completely changing quoted-printable decoding. Parser I wrote initially failed benchmarking; it didn't ignore/recover from bad encodings.
New strategy leverages the knowledge that quoted-printable is identical to (URL) percent-escaping, except for the control character. Swap control and escape characters, let Swift do a better job decoding...
| @@ -22,9 +22,14 @@ public struct Body: CustomStringConvertible, RawRepresentable, Sendable { | |||
| guard !parts.isEmpty else { | |||
| throw MIMEError.dataNotFound | |||
| } | |||
There was a problem hiding this comment.
Handle any body encoding, as long as header matches
| case .gmailMessageID(let id), .gmailThreadID(let id): "\(self.id): \(id)" | ||
| case .internalDate(let date): "\(id): \(date)" | ||
| case .uid(let uid): "\(id): \(uid)" | ||
| func merging(_ components: [Component]) -> Self { |
There was a problem hiding this comment.
Because IMAP messages are immutable, updates/changes are merged into a copy
Implement all additional
MIMEdecodings used by IMAP:String.headerDecoded; handle any combination of quoted-printable and base64 encodings in raw IMAP headersString.removingPercentEncodingMessageand integrate decoded dataClose #171; close #239