GMimeFilterYenc

## GMimeFilterYenc GMimeFilterYenc — yEncode or yDecode |

## Synopsis

                        GMimeFilterYenc;
    GMimeFilter *       g_mime_filter_yenc_new              (gboolean encode);
    void                g_mime_filter_yenc_set_state        (GMimeFilterYenc *yenc,
                                                             int state);
    void                g_mime_filter_yenc_set_crc          (GMimeFilterYenc *yenc,
                                                             guint32 crc);
    guint32             g_mime_filter_yenc_get_crc          (GMimeFilterYenc *yenc);
    guint32             g_mime_filter_yenc_get_pcrc         (GMimeFilterYenc *yenc);

    #define             GMIME_YENCODE_CRC_INIT
    #define             GMIME_YENCODE_CRC_FINAL             (crc)
    #define             GMIME_YENCODE_STATE_INIT
    #define             GMIME_YDECODE_STATE_INIT
    #define             GMIME_YDECODE_STATE_EOLN
    #define             GMIME_YDECODE_STATE_ESCAPE
    #define             GMIME_YDECODE_STATE_END
    #define             GMIME_YDECODE_STATE_BEGIN
    #define             GMIME_YDECODE_STATE_DECODE
    #define             GMIME_YDECODE_STATE_PART
    size_t              g_mime_ydecode_step                 (unsigned char *inbuf,
                                                             size_t inlen,
                                                             unsigned char *outbuf,
                                                             int *state,
                                                             guint32 *pcrc,
                                                             guint32 *crc);
    size_t              g_mime_yencode_step                 (unsigned char *inbuf,
                                                             size_t inlen,
                                                             unsigned char *outbuf,
                                                             int *state,
                                                             guint32 *pcrc,
                                                             guint32 *crc);
    size_t              g_mime_yencode_close                (unsigned char *inbuf,
                                                             size_t inlen,
                                                             unsigned char *outbuf,
                                                             int *state,
                                                             guint32 *pcrc,
                                                             guint32 *crc);

## Object Hierarchy

      GObject
       +----GMimeFilter
             +----GMimeFilterYenc

## Description

A GMimeFilter used to encode or decode the Usenet yEncoding.

## Details

### GMimeFilterYenc

    typedef struct _GMimeFilterYenc GMimeFilterYenc;

A filter for yEncoding or yDecoding a stream.

### g_mime_filter_yenc_new ()

    GMimeFilter *       g_mime_filter_yenc_new              (gboolean encode);

Creates a new yEnc filter.

`encode` : | encode vs decode
Returns : | a new yEnc filter.

### g_mime_filter_yenc_set_state ()

    void                g_mime_filter_yenc_set_state        (GMimeFilterYenc *yenc,
                                                             int state);

Sets the current state of the yencoder/ydecoder

`yenc` : | yEnc filter
`state` : | encode/decode state

### g_mime_filter_yenc_set_crc ()

    void                g_mime_filter_yenc_set_crc          (GMimeFilterYenc *yenc,
                                                             guint32 crc);

Sets the current crc32 value on the yEnc filter `yenc` to `crc`.

`yenc` : | yEnc filter
`crc` : | crc32

### g_mime_filter_yenc_get_crc ()

    guint32             g_mime_filter_yenc_get_crc          (GMimeFilterYenc *yenc);

Get the computed crc or (guint32) -1 on fail.

`yenc` : | yEnc filter
Returns : | the computed crc or (guint32) -1 on fail.

### g_mime_filter_yenc_get_pcrc ()

    guint32             g_mime_filter_yenc_get_pcrc         (GMimeFilterYenc *yenc);

Get the computed part crc or (guint32) -1 on fail.

`yenc` : | yEnc filter
Returns : | the computed part crc or (guint32) -1 on fail.

### GMIME_YENCODE_CRC_INIT

    #define GMIME_YENCODE_CRC_INIT       (~0)

Initial state for the crc and pcrc state variables.

### GMIME_YENCODE_CRC_FINAL()

    #define GMIME_YENCODE_CRC_FINAL(crc) (~crc)

Gets the final crc value from `crc`.

`crc` : | crc or pcrc state variable

### GMIME_YENCODE_STATE_INIT

    #define GMIME_YENCODE_STATE_INIT     (0)

Initial state for the `g_mime_ydecode_step()` function.

### GMIME_YDECODE_STATE_INIT

    #define GMIME_YDECODE_STATE_INIT     (0)

Initial state for the `g_mime_ydecode_step()` function.

### GMIME_YDECODE_STATE_EOLN

    #define GMIME_YDECODE_STATE_EOLN     (1 << 8)

State bit that denotes the yEnc filter has reached an end-of-line.

This state is for internal use only.

### GMIME_YDECODE_STATE_ESCAPE

    #define GMIME_YDECODE_STATE_ESCAPE   (1 << 9)

State bit that denotes the yEnc filter has reached an escape sequence.

This state is for internal use only.

### GMIME_YDECODE_STATE_END

    #define GMIME_YDECODE_STATE_END      (1 << 15)

State bit that denoates that `g_mime_ydecode_step()` has finished decoding.

### GMIME_YDECODE_STATE_BEGIN

    #define GMIME_YDECODE_STATE_BEGIN    (1 << 12)

State bit that denotes the yEnc filter has found the =ybegin line.

### GMIME_YDECODE_STATE_DECODE

    #define GMIME_YDECODE_STATE_DECODE   (1 << 14)

State bit that denotes yEnc filter has begun decoding the actual yencoded content and will continue to do so until an =yend line is found (or until there is nothing left to decode).

### GMIME_YDECODE_STATE_PART

    #define GMIME_YDECODE_STATE_PART     (1 << 13)

State bit that denotes the yEnc filter has found the =ypart line. (Note: not all yencoded blocks have one)

### g_mime_ydecode_step ()

    size_t              g_mime_ydecode_step                 (unsigned char *inbuf,
                                                             size_t inlen,
                                                             unsigned char *outbuf,
                                                             int *state,
                                                             guint32 *pcrc,
                                                             guint32 *crc);

Performs a 'decode step' on a chunk of yEncoded data of length `inlen` pointed to by `inbuf` and writes to `outbuf`. Assumes the =ybegin and =ypart lines have already been stripped off.

To get the crc32 value of the part, use GMIME_YENCODE_CRC_FINAL (`pcrc`). If there are more parts, you should reuse `crc` without re-initializing. Once all parts have been decoded, you may get the combined crc32 value of all the parts using GMIME_YENCODE_CRC_FINAL (`crc`).

`inbuf` : | input buffer
`inlen` : | input buffer length
`outbuf` : | output buffer
`state` : | ydecode state
`pcrc` : | part crc state
`crc` : | crc state
Returns : | the number of bytes decoded.

### g_mime_yencode_step ()

    size_t              g_mime_yencode_step                 (unsigned char *inbuf,
                                                             size_t inlen,
                                                             unsigned char *outbuf,
                                                             int *state,
                                                             guint32 *pcrc,
                                                             guint32 *crc);

Performs an yEncode 'encode step' on a chunk of raw data of length `inlen` pointed to by `inbuf` and writes to `outbuf`.

`state` should be initialized to GMIME_YENCODE_STATE_INIT before beginning making the first call to this function. Subsequent calls should reuse `state`.

Along the same lines, `pcrc` and `crc` should be initialized to GMIME_YENCODE_CRC_INIT before using.

`inbuf` : | input buffer
`inlen` : | input buffer length
`outbuf` : | output buffer
`state` : | yencode state
`pcrc` : | part crc state
`crc` : | crc state
Returns : | the number of bytes encoded.

### g_mime_yencode_close ()

    size_t              g_mime_yencode_close                (unsigned char *inbuf,
                                                             size_t inlen,
                                                             unsigned char *outbuf,
                                                             int *state,
                                                             guint32 *pcrc,
                                                             guint32 *crc);

Call this function when finished encoding data with `g_mime_yencode_step()` to flush off the remaining state.

GMIME_YENCODE_CRC_FINAL (`pcrc`) will give you the crc32 of the encoded "part". If there are more "parts" to encode, you should re-use `crc` when encoding the next "parts" and then use GMIME_YENCODE_CRC_FINAL (`crc`) to get the combined crc32 value of all the parts.

`inbuf` : | input buffer
`inlen` : | input buffer length
`outbuf` : | output buffer
`state` : | yencode state
`pcrc` : | part crc state
`crc` : | crc state
Returns : | the number of bytes encoded.

## See Also

GMimeFilter