Skip to content

Fails to decode utf8 text in some cases #20

@wyllys66

Description

@wyllys66

In the odd event that an attachment has content-type like this:

Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

This may be an odd combination, but it is definitely out there in the wild and should be handled even if it is "non-standard"

The library tries to decode it as ".ascii" here:

guard let decoded = raw.data(using: .ascii) else { throw Error.decodingFailed }

Even though the content-transfer-encoding is specified as 7bit, the data is actually utf-8 and standard ascii decoding will fail.
The charset should possibly override the transfer encoding, or possibly the decoder could fall-back to trying .utf8 if the .ascii decode fails. For example:

     guard let decoded = raw.data(using: .ascii) else {
            raw.data(using: .utf8) else { throw Error.decodingFailed }
     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions