CamelIMAP4Stream
3
CAMEL Library

# CamelIMAP4Stream

## Synopsis

    #define             IMAP4_READ_PRELEN
    #define             IMAP4_READ_BUFLEN
                        camel_imap4_token_t;
                        CamelIMAP4Stream;
    CamelStream*        camel_imap4_stream_new              (CamelStream *stream);
    int                 camel_imap4_stream_next_token       (CamelIMAP4Stream *stream,
                                                             camel_imap4_token_t *token);
    int                 camel_imap4_stream_unget_token      (CamelIMAP4Stream *stream,
                                                             camel_imap4_token_t *token);
    int                 camel_imap4_stream_line             (CamelIMAP4Stream *stream,
                                                             unsigned char **line,
                                                             size_t *len);
    int                 camel_imap4_stream_literal          (CamelIMAP4Stream *stream,
                                                             unsigned char **literal,
                                                             size_t *len);

## Description

## Details

### IMAP4_READ_PRELEN

    #define IMAP4_READ_PRELEN   128

### IMAP4_READ_BUFLEN

    #define IMAP4_READ_BUFLEN   4096

### camel_imap4_token_t

    typedef struct {
    	int token;
    	union {
    		char *atom;
    		char *flag;
    		char *qstring;
    		size_t literal;
    		guint32 number;
    	} v;
    } camel_imap4_token_t;

### CamelIMAP4Stream

    typedef struct {
    	CamelStream parent_object;

    	CamelStream *stream;

    	guint disconnected:1;  /* disconnected state */
    	guint have_unget:1;    /* have an unget token */
    	guint mode:1;          /* TOKEN vs LITERAL */
    	guint eol:1;           /* end-of-literal */

    	size_t literal;

    	/* i/o buffers */
    	unsigned char realbuf[IMAP4_READ_PRELEN + IMAP4_READ_BUFLEN + 1];
    	unsigned char *inbuf;
    	unsigned char *inptr;
    	unsigned char *inend;

    	/* token buffers */
    	unsigned char *tokenbuf;
    	unsigned char *tokenptr;
    	unsigned int tokenleft;

    	camel_imap4_token_t unget;
    } CamelIMAP4Stream;

### camel_imap4_stream_new ()

    CamelStream*        camel_imap4_stream_new              (CamelStream *stream);

`stream` :

  tcp stream

Returns :

  a new imap4 stream

### camel_imap4_stream_next_token ()

    int                 camel_imap4_stream_next_token       (CamelIMAP4Stream *stream,
                                                             camel_imap4_token_t *token);

Reads the next token from the imap4 stream and saves it in `token`.

`stream` :

  imap4 stream

`token` :

  imap4 token

Returns :

  0 on success or -1 on fail.

### camel_imap4_stream_unget_token ()

    int                 camel_imap4_stream_unget_token      (CamelIMAP4Stream *stream,
                                                             camel_imap4_token_t *token);

Ungets an imap4 token (as in `ungetc()`).

Note: you may *ONLY* unget a single token. Trying to unget another token will fail.

`stream` :

  imap4 stream

`token` :

  token to 'unget'

Returns :

  0 on success or -1 on fail.

### camel_imap4_stream_line ()

    int                 camel_imap4_stream_line             (CamelIMAP4Stream *stream,
                                                             unsigned char **line,
                                                             size_t *len);

Reads a single line from the imap4 stream and points `line` at an internal buffer containing the line read and sets `len` to the length of the line buffer.

`stream` :

  imap4 stream

`line` :

  line pointer

`len` :

  line length

Returns :

  -1 on error, 0 if the line read is complete, or 1 if the read is incomplete.

### camel_imap4_stream_literal ()

    int                 camel_imap4_stream_literal          (CamelIMAP4Stream *stream,
                                                             unsigned char **literal,
                                                             size_t *len);

Sets `literal` to the beginning of the next chunk of the literal buffer from the IMAP stream and sets `len` to the length of the `literal` buffer.

`stream` :

  IMAP stream

`literal` :

  literal pointer

`len` :

  literal length

Returns :

  >0 if more literal data exists, 0 if the end of the literal has been reached or -1 on fail.