GMimeFilterBest

GMimeFilterBest — Determine the best charset/encoding to use for a stream

Synopsis

struct              GMimeFilterBest;
enum                GMimeFilterBestFlags;
GMimeFilter *       g_mime_filter_best_new              (GMimeFilterBestFlags flags);
const char *        g_mime_filter_best_charset          (GMimeFilterBest *best);
GMimeContentEncoding g_mime_filter_best_encoding        (GMimeFilterBest *best,
                                                         GMimeEncodingConstraint constraint);

Description

A GMimeFilter which is meant to determine the best charset and/or transfer encoding suitable for the stream which is filtered through it.

Details

struct GMimeFilterBest

struct GMimeFilterBest {
	GMimeFilter parent_object;
	
	GMimeFilterBestFlags flags;
	
	/* for best charset detection */
	GMimeCharset charset;
	
	/* for best encoding detection */
	unsigned int count0;      /* count of null bytes */
	unsigned int count8;      /* count of 8bit bytes */
	unsigned int total;       /* total octets */
	
	unsigned int maxline;     /* longest line length */
	unsigned int linelen;     /* current line length */
	
	unsigned char frombuf[6];
	unsigned int fromlen : 4;
	unsigned int hadfrom : 1;
	
	unsigned int startline : 1;
	unsigned int midline : 1;
};

A filter for calculating the best encoding and/or charset to encode the data passed through it.

GMimeFilter parent_object;

parent GMimeFilter

GMimeFilterBestFlags flags;

GMimeFilterBestFlags

GMimeCharset charset;

GMimeCharset state

unsigned int count0;

count of nul-bytes passed through the filter

unsigned int count8;

count of 8bit bytes passed through the filter

unsigned int total;

total number of bytes passed through the filter

unsigned int maxline;

the length of the longest line passed through the filter

unsigned int linelen;

current line length

unsigned char frombuf[6];

buffer for checking From_ lines

unsigned int fromlen : 4;

length of bytes in frombuf

unsigned int hadfrom : 1;

TRUE if any line started with "From "

unsigned int startline : 1;

start line state

unsigned int midline : 1;

mid-line state

enum GMimeFilterBestFlags

typedef enum {
	GMIME_FILTER_BEST_CHARSET  = (1 << 0),
	GMIME_FILTER_BEST_ENCODING = (1 << 1)
} GMimeFilterBestFlags;

Bit flags to enable charset and/or encoding scanning to make educated guesses as to what the best charset and/or encodings to use for the content passed through the filter.

GMIME_FILTER_BEST_CHARSET

Enable best-charset detection.

GMIME_FILTER_BEST_ENCODING

Enable best-encoding detection.

g_mime_filter_best_new ()

GMimeFilter *       g_mime_filter_best_new              (GMimeFilterBestFlags flags);

Creates a new GMimeFilterBest filter. flags are used to determine which information to keep statistics of. If the GMIME_FILTER_BEST_CHARSET bit is set, the filter will be able to compute the best charset for encoding the stream of data filtered. If the GMIME_FILTER_BEST_ENCODING bit is set, the filter will be able to compute the best Content-Transfer-Encoding for use with the stream being filtered.

Note: In order for the g_mime_filter_best_charset() function to work, the stream being filtered MUST already be encoded in UTF-8.

flags :

filter flags

Returns :

a new best filter with flags flags.

g_mime_filter_best_charset ()

const char *        g_mime_filter_best_charset          (GMimeFilterBest *best);

Calculates the best charset for encoding the stream filtered through the best filter.

best :

best filter

Returns :

a pointer to a string containing the name of the charset best suited for the text filtered through best.

g_mime_filter_best_encoding ()

GMimeContentEncoding g_mime_filter_best_encoding        (GMimeFilterBest *best,
                                                         GMimeEncodingConstraint constraint);

Calculates the most efficient Content-Transfer-Encoding for the stream filtered through best that fits within the encoding constraint.

best :

a GMimeFilterBest

constraint :

a GMimeEncodingConstraint

Returns :

the best encoding for the stream filtered by best.

See Also

GMimeFilter