Camel.MimeParser¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class Camel.MimeParser(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
- classmethod new()¶
- Returns:
A new
Camel.MimeParser
object- Return type:
Create a new
Camel.MimeParser
object.
- content_type()¶
- Returns:
A content_type structure, or
None
if there is no content-type defined for thisCamel.part
of state of the parser.- Return type:
Get the content type defined in the current
Camel.part
.
- drop_step()¶
Drop the last step call. This should only be used in conjunction with seeking of the stream as the stream may be in an undefined state relative to the state of the parser.
Use this call with care.
- dup_headers()¶
- Returns:
The headers, or
None
, if there are no headers defined for the currentCamel.part
or state. Free it withCamel.NameValueArray.free
().- Return type:
Get the list of the raw headers which are defined for the current state of the parser. These headers are valid until the next call to
Camel.MimeParser.step
(), orCamel.MimeParser.drop_step
().New in version 3.24.
- filter_add(mf)¶
- Parameters:
mf (
Camel.MimeFilter
) – aCamel.MimeFilter
- Returns:
An id that may be passed to
Camel.MimeParser.filter_remove
() to remove the filter, or -1 if the operation failed.- Return type:
Add a filter that will be applied to any body content before it is passed to the caller. Filters may be pipelined to perform multi-pass operations on the content, and are applied in the order they were added.
Note that filters are only applied to the body content of messages, and once a filter has been set, all content returned by a
Camel.MimeParser.step
() with a state ofCamel.MimeParserState.BODY
will have passed through the filter.New in version 2.22.
- filter_remove(id)¶
- Parameters:
id (
int
) – id of the filter to remove, as returned fromCamel.MimeParser.filter_add
()
Remove a processing filter from the pipeline. There is no restriction on the order the filters can be removed.
New in version 2.22.
- from_line()¶
-
Get the last scanned “From “ line, from a recently scanned from. This should only be called in the
Camel.MimeParserState.FROM
state. The from line will include the closing \n found (if there was one).The return value will remain valid while in the
Camel.MimeParserState.FROM
state, or any deeper state.New in version 2.22.
- header(name, offset)¶
- Parameters:
- Returns:
The header value, or
None
if the header is not defined.- Return type:
Lookup a header by name.
- init_with_bytes(bytes)¶
- Parameters:
bytes (
GLib.Bytes
) – aGLib.Bytes
containing the message content
Convenience function creates a
Gio.MemoryInputStream
from bytes and hands it off toCamel.MimeParser.init_with_input_stream
().New in version 3.12.
- init_with_fd(fd)¶
-
Initialise the scanner with an fd. The scanner’s offsets will be relative to the current file position of the file descriptor. As a result, seekable descritors should be seeked using the parser seek functions.
- init_with_input_stream(input_stream)¶
- Parameters:
input_stream (
Gio.InputStream
) – aGio.InputStream
Initialize the scanner with input_stream. The scanner’s offsets will be relative to the current file position of the stream. As a result, seekable streams should only be seeked using the parser seek function.
New in version 3.12.
- init_with_stream(stream)¶
- Parameters:
stream (
Camel.Stream
) – aCamel.Stream
to init with- Raises:
- Returns:
-1 on error.
- Return type:
Initialise the scanner with a source stream. The scanner’s offsets will be relative to the current file position of the stream. As a result, seekable streams should only be seeked using the parser seek function.
- postface()¶
-
Retrieve the postface text for the current multipart. Only returns valid data when the current state if
Camel.MimeParserState.MULTIPART_END
.New in version 2.22.
- preface()¶
-
Retrieve the preface text for the current multipart. Can only be used when the state is
Camel.MimeParserState.MULTIPART_END
.New in version 2.22.
- push_state(newstate, boundary)¶
- Parameters:
newstate (
Camel.MimeParserState
) – New stateboundary (
str
) – Boundary marker for state.
Pre-load a new parser state. Used to post-parse multipart content without headers.
- read(len)¶
- Parameters:
len (
int
) – The length of data to read- Raises:
- Returns:
The number of bytes available, or -1 on error.
- databuffer:
The data buffer
- Return type:
Read at most len bytes from the internal mime parser buffer.
Returns the address of the internal buffer in databuffer, and the length of useful data.
len may be specified as
GObject.G_MAXSSIZE
, in which case you will get the full remainder of the buffer at each call.Note that no parsing of the data read through this function occurs, so no state changes occur, but the seek position is updated appropriately.
- scan_from(scan_from)¶
-
Tell the scanner if it should scan “^From “ lines or not.
If the scanner is scanning from lines, two additional states
Camel.MimeParserState.FROM
andCamel.MimeParserState.FROM_END
will be returned to the caller during parsing.This may also be preceeded by an optional
Camel.MimeParserState.PRE_FROM
state which contains the scanned data found before the From line is encountered. See alsoCamel.MimeParser.scan_pre_from
().
- scan_pre_from(scan_pre_from)¶
-
Tell the scanner whether we want to know abou the pre-from data during a scan. If we do, then we may get an additional state
Camel.MimeParserState.PRE_FROM
which returns the specified data.
- seek(offset, whence)¶
- Parameters:
- Returns:
The new seek offset, or -1 on an error (for example, trying to seek on a non-seekable stream or file descriptor).
- Return type:
Reset the source position to a known value.
Note that if the source stream/descriptor was not positioned at 0 to begin with, and an absolute seek is specified (whence != SEEK_CUR), then the seek position may not match the desired seek position.
New in version 2.22.
- state()¶
- Returns:
The current parser state.
- Return type:
Get the current parser state.
- step(databuffer)¶
- Parameters:
databuffer (
bytes
) – Pointer to accept a pointer to the data associated with this step (if any). May beNone
, in which case datalength is also ingored.- Returns:
The current new state of the parser is returned.
- databuffer:
Pointer to accept a pointer to the data associated with this step (if any). May be
None
, in which case datalength is also ingored.
- Return type:
(
Camel.MimeParserState
, databuffer:bytes
)
Parse the next
Camel.part
of the MIME message. IfCamel.MimeParser.unstep
() has been called, then continue to return the same state for that many calls.If the step is
Camel.MimeParserState.BODY
then the databuffer and datalength pointers will be setup to point to the internal data buffer of the scanner and may be processed as required. Any filters will have already been applied to this data.Refer to the state diagram elsewhere for a full listing of the states an application is gauranteed to get from the scanner.
- stream()¶
- Returns:
The stream from
Camel.MimeParser.init_with_stream
(), orNone
if the parser is reading from a file descriptor or is uninitialised.- Return type:
Camel.Stream
orNone
Get the stream, if any, the parser has been initialised with. May be used to setup sub-streams, but should not be read from directly (without saving and restoring the seek position in between).
- tell()¶
- Returns:
See above.
- Return type:
Return the current scanning offset. The meaning of this value will depend on the current state of the parser.
An incomplete listing of the states:
Camel.MimeParserState.INITIAL
, The start of the current message.Camel.MimeParserState.HEADER
,Camel.MimeParserState.MESSAGE
,Camel.MimeParserState.MULTIPART
, the character position immediately after the end of the header.Camel.MimeParserState.BODY
, Position within the message of the start of the current data block. CAMEL_MIME_PARSER_STATE_*_END, The position of the character starting the next section of the scan (the last position + 1 of the respective current state).New in version 2.22.
- tell_start_boundary()¶
- Returns:
The start of the boundary, or -1 if there was no boundary encountered yet.
- Return type:
When parsing a multipart, this returns the start of the last boundary.
New in version 2.22.
- tell_start_from()¶
- Returns:
The start of the from line, or -1 if there was no From line, or From lines are not being scanned.
- Return type:
If the parser is scanning From lines, then this returns the position of the start of the From line.
New in version 2.22.
- tell_start_headers()¶
- Returns:
The header start position, or -1 if no headers were scanned in the current state.
- Return type:
Find out the position within the file of where the headers started, this is cached by the parser at the time.
New in version 2.22.
- unstep()¶
Cause the last step operation to repeat itself. If this is called repeated times, then the same step will be repeated that many times.
Note that it is not possible to scan back using this function, only to have a way of peeking the next state.
- do_content() virtual¶
- do_part() virtual¶