purebred-email-0.6: types and parser for email messages (including MIME)
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.MIME.Charset

Description

MIME character sets.

Recognised charsets:

  • us-ascii / iso646-us
  • utf-8
  • iso-8859-1

See also the purebred-icu plugin, which adds support for many character sets.

Synopsis

Documentation

class HasCharset a where Source #

Minimal complete definition

charsetName, charsetData, charsetDecoded, charsetEncode

Associated Types

type Decoded a Source #

Methods

charsetName :: Getter a (Maybe CharsetName) Source #

Get the declared (or default) character set name. There is no guarantee that it corresponds to a registered or supported charset.

charsetData :: Getter a ByteString Source #

Return the encoded data in the structure

charsetDecoded :: AsCharsetError e => CharsetLookup -> forall p f. (Profunctor p, Contravariant f) => Optic' p f a (Either e (Decoded a)) Source #

Structure with the encoded data replaced with Text

charsetDecoded' :: CharsetLookup -> forall p f. (Profunctor p, Contravariant f) => Optic' p f a (Either CharsetError (Decoded a)) Source #

Structure with the encoded data replaced with Text (monomorphic error type)

charsetEncode :: Decoded a -> a Source #

Encode the data

Instances

Instances details
HasCharset ByteEntity Source #

RFC 6657 specifies that each subtype of the text media type can define its own default value for the charset parameter, including the absense of any default. It can also specify that the charset information is transported inside the payload (such as in text/xml. Behaviour for common media types includes:

text/plain
Default: us-ascii (RFC 6657)
text/csv
Default: utf-8 (RFC 7111)
text/markdown
No default; charset parameter is REQUIRED (RFC 7763)
text/enriched
Default: us-ascii (RFC 1896)
text/rtf
Decoded as us-ascii. Serialised RTF must be 7-bit ASCII, with the character set declared in the payload. Decoding RTF is outside the scope of this library. See https://www.iana.org/assignments/media-types/text/rtf.
Instance details

Defined in Data.MIME

Associated Types

type Decoded ByteEntity Source #

HasCharset EncodedParameterValue Source #

The default charset us-ascii is implied by the abstract of RFC 2231 which states: /This memo defines … a means to specify parameter values in character sets other than US-ASCII/.

When encoding, 'utf-8' is always used, but if the whole string contains only ASCII characters then the charset declaration is omitted (so that it can be encoded as a non-extended parameter).

Instance details

Defined in Data.MIME.Parameter

Associated Types

type Decoded EncodedParameterValue Source #

charsetText :: (HasCharset a, AsCharsetError e, Profunctor p, Contravariant f) => CharsetLookup -> Optic' p f a (Either e Text) Source #

Decode the object according to the declared charset.

charsetText' :: (HasCharset a, Profunctor p, Contravariant f) => CharsetLookup -> Optic' p f a (Either CharsetError Text) Source #

Monomorphic in error type

charsetPrism :: forall a. HasCharset a => CharsetLookup -> Prism' a (Decoded a) Source #

Prism for charset decoded/encoded data. Information about decoding failures is discarded.

defaultCharsets :: CharsetLookup Source #

Supports US-ASCII, UTF-8 and ISO-8859-1, UTF-16[BE|LE] and UTF-32[BE|LE]. The purebred-icu package provides support for more charsets.

decodeLenient :: ByteString -> Text Source #

Decode as UTF-8, replacing invalid sequences with placeholders.