GMimeContent

GMimeContent — Content objects

Functions

Types and Values

Description

A GMimeContent is a wrapper object for a GMimePart's body, allowing clients to read the content from the backing stream without having to know whether it is encoded/compressed/etc and not neding to know how to undo said encoding(s).

Functions

g_mime_content_new ()

GMimeContent *
g_mime_content_new (void);

Creates a new GMimeContent object.

Returns

a new GMimeContent object.


g_mime_content_new_with_stream ()

GMimeContent *
g_mime_content_new_with_stream (GMimeStream *stream,
                                GMimeContentEncoding encoding);

Creates a new GMimeContent object around stream .

Parameters

stream

a GMimeStream

 

encoding

stream's encoding

 

Returns

a new GMimeContent object holding its own reference to stream .


g_mime_content_set_stream ()

void
g_mime_content_set_stream (GMimeContent *content,
                           GMimeStream *stream);

Replaces the wrapper's internal stream with stream . Don't forget, if stream is not of the same encoding as the old stream, you'll want to call g_mime_content_set_encoding() as well.

Note: caller is responsible for its own reference on stream .

Parameters

content

a GMimeContent

 

stream

a GMimeStream

 

g_mime_content_get_stream ()

GMimeStream *
g_mime_content_get_stream (GMimeContent *content);

Gets a reference to the stream wrapped by content .

Parameters

content

a GMimeContent

 

Returns

a reference to the internal stream.

[transfer none]


g_mime_content_set_encoding ()

void
g_mime_content_set_encoding (GMimeContent *content,
                             GMimeContentEncoding encoding);

Sets the encoding type of the internal stream.

Parameters

content

a GMimeContent

 

encoding

encoding

 

g_mime_content_get_encoding ()

GMimeContentEncoding
g_mime_content_get_encoding (GMimeContent *content);

Gets the encoding type of the stream wrapped by content .

Parameters

content

a GMimeContent

 

Returns

the encoding type of the internal stream.


g_mime_content_get_newline_format ()

gboolean
g_mime_content_get_newline_format (GMimeContent *content,
                                   GMimeNewLineFormat *format);

Gets the raw content's new-line format, if known. This is a hint for verifying digital signatures, not a request to convert the content. Mixed newlines are reported as GMIME_NEWLINE_FORMAT_MIXED. Content without LF or CRLF has no known format.

Parameters

content

a GMimeContent

 

format

the observed new-line format.

[out][optional]

Returns

TRUE if format is known, or FALSE otherwise, leaving format unchanged.


g_mime_content_set_newline_format ()

void
g_mime_content_set_newline_format (GMimeContent *content,
                                   GMimeNewLineFormat format);

Sets the raw content's new-line format hint without modifying its bytes.

Parameters

content

a GMimeContent

 

format

the observed new-line format

 

g_mime_content_clear_newline_format ()

void
g_mime_content_clear_newline_format (GMimeContent *content);

Clears the new-line format hint without modifying the content. Replacing the backing stream also clears this hint.

Parameters

content

a GMimeContent

 

g_mime_content_open ()

GMimeStream *
g_mime_content_open (GMimeContent *content);

Rewinds the backing stream and returns a new stream which decodes the content as it is read, without buffering the entire content in memory. Default, 7bit, 8bit, and binary content pass through unchanged.

The returned stream retains the backing stream but does not close it. It has its own decoder state, using the encoding at the time of this call. Readers share the backing stream's position, so opening another reader or otherwise using that stream can interfere with existing readers. Closing a reader does not rewind the backing stream.

Parameters

content

a GMimeContent

 

Returns

a decoded stream, or NULL if rewinding fails, with errno set by the backing stream. Read failures are reported by g_mime_stream_read() as -1 with errno set.

[nullable][transfer full]


g_mime_content_write_to_stream ()

ssize_t
g_mime_content_write_to_stream (GMimeContent *content,
                                GMimeStream *stream);

Copies the backing stream verbatim, without decoding its transfer encoding. Rewinds the source before copying and again on success. On an I/O failure, leaves the source at its current position. Neither stream is closed and the output stream is not flushed.

Use g_mime_content_decode_to_stream() for decoded bytes or g_mime_content_open() for a decoded reader.

Parameters

content

a GMimeContent

 

stream

output stream

 

Returns

the number of bytes written or -1 on failure, with errno set.


g_mime_content_decode_to_stream ()

ssize_t
g_mime_content_decode_to_stream (GMimeContent *content,
                                 GMimeStream *stream);

Decodes the content into stream using the content's transfer encoding. Default, 7bit, 8bit, and binary data pass through unchanged. Calls the virtual g_mime_content_write_to_stream() through a decoder, rewinding the source before copying and again on success. An I/O failure leaves the source at its current position. Neither stream is closed or flushed; only the decoder's buffered data is flushed.

Parameters

content

a GMimeContent

 

stream

output stream

 

Returns

the number of decoded bytes written or -1 on failure, with errno set. A failure may leave partial output in stream .

Types and Values

enum GMimeContentStorage

Storage for parsed MIME part content. The caller owns the input stream in both modes. Memory storage allows it to be closed or modified after parsing. Source storage requires it to remain open and unchanged while the parsed content is in use.

Members

GMIME_CONTENT_STORAGE_MEMORY

Copy MIME part content into memory.

 

GMIME_CONTENT_STORAGE_SOURCE

Reference content in the seekable input.

 

GMimeContent

typedef struct _GMimeContent GMimeContent;

A wrapper for a stream which may be encoded.

See Also

GMimePart