Skip to content

BUG: decodePart drops charset transform when Content-Type parse fails #1085

@andrinoff

Description

@andrinoff

Describe the bug

fetcher/fetcher.go:135-143:

mediaType, params, err := mime.ParseMediaType(header.Get("Content-Type"))
if err != nil {
    body, readErr := io.ReadAll(reader)
    if readErr != nil { ... }
    return string(body), nil
}

When Content-Type is malformed but a charset parameter would still have been parseable (or is implied), the fallback returns the raw bytes as a string with no charset transform. Non-UTF-8 emails (e.g. ISO-8859-1) render as mojibake.

Expected behavior

If parse fails, attempt a best-effort charset detection (or assume UTF-8 explicitly with transform.NewReader) instead of returning raw bytes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions