Pecu
Pecu, decoder/encoder of quoted-printable flow.
A quoted-printable flow, is a rich text encoding used by emails to safely transmit a text even if it use some bytes which can not be encoded into 7 bits. It is described by RFC2045 as a possible Content-Transfer-Encoding of the email's contents. This library wants to provide a non-blocking encoder/decoder to this such format. quoted-printable does not imply any encoding. A latin1i can be used or UTF-8. This such information is available into the Content-type value.
The type for input sources. With a `Manual
source the client must provide input with src
.
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
.
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.
val 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.
val decoder_dangerous : decoder -> bool
decoder_dangerous d
returns true
if encoded input does not respect the 80-columns rule. In this case, internal buffers can grow automatically. If you are interested in a best-effort decoding you can still continue to decode even if decoder_dangerous d
returns true
. However, it could be an attack entry point in a server-context.
The type for output destinations. With a `Manual
destination the client must provide output storage with dst
.
encode e v
: 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.
val dst_rem : encoder -> int
dst_rem e
is the remaining number of non-written, free bytes in the last buffer provided with dst
.
module Inline : sig ... end