## GMimeParser GMimeParser — Message and MIME part parser |

## Synopsis

                        GMimeParser;
    void                (*GMimeParserHeaderRegexFunc)       (GMimeParser *parser,
                                                             const char *header,
                                                             const char *value,
                                                             off_t offset,
                                                             gpointer user_data);
    GMimeParser*        g_mime_parser_new                   (void);
    GMimeParser*        g_mime_parser_new_with_stream       (GMimeStream *stream);
    void                g_mime_parser_init_with_stream      (GMimeParser *parser,
                                                             GMimeStream *stream);
    gboolean            g_mime_parser_get_persist_stream    (GMimeParser *parser);
    void                g_mime_parser_set_persist_stream    (GMimeParser *parser,
                                                             gboolean persist);
    gboolean            g_mime_parser_get_scan_from         (GMimeParser *parser);
    void                g_mime_parser_set_scan_from         (GMimeParser *parser,
                                                             gboolean scan_from);
    gboolean            g_mime_parser_get_respect_content_length
                                                            (GMimeParser *parser);
    void                g_mime_parser_set_respect_content_length
                                                            (GMimeParser *parser,
                                                             gboolean respect_content_length);
    void                g_mime_parser_set_header_regex      (GMimeParser *parser,
                                                             const char *regex,
                                                             GMimeParserHeaderRegexFunc header_cb,
                                                             gpointer user_data);
    off_t               g_mime_parser_tell                  (GMimeParser *parser);
    gboolean            g_mime_parser_eos                   (GMimeParser *parser);
    GMimeObject*        g_mime_parser_construct_part        (GMimeParser *parser);
    GMimeMessage*       g_mime_parser_construct_message     (GMimeParser *parser);
    char*               g_mime_parser_get_from              (GMimeParser *parser);
    off_t               g_mime_parser_get_from_offset       (GMimeParser *parser);
    off_t               g_mime_parser_get_headers_begin     (GMimeParser *parser);
    off_t               g_mime_parser_get_headers_end       (GMimeParser *parser);

## Object Hierarchy

      GObject
       +----GMimeParser

## Description

A GMimeParser parses a stream into a GMimeMessage or other GMimeObject and can also handle parsing MBox formatted streams into multiple GMimeMessage objects.

## Details

### GMimeParser

    typedef struct _GMimeParser GMimeParser;

### GMimeParserHeaderRegexFunc ()

    void                (*GMimeParserHeaderRegexFunc)       (GMimeParser *parser,
                                                             const char *header,
                                                             const char *value,
                                                             off_t offset,
                                                             gpointer user_data);

Function signature for the callback to `g_mime_parser_set_header_regex()`.

`parser` : | The GMimeParser object.
`header` : | The header field matched.
`value` : | The header field value.
`offset` : | The header field offset.
`user_data` : | The user-supplied callback data.

### g_mime_parser_new ()

    GMimeParser*        g_mime_parser_new                   (void);

Creates a new parser object.

Returns : | a new parser object.

### g_mime_parser_new_with_stream ()

    GMimeParser*        g_mime_parser_new_with_stream       (GMimeStream *stream);

Creates a new parser object preset to parse `stream`.

`stream` : | raw message or part stream
Returns : | a new parser object.

### g_mime_parser_init_with_stream ()

    void                g_mime_parser_init_with_stream      (GMimeParser *parser,
                                                             GMimeStream *stream);

Initializes `parser` to use `stream`.

WARNING: Initializing a parser with a stream is comparable to selling your soul (`stream`) to the devil (`parser`). 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 `g_mime_stream_tell()` because it will not necessarily give you the current `parser` offset since `parser` handles its own internal read-ahead buffer. Instead, it is recommended that you use `g_mime_parser_tell()` if you have a reason to need the current offset of the `parser`.

`parser` : | MIME parser object
`stream` : | raw message or part stream

### g_mime_parser_get_persist_stream ()

    gboolean            g_mime_parser_get_persist_stream    (GMimeParser *parser);

Gets whether or not the underlying stream is persistent.

`parser` : | MIME parser object
Returns : | `TRUE` if the `parser` will leave the content on disk or `FALSE` if it will load the content into memory.

