GMime.Parser

g GMime.Parser GMime.Parser GObject.Object GObject.Object GObject.Object->GMime.Parser

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

class

new_with_stream (stream)

construct_message (options)

construct_part (options)

eos ()

get_format ()

get_headers_begin ()

get_headers_end ()

get_mbox_marker ()

get_mbox_marker_offset ()

get_persist_stream ()

get_respect_content_length ()

init_with_stream (stream)

set_format (format)

set_persist_stream (persist)

set_respect_content_length (respect_content_length)

tell ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_object

GObject.Object

r

parent GObject.Object

priv

object

r

private parser state

Class Details

class GMime.Parser(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

GMime.ParserClass

A MIME parser context.

classmethod new()
Returns:

a new parser object.

Return type:

GMime.Parser

Creates a new parser object.

classmethod new_with_stream(stream)
Parameters:

stream (GMime.Stream) – raw message or part stream

Returns:

a new parser object.

Return type:

GMime.Parser

Creates a new parser object preset to parse stream.

construct_message(options)
Parameters:

options (GMime.ParserOptions or None) – a GMime.ParserOptions or None

Returns:

a MIME message or None on fail.

Return type:

GMime.Message or None

Constructs a MIME message from self.

construct_part(options)
Parameters:

options (GMime.ParserOptions or None) – a GMime.ParserOptions or None

Returns:

a MIME part based on self or None on fail.

Return type:

GMime.Object or None

Constructs a MIME part from self.

eos()
Returns:

True on EOS or False otherwise.

Return type:

bool

Tests the end-of-stream indicator for self's internal stream.

get_format()
Returns:

the format that the parser is set to parse.

Return type:

GMime.Format

Gets the format that the parser is set to parse.

get_headers_begin()
Returns:

the offset of the beginning of the headers of the most recently parsed message or %-1 on error.

Return type:

int

Gets the stream offset of the beginning of the headers of the most recently parsed message.

get_headers_end()
Returns:

the offset of the end of the headers of the most recently parsed message or %-1 on error.

Return type:

int

Gets the stream offset of the end of the headers of the most recently parsed message.

get_mbox_marker()
Returns:

the mbox-style From-line of the most recently parsed message or None on error.

Return type:

str or None

Gets the mbox-style From-line of the most recently parsed message (gotten from GMime.Parser.construct_message()).

get_mbox_marker_offset()
Returns:

the offset of the most recently parsed mbox-style From-line or %-1 on error.

Return type:

int

Gets the offset of the most recently parsed mbox-style From-line (gotten from GMime.Parser.construct_message()).

get_persist_stream()
Returns:

True if the self will leave the content on disk or False if it will load the content into memory.

Return type:

bool

Gets whether or not the underlying stream is persistent.

get_respect_content_length()
Returns:

whether or not self is set to use Content-Length for determining the offset of the end of the message.

Return type:

bool

Gets whether or not self is set to use Content-Length for determining the offset of the end of the message.

init_with_stream(stream)
Parameters:

stream (GMime.Stream) – raw message or part stream

Initializes self to use stream.

WARNING: Initializing a parser with a stream is comparable to selling your soul (stream) to the devil (self). You are basically giving the parser complete control of the stream, this means that you had better not touch the stream so long as the parser is still using it. This means no reading, writing, seeking, or resetting of the stream. Anything that will/could change the current stream’s offset is PROHIBITED.

It is also recommended that you not use GMime.Stream.tell() because it will not necessarily give you the current self offset since self handles its own internal read-ahead buffer. Instead, it is recommended that you use GMime.Parser.tell() if you have a reason to need the current offset of the self.

set_format(format)
Parameters:

format (GMime.Format) – a GMime.Format

Sets the format that the parser should expect the stream to be in.

set_persist_stream(persist)
Parameters:

persist (bool) – persist attribute

Sets whether or not the self's underlying stream is persistent.

If persist is True, the self will attempt to construct messages/parts whose content will remain on disk rather than being loaded into memory so as to reduce memory usage. This is the default.

If persist is False, the self will always load message content into memory.

Note: This attribute only serves as a hint to the self. If the underlying stream does not support seeking, then this attribute will be ignored.

By default, this feature is enabled if the underlying stream is seekable.

set_respect_content_length(respect_content_length)
Parameters:

respect_content_length (bool) – True if the parser should use Content-Length headers or False otherwise.

Sets whether or not self should respect Content-Length headers when deciding where to look for the start of the next message. Only used when the parser is also set to scan for From-lines.

Most notably useful when parsing broken Solaris mbox files (See http://www.jwz.org/doc/content-length.html for details).

By default, this feature is disabled.

tell()
Returns:

the current stream offset from the parser’s internal stream or %-1 on error.

Return type:

int

Gets the current stream offset from the parser’s internal stream.