GMime.Encoding

Fields

Name

Type

Access

Description

encode

bool

r/w

True if encoding or False if decoding

encoding

GMime.ContentEncoding

r/w

the type of encoding

save

int

r/w

saved bytes from the previous step

state

int

r/w

current encder/decoder state

uubuf

bytes

r/w

a temporary buffer needed when uuencoding data

Methods

class

base64_decode_step (inbuf, inlen, outbuf, state, save)

class

base64_encode_close (inbuf, inlen, outbuf, state, save)

class

base64_encode_step (inbuf, inlen, outbuf, state, save)

class

quoted_decode_step (inbuf, inlen, outbuf, state, save)

class

quoted_encode_close (inbuf, inlen, outbuf, state, save)

class

quoted_encode_step (inbuf, inlen, outbuf, state, save)

class

uudecode_step (inbuf, inlen, outbuf, state, save)

class

uuencode_close (inbuf, inlen, outbuf, uubuf, state, save)

class

uuencode_step (inbuf, inlen, outbuf, uubuf, state, save)

flush (inbuf, inlen, outbuf)

init_decode (encoding)

init_encode (encoding)

outlen (inlen)

reset ()

step (inbuf, inlen, outbuf)

Details

class GMime.Encoding

A context used for encoding or decoding data.

classmethod base64_decode_step(inbuf, inlen, outbuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output buffer

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been decoded

Returns:

the number of bytes decoded (which have been dumped in outbuf).

Return type:

int

Decodes a chunk of base64 encoded data.

classmethod base64_encode_close(inbuf, inlen, outbuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output buffer

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been encoded

Returns:

the number of bytes encoded.

Return type:

int

Base64 encodes the input stream to the output stream. Call this when finished encoding data with GMime.Encoding.base64_encode_step() to flush off the last little bit.

classmethod base64_encode_step(inbuf, inlen, outbuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output buffer

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been encoded

Returns:

the number of bytes encoded.

Return type:

int

Base64 encodes a chunk of data. Performs an ‘encode step’, only encodes blocks of 3 characters to the output at a time, saves left-over state in state and save (initialise to 0 on first invocation).

classmethod quoted_decode_step(inbuf, inlen, outbuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output buffer

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been decoded

Returns:

the number of bytes decoded.

Return type:

int

Decodes a block of quoted-printable encoded data. Performs a ‘decode step’ on a chunk of QP encoded data.

classmethod quoted_encode_close(inbuf, inlen, outbuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output buffer

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been encoded

Returns:

the number of bytes encoded.

Return type:

int

Quoted-printable encodes a block of text. Call this when finished encoding data with GMime.Encoding.quoted_encode_step() to flush off the last little bit.

classmethod quoted_encode_step(inbuf, inlen, outbuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output buffer

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been encoded

Returns:

the number of bytes encoded.

Return type:

int

Quoted-printable encodes a block of text. Performs an ‘encode step’, saves left-over state in state and save (initialise to -1 on first invocation).

classmethod uudecode_step(inbuf, inlen, outbuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output buffer

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been decoded

Returns:

the number of bytes decoded.

Return type:

int

Uudecodes a chunk of data. Performs a ‘decode step’ on a chunk of uuencoded data. Assumes the “begin mode filename” line has been stripped off.

classmethod uuencode_close(inbuf, inlen, outbuf, uubuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output buffer

  • uubuf (int) – temporary buffer of 60 bytes

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been encoded

Returns:

the number of bytes encoded.

Return type:

int

Uuencodes a chunk of data. Call this when finished encoding data with GMime.Encoding.uuencode_step() to flush off the last little bit.

classmethod uuencode_step(inbuf, inlen, outbuf, uubuf, state, save)
Parameters:
  • inbuf (int) – input buffer

  • inlen (int) – input buffer length

  • outbuf (int) – output stream

  • uubuf (int) – temporary buffer of 60 bytes

  • state (int) – holds the number of bits that are stored in save

  • save (int) – leftover bits that have not yet been encoded

Returns:

the number of bytes encoded.

Return type:

int

Uuencodes a chunk of data. Performs an ‘encode step’, only encodes blocks of 45 characters to the output at a time, saves left-over state in uubuf, state and save (initialize to 0 on first invocation).

flush(inbuf, inlen, outbuf)
Parameters:
  • inbuf (str) – an input buffer to encode or decode

  • inlen (int) – input buffer length

  • outbuf (str) – an output buffer

Returns:

the number of bytes written to outbuf.

Return type:

int

Completes the incremental encode or decode of the input stream (see GMime.Encoding.step() for details).

init_decode(encoding)
Parameters:

encoding (GMime.ContentEncoding) – a GMime.ContentEncoding to use

Initializes a GMime.Encoding state machine for decoding from encoding.

init_encode(encoding)
Parameters:

encoding (GMime.ContentEncoding) – a GMime.ContentEncoding to use

Initializes a GMime.Encoding state machine for encoding to encoding.

outlen(inlen)
Parameters:

inlen (int) – an input length

Returns:

the maximum number of bytes needed to encode or decode a buffer of inlen bytes.

Return type:

int

Given the input length, inlen, calculate the needed output length to perform an encoding or decoding step.

reset()

Resets the state of the GMime.Encoding.

step(inbuf, inlen, outbuf)
Parameters:
  • inbuf (str) – an input buffer to encode or decode

  • inlen (int) – input buffer length

  • outbuf (str) – an output buffer

Returns:

the number of bytes written to outbuf.

Return type:

int

Incrementally encodes or decodes (depending on self) an input stream by ‘stepping’ through a block of input at a time.

You should make sure outbuf is large enough by calling GMime.Encoding.outlen() to find out how large outbuf might need to be.