# `Plover.Content`
[🔗](https://github.com/codonnell/plover/blob/main/lib/plover/content.ex#L1)

Content-Transfer-Encoding decoding and charset conversion for email body parts.

Decodes base64 and quoted-printable transfer encodings as specified in
RFC 2045, and converts common charsets to UTF-8 using only OTP stdlib.

## Examples

    # Decode base64 content
    {:ok, binary} = Plover.Content.decode(raw, "BASE64")

    # Decode quoted-printable with charset conversion
    {:ok, text} = Plover.Content.decode(raw, "QUOTED-PRINTABLE", "ISO-8859-1")

    # Decode and convert in one step
    {:ok, utf8_text} = Plover.Content.decode(raw, "BASE64", "Windows-1252")

# `convert_charset`

```elixir
@spec convert_charset(binary(), String.t()) :: binary()
```

Convert binary data from the given charset to UTF-8.

Supported charsets: UTF-8, US-ASCII, ISO-8859-1 (Latin-1), Windows-1252.
Unknown charsets return the data unchanged.

# `decode`

```elixir
@spec decode(binary(), String.t()) :: {:ok, binary()} | {:error, term()}
```

Decode content using the specified transfer encoding.

Supported encodings: `"BASE64"`, `"QUOTED-PRINTABLE"`, `"7BIT"`, `"8BIT"`, `"BINARY"`.
Encoding names are case-insensitive.

# `decode`

```elixir
@spec decode(binary(), String.t(), String.t()) :: {:ok, binary()} | {:error, term()}
```

Decode content using the specified transfer encoding, then convert
from the given charset to UTF-8.

# `decode_base64`

```elixir
@spec decode_base64(binary()) :: {:ok, binary()} | {:error, term()}
```

Decode base64 encoded data. Whitespace (line breaks) is ignored.

# `decode_encoded_words`

```elixir
@spec decode_encoded_words(String.t() | nil) :: String.t() | nil
```

Decode RFC 2047 encoded-words in a header value.

Encoded-words have the form `=?charset?encoding?text?=` where encoding is
`B` (base64) or `Q` (quoted-printable with `_` for space). Adjacent
encoded-words separated only by whitespace are concatenated per RFC 2047
Section 6.2.

Returns the decoded string. Passes through `nil` and plain strings
that contain no encoded-words.

# `decode_quoted_printable`

```elixir
@spec decode_quoted_printable(binary()) :: {:ok, binary()} | {:error, term()}
```

Decode quoted-printable encoded data per RFC 2045 Section 6.7.

- `=XX` hex pairs are decoded to the corresponding byte
- Soft line breaks (`=\r\n` or `=\n`) are removed
- All other characters pass through unchanged

---

*Consult [api-reference.md](api-reference.md) for complete listing*
