package pecu

  1. Overview
  2. Docs
Encoder/Decoder of Quoted-Printable (RFC2045 & RFC2047)

Install

Dune Dependency

Authors

Maintainers

Sources

pecu-v0.4.tbz
sha256=77d3ce3b785257acce0b62d75db647707ad70b622f48f3c7b6109911d03cbc1e
sha512=0216d7bd533489dd800f48418931832b0d96d277a9424a6fe08ff87eb55cf78c0ad55c26459603a138715d1bcc90768e944cff24f5497d2e3390387aa93a1c14

doc/pecu/Pecu/Inline/index.html

Module Pecu.InlineSource

Decode inline quoted-printable value.

The purpose of this sub-module is to decode/encode inline quoted-printable data described by RFC2047. Header of an email can not emit in anyway (before RFC6532) bytes encoded into 8 bits. To be able to use an encoding such as latin1 or UTF-8, we can use an inlined quoted-printable text.

Sourcetype decoder

The type for decoders.

Sourcetype decode = [
  1. | `Await
  2. | `End
  3. | `Char of char
  4. | `Malformed of string
]
Sourceval src : decoder -> Bytes.t -> int -> int -> unit

src d s j l provides d with l bytes to read, starting at j in s. This byte range is read by calls to decode with d until `Await is returned. To signal the end of input, call the function with l = 0.

Sourceval decoder : src -> decoder

decoder src is a decoder that inputs from src.

Sourceval decode : decoder -> decode

decode d is:

  • `Await if d has a `Manual input source and awaits for more input. The client must use src to provide it.
  • `End if the end of input was reached.
  • `Malformed bytes if the bytes sequence is malformed according to the decoded quoted-printable encoding scheme. If you are interested in a best-effort decoding you can still continue to decode after an error until the decode synchronizes again on valid bytes.
  • `Data data if a data sequence value was decoded.
  • `Line line if a line sequence value plus a line-break was decoded.

Note. Repeated invocation always eventually returns `End, even in case of errors.

Sourceval decoder_byte_count : decoder -> int

decoder_byte_count d is the number of characters already decoded on d (included malformed ones). This is the last decode's end output offset counting from beginning of the stream.

Sourceval decoder_src : decoder -> src

decoder_src d is d's input source.

Sourcetype encode = [
  1. | `Await
  2. | `End
  3. | `Char of char
]
Sourcetype encoder

The type for encoders.

Sourceval encoder : dst -> encoder

encoder dst is an encoder that outputs to dst.

Sourceval encode : encoder -> encode -> [ `Ok | `Partial ]

encode encoder is:

  • `Partial iff e has a `Manual destination and needs more output storage. The client must use dst to provide a new buffer and then call encode with `Await until `Ok is returned.
  • `Ok when the encoder is ready to encode a new `Char, `Line_break or `End

For `Manual destination, encoding `End always return `Partial, the client should continue as usual with `Await until `Ok is returned at which point dst_rem encoder is guaranteed to be the sode of the last provided buffer (i.e. nothing was written).

Raises. Invalid_argument if a `Char, `Line_break or `End is encoded after a `Partial encode.

Sourceval encoder_dst : encoder -> dst

encoder_dst encoder is encoder's output destination.

Sourceval dst : encoder -> Bytes.t -> int -> int -> unit

dst e s j l provides e with l bytes to write, starting at j in s. This byte range is written by calls to encode with e until `Partial is returned. Use dst_rem to know the remaining number of non-written free bytes in s.

Sourceval dst_rem : encoder -> int

dst_rem e is the remaining number of non-written, free bytes in the last buffer provided with dst.

OCaml

Innovation. Community. Security.