### g_mime_parser_set_persist_stream ()

    void                g_mime_parser_set_persist_stream    (GMimeParser *parser,
                                                             gboolean persist);

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

If `persist` is `TRUE`, the `parser` 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 `parser` will always load message content into memory.

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

`parser` : | MIME parser object
`persist` : | persist attribute

### g_mime_parser_get_scan_from ()

    gboolean            g_mime_parser_get_scan_from         (GMimeParser *parser);

Gets whether or not `parser` is set to scan mbox-style From-lines.

`parser` : | MIME parser object
Returns : | whether or not `parser` is set to scan mbox-style From-lines.

### g_mime_parser_set_scan_from ()

    void                g_mime_parser_set_scan_from         (GMimeParser *parser,
                                                             gboolean scan_from);

Sets whether or not `parser` should scan mbox-style From-lines.

`parser` : | MIME parser object
`scan_from` : | `TRUE` to scan From-lines or `FALSE` otherwise

### g_mime_parser_get_respect_content_length ()

    gboolean            g_mime_parser_get_respect_content_length
                                                            (GMimeParser *parser);

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

`parser` : | MIME parser object
Returns : | whether or not `parser` is set to use Content-Length for determining the offset of the end of the message.

### g_mime_parser_set_respect_content_length ()

    void                g_mime_parser_set_respect_content_length
                                                            (GMimeParser *parser,
                                                             gboolean respect_content_length);

Sets whether or not `parser` 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).

`parser` : | MIME parser object
`respect_content_length` : | `TRUE` if the parser should use Content-Length headers or `FALSE` otherwise.

### g_mime_parser_set_header_regex ()

    void                g_mime_parser_set_header_regex      (GMimeParser *parser,
                                                             const char *regex,
                                                             GMimeParserHeaderRegexFunc header_cb,
                                                             gpointer user_data);

Sets the regular expression pattern `regex` on `parser`. Whenever a header matching the pattern `regex` is parsed, `header_cb` is called with `user_data` as the user_data argument.

`parser` : | MIME parser object
`regex` : | regular expression
`header_cb` : | callback function
`user_data` : | user data

### g_mime_parser_tell ()

    off_t               g_mime_parser_tell                  (GMimeParser *parser);

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

`parser` : | MIME parser object
Returns : | the current stream offset from the parser's internal stream or -1 on error.

### g_mime_parser_eos ()

    gboolean            g_mime_parser_eos                   (GMimeParser *parser);

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

`parser` : | MIME parser
Returns : | `TRUE` on EOS or `FALSE` otherwise.

### g_mime_parser_construct_part ()

    GMimeObject*        g_mime_parser_construct_part        (GMimeParser *parser);

Constructs a MIME part from `parser`.

`parser` : | MIME parser object
Returns : | a MIME part based on `parser` or `NULL` on fail.

### g_mime_parser_construct_message ()

    GMimeMessage*       g_mime_parser_construct_message     (GMimeParser *parser);

Constructs a MIME message from `parser`.

`parser` : | MIME parser object
Returns : | a MIME message or `NULL` on fail.

### g_mime_parser_get_from ()

    char*               g_mime_parser_get_from              (GMimeParser *parser);

Gets the mbox-style From-line of the most recently parsed message (gotten from `g_mime_parser_construct_message()`).

`parser` : | MIME parser object
Returns : | the mbox-style From-line of the most recently parsed message or `NULL` on error.

### g_mime_parser_get_from_offset ()

    off_t               g_mime_parser_get_from_offset       (GMimeParser *parser);

Gets the offset of the most recently parsed mbox-style From-line (gotten from `g_mime_parser_construct_message()`).

`parser` : | MIME parser object
Returns : | the offset of the most recently parsed mbox-style From-line or -1 on error.

### g_mime_parser_get_headers_begin ()

    off_t               g_mime_parser_get_headers_begin     (GMimeParser *parser);

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

`parser` : | a GMimeParser context
Returns : | the offset of the beginning of the headers of the most recently parsed message or `-1` on error.

Since 2.2.23

### g_mime_parser_get_headers_end ()

    off_t               g_mime_parser_get_headers_end       (GMimeParser *parser);

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

`parser` : | a GMimeParser context
Returns : | the offset of the end of the headers of the most recently parsed message or `-1` on error.

Since 2.2.23