/* A lexical scanner generated by flex */

/* Scanner skeleton version:
 * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $
 */

#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5

#include <stdio.h>
#include <errno.h>

/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
#ifdef c_plusplus
#ifndef __cplusplus
#define __cplusplus
#endif
#endif


#ifdef __cplusplus

#include <stdlib.h>
#ifndef _WIN32
#include <unistd.h>
#endif

/* Use prototypes in function declarations. */
#define YY_USE_PROTOS

/* The "const" storage-class-modifier is valid. */
#define YY_USE_CONST

#else	/* ! __cplusplus */

#if __STDC__

#define YY_USE_PROTOS
#define YY_USE_CONST

#endif	/* __STDC__ */
#endif	/* ! __cplusplus */

#ifdef __TURBOC__
 #pragma warn -rch
 #pragma warn -use
#include <io.h>
#include <stdlib.h>
#define YY_USE_CONST
#define YY_USE_PROTOS
#endif

#ifdef YY_USE_CONST
#define yyconst const
#else
#define yyconst
#endif


#ifdef YY_USE_PROTOS
#define YY_PROTO(proto) proto
#else
#define YY_PROTO(proto) ()
#endif


/* Returned upon end-of-file. */
#define YY_NULL 0

/* Promotes a possibly negative, possibly signed char to an unsigned
 * integer for use as an array index.  If the signed char is negative,
 * we want to instead treat it as an 8-bit unsigned char, hence the
 * double cast.
 */
#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)

/* Enter a start condition.  This macro really ought to take a parameter,
 * but we do it the disgusting crufty way forced on us by the ()-less
 * definition of BEGIN.
 */
#define BEGIN yy_start = 1 + 2 *

/* Translate the current start state into a value that can be later handed
 * to BEGIN to return to the state.  The YYSTATE alias is for lex
 * compatibility.
 */
#define YY_START ((yy_start - 1) / 2)
#define YYSTATE YY_START

/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)

/* Special action meaning "start processing a new file". */
#define YY_NEW_FILE yyrestart( yyin )

#define YY_END_OF_BUFFER_CHAR 0

/* Size of default input buffer. */
#define YY_BUF_SIZE 16384

typedef struct yy_buffer_state *YY_BUFFER_STATE;

extern int yyleng;
extern FILE *yyin, *yyout;

#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2

/* The funky do-while in the following #define is used to turn the definition
 * int a single C statement (which needs a semi-colon terminator).  This
 * avoids problems with code like:
 *
 * 	if ( condition_holds )
 *		yyless( 5 );
 *	else
 *		do_something_else();
 *
 * Prior to using the do-while the compiler would get upset at the
 * "else" because it interpreted the "if" statement as being all
 * done when it reached the ';' after the yyless() call.
 */

/* Return all but the first 'n' matched characters back to the input stream. */

#define yyless(n) \
	do \
		{ \
		/* Undo effects of setting up yytext. */ \
		*yy_cp = yy_hold_char; \
		YY_RESTORE_YY_MORE_OFFSET \
		yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
		} \
	while ( 0 )

#define unput(c) yyunput( c, yytext_ptr )

/* The following is because we cannot portably get our hands on size_t
 * (without autoconf's help, which isn't available because we want
 * flex-generated scanners to compile on their own).
 */
typedef unsigned int yy_size_t;


struct yy_buffer_state
	{
	FILE *yy_input_file;

	char *yy_ch_buf;		/* input buffer */
	char *yy_buf_pos;		/* current position in input buffer */

	/* Size of input buffer in bytes, not including room for EOB
	 * characters.
	 */
	yy_size_t yy_buf_size;

	/* Number of characters read into yy_ch_buf, not including EOB
	 * characters.
	 */
	int yy_n_chars;

	/* Whether we "own" the buffer - i.e., we know we created it,
	 * and can realloc() it to grow it, and should free() it to
	 * delete it.
	 */
	int yy_is_our_buffer;

	/* Whether this is an "interactive" input source; if so, and
	 * if we're using stdio for input, then we want to use getc()
	 * instead of fread(), to make sure we stop fetching input after
	 * each newline.
	 */
	int yy_is_interactive;

	/* Whether we're considered to be at the beginning of a line.
	 * If so, '^' rules will be active on the next match, otherwise
	 * not.
	 */
	int yy_at_bol;

	/* Whether to try to fill the input buffer when we reach the
	 * end of it.
	 */
	int yy_fill_buffer;

	int yy_buffer_status;
#define YY_BUFFER_NEW 0
#define YY_BUFFER_NORMAL 1
	/* When an EOF's been seen but there's still some text to process
	 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
	 * shouldn't try reading from the input source any more.  We might
	 * still have a bunch of tokens to match, though, because of
	 * possible backing-up.
	 *
	 * When we actually see the EOF, we change the status to "new"
	 * (via yyrestart()), so that the user can continue scanning by
	 * just pointing yyin at a new input file.
	 */
#define YY_BUFFER_EOF_PENDING 2
	};

static YY_BUFFER_STATE yy_current_buffer = 0;

/* We provide macros for accessing buffer states in case in the
 * future we want to put the buffer states in a more general
 * "scanner state".
 */
#define YY_CURRENT_BUFFER yy_current_buffer


/* yy_hold_char holds the character lost when yytext is formed. */
static char yy_hold_char;

static int yy_n_chars;		/* number of characters read into yy_ch_buf */


int yyleng;

/* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0;
static int yy_init = 1;		/* whether we need to initialize */
static int yy_start = 0;	/* start state number */

/* Flag which is used to allow yywrap()'s to do buffer switches
 * instead of setting up a fresh yyin.  A bit of a hack ...
 */
static int yy_did_buffer_switch_on_eof;

void yyrestart YY_PROTO(( FILE *input_file ));

void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
void yy_load_buffer_state YY_PROTO(( void ));
YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )

YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));

static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
static void yy_flex_free YY_PROTO(( void * ));

#define yy_new_buffer yy_create_buffer

#define yy_set_interactive(is_interactive) \
	{ \
	if ( ! yy_current_buffer ) \
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
	yy_current_buffer->yy_is_interactive = is_interactive; \
	}

#define yy_set_bol(at_bol) \
	{ \
	if ( ! yy_current_buffer ) \
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
	yy_current_buffer->yy_at_bol = at_bol; \
	}

#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)


#define yywrap() 1
#define YY_SKIP_YYWRAP
typedef unsigned char YY_CHAR;
FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
typedef int yy_state_type;
extern char *yytext;
#define yytext_ptr yytext

static yy_state_type yy_get_previous_state YY_PROTO(( void ));
static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
static int yy_get_next_buffer YY_PROTO(( void ));
static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));

/* Done after the current pattern has been matched and before the
 * corresponding action - sets up yytext.
 */
#define YY_DO_BEFORE_ACTION \
	yytext_ptr = yy_bp; \
	yyleng = (int) (yy_cp - yy_bp); \
	yy_hold_char = *yy_cp; \
	*yy_cp = '\0'; \
	yy_c_buf_p = yy_cp;

#define YY_NUM_RULES 31
#define YY_END_OF_BUFFER 32
static yyconst short int yy_accept[334] =
    {   0,
        0,    0,   23,   23,    0,    0,   32,   27,   28,   27,
       27,   23,   24,   25,   23,   23,   23,   23,   23,   23,
       23,   23,   23,   23,   23,   29,   30,   27,   28,   27,
       27,   23,    0,    0,    0,   22,    0,   24,   25,   23,
       23,   23,   23,   23,   23,   23,   23,   23,   23,   23,
       23,   23,   23,   29,   30,   27,   27,   23,   23,   12,
       23,   23,   23,   23,   23,   23,   23,   23,   23,   23,
       23,   11,   23,   23,   23,   23,   26,   27,   27,   13,
       12,    0,    0,   23,   23,   23,   23,   23,   23,   23,
       23,   23,   23,   23,   11,    0,    0,   23,   23,   23,

       23,   27,   13,    0,    0,    0,   23,    7,    9,   23,
       23,   23,   23,   23,   23,   23,   23,    0,   23,   23,
       23,   23,   27,    0,   12,   23,    7,    0,    0,    9,
        0,    0,   23,   23,   23,   23,   23,   23,   23,   23,
       11,   23,   23,   23,   23,   27,   13,   23,    0,    0,
       23,   23,   23,   23,   23,   10,   18,   23,   23,   23,
       23,   23,   27,   23,    7,    9,   23,   23,   23,   23,
       23,   10,    0,    0,   18,    0,    0,    8,   23,   23,
       23,   23,   27,   23,   23,   23,   23,   20,   23,   17,
        0,    0,    8,    0,    0,   23,   23,    3,   19,   27,

       23,   23,   23,   23,   23,   20,    0,    0,   23,   17,
        0,    0,   10,   18,    0,   23,   23,    3,    0,    0,
       19,    0,    0,   27,   23,   23,   23,   23,   14,    0,
       16,   17,   17,    0,    8,    2,   23,    0,    0,   27,
       23,   23,   23,   15,   14,    0,    0,   20,   16,    0,
        0,   17,    2,    0,    0,   21,    3,   19,   27,   23,
       23,    4,   15,    0,    0,    0,    0,    0,   21,    0,
        0,   27,   23,   23,    4,    0,    0,    0,   14,   16,
        2,    0,   27,   23,   23,    0,   15,   21,   27,   27,
       23,   23,    4,   27,   27,   23,   23,   27,   23,   23,

       27,   23,   23,   27,    5,   23,   27,    5,    0,    0,
       23,   27,    0,   23,   27,    5,   23,   27,   23,   27,
       23,   27,    6,   27,    6,    0,    0,   27,    0,   27,
        6,    1,    0
    } ;

static yyconst int yy_ec[256] =
    {   0,
        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
        1,    1,    4,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    5,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    6,    1,    1,    7,    7,    7,
        7,    7,    7,    7,    7,    7,    7,    8,    1,    1,
        1,    1,    1,    1,    9,   10,   11,   12,   13,   14,
       15,   16,   17,   18,   16,   19,   20,   21,   22,   23,
       16,   24,   25,   26,   27,   28,   16,   29,   30,   16,
        1,    1,    1,    1,    1,    1,    9,   10,   11,   12,

       13,   14,   15,   16,   17,   18,   16,   19,   20,   21,
       22,   23,   16,   24,   25,   26,   27,   28,   16,   29,
       30,   16,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,

        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1
    } ;

static yyconst int yy_meta[31] =
    {   0,
        1,    1,    2,    3,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1
    } ;

static yyconst short int yy_base[390] =
    {   0,
        0,    1,    5,   13,  851,  839,  824,    0,  815,  803,
      776,    7,   16,    9,   25,   40,   43,   31,   28,   50,
       53,   64,   56,   61,   66,    0,  785,    0,  782,    0,
      757,   70,    0,  761,    0,  874,  733,   77,  723,   72,
       81,   84,   89,   91,   93,   97,  120,   99,  103,  106,
      122,  114,  141,    0,  718,  125,  688,  129,  132,  134,
      138,  143,  145,  147,  149,  154,  156,  159,  169,  172,
      176,  179,  181,  183,  186,  188,  874,  193,  690,  196,
      200,   43,  684,  203,  205,  207,  214,  216,  218,  220,
      225,  227,  229,  233,  235,   56,  682,  239,  244,  246,

      248,  106,  250,  256,  669,    0,  256,  262,  264,  266,
      268,  270,  272,  275,  283,  287,  289,    0,  292,  299,
      301,  305,  292,    0,  307,  310,  312,  317,  649,  314,
      321,  635,  321,  324,  326,  329,  331,  338,  340,  348,
      350,  352,  355,  359,  361,  388,  365,  367,    0,    0,
      372,  374,  379,  394,  381,  383,  396,  403,  405,  409,
      411,  413,  438,  421,  416,  418,  423,  433,  445,  428,
      448,  451,  399,  616,  454,  457,  608,  457,  460,  462,
      464,  466,  482,  474,  472,  489,  491,  476,  494,  496,
        0,    0,  501,  504,  604,  504,  507,  509,  513,  556,

      517,  519,  521,  523,  528,  531,  535,  547,  535,  543,
      547,  545,  550,  552,    0,  554,  556,  560,  563,  538,
      563,  567,  526,  579,  567,  570,  585,  574,  572,    0,
      589,  591,  593,    0,  596,  598,  600,    0,    0,  608,
      602,  614,  617,  619,  623,  626,  515,  626,  629,  632,
      511,  632,  637,  640,  498,  640,  643,  645,  649,  655,
      657,  659,  661,  664,  482,    0,    0,    0,  664,  668,
      470,  466,  671,  673,  675,  679,  427,    0,  679,  686,
      688,    0,  114,  690,  693,    0,  695,  697,  421,  163,
      701,  703,  699,  416,  405,  707,  709,  374,  711,  716,

      371,  720,  722,  359,  727,  731,  353,  735,  738,  346,
      738,  339,    0,  741,  338,  743,  745,  331,  748,  301,
      751,  292,  753,  281,  757,  760,  281,  275,    0,  273,
      764,    0,  874,  768,  771,  774,  777,  780,  783,  786,
      261,  789,  792,  795,  798,  240,  801,  804,  233,  225,
      807,  211,  200,  810,  813,  816,  819,  822,  825,  828,
      192,  187,  831,  834,  837,  176,  840,  843,  154,  846,
      138,  849,  113,  103,  852,  855,  858,  861,  864,   97,
       70,   49,   40,   25,   21,  867,   13,  870,    0
    } ;

static yyconst short int yy_def[390] =
    {   0,
      334,  334,  335,  335,  336,  336,  333,  337,  333,  337,
      337,  338,  333,  333,  338,  338,  338,  338,  338,  338,
      338,  338,  338,  338,  338,  339,  333,  337,  333,  340,
      337,  338,  333,  333,  341,  333,  333,  333,  333,  338,
      338,  338,  338,  338,  338,  338,  338,  338,  338,  338,
      338,  338,  338,  339,  333,  340,  337,  341,  338,  342,
      338,  338,  338,  338,  338,  338,  338,  338,  338,  338,
      338,  343,  338,  338,  338,  338,  333,  340,  337,  344,
      342,  333,  333,  338,  338,  338,  338,  338,  338,  338,
      338,  338,  338,  338,  343,  333,  333,  338,  338,  338,

      338,  345,  344,  333,  333,  346,  338,  347,  348,  338,
      338,  338,  338,  338,  338,  338,  338,  349,  338,  338,
      338,  338,  345,  350,  346,  338,  347,  333,  333,  348,
      333,  333,  338,  338,  338,  338,  338,  338,  338,  338,
      349,  338,  338,  338,  338,  351,  350,  338,  352,  353,
      338,  338,  338,  338,  338,  354,  355,  338,  338,  338,
      338,  338,  356,  338,  352,  353,  338,  338,  338,  338,
      338,  354,  333,  333,  355,  333,  333,  357,  338,  338,
      338,  338,  358,  338,  338,  338,  338,  359,  338,  360,
      361,  362,  357,  333,  333,  338,  338,  363,  364,  337,

      338,  338,  338,  338,  338,  359,  333,  333,  338,  365,
      333,  333,  361,  362,  366,  338,  338,  363,  333,  333,
      364,  333,  333,  367,  338,  338,  338,  338,  368,  369,
      370,  365,  360,  371,  366,  372,  338,  373,  374,  375,
      338,  338,  338,  376,  368,  333,  333,  369,  370,  333,
      333,  371,  372,  333,  333,  377,  373,  374,  378,  338,
      338,  379,  376,  333,  333,  380,  381,  382,  377,  333,
      333,  337,  338,  338,  379,  333,  333,  383,  380,  381,
      382,  384,  337,  338,  338,  385,  383,  384,  337,  337,
      338,  338,  385,  337,  337,  338,  338,  337,  338,  338,

      337,  338,  338,  337,  386,  338,  337,  386,  333,  333,
      338,  337,  387,  338,  337,  387,  338,  337,  338,  337,
      338,  337,  388,  337,  388,  333,  333,  337,  389,  337,
      389,  337,    0,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333
    } ;

static yyconst short int yy_nxt[905] =
    {   0,
      331,   35,    9,    9,   35,   10,   10,   13,   14,   33,
       34,   38,   39,  316,   11,   13,   14,   35,   36,   37,
       35,  293,   15,   16,   17,  288,   18,   33,   34,   19,
       33,   34,   20,   33,   34,   40,   21,   22,   23,   24,
      287,   25,   33,   34,  106,   33,   34,  106,   45,  281,
       41,   43,   33,   34,   44,   33,   34,  118,   33,   34,
      118,   42,   46,   33,   34,   47,   33,   34,   33,   34,
      280,   53,   33,   34,   33,   34,   48,   51,   35,   36,
       37,   35,   59,   33,   34,   52,   33,   34,   60,   49,
       50,   33,   34,   33,   34,   33,   34,  279,   64,   33,

       34,   33,   34,  258,   61,   33,   34,   28,   33,   34,
       28,   70,   63,  257,   62,   71,   33,   34,  289,   69,
      290,   65,   33,   34,   33,   34,   73,   77,   78,   72,
       66,   33,   34,   67,   33,   34,   82,   83,  252,   80,
       33,   34,   68,   33,   34,   33,   34,   33,   34,   33,
       34,   33,   34,   74,  248,   85,   33,   34,   33,   34,
       75,   33,   34,   84,   86,   76,   89,  294,   90,  295,
       87,   33,   34,   88,   33,   34,  235,   91,   33,   34,
       92,   96,   97,   33,   34,   33,   34,  214,   33,   34,
       33,   34,  213,   94,  100,   77,   78,   93,  104,  105,

      166,   99,   82,   83,   98,   33,   34,   33,   34,   33,
       34,  165,  108,  101,  109,  107,   33,   34,   33,   34,
       33,   34,   33,   34,  111,  147,  110,   33,   34,   33,
       34,   33,   34,  141,  112,   33,   34,   96,   97,  115,
      125,   33,   34,  113,  119,  117,   33,   34,   33,   34,
       33,   34,  104,  105,  114,  116,  122,  124,   33,   34,
      124,   58,  121,  120,  128,  129,  131,  132,   33,   34,
       33,   34,   33,   34,   33,   34,  126,   33,   34,  332,
      137,  330,  134,  326,  136,   33,   34,  328,  133,   33,
       34,   33,   34,   28,   33,   34,  146,  135,  324,  140,

      142,   33,   34,   33,   34,  322,  138,   33,   34,   82,
       83,  139,   33,   34,  128,  129,  131,  132,  149,  144,
      143,  149,  150,   33,   34,  150,   33,   34,   33,   34,
      145,   33,   34,   33,   34,  148,  152,  320,  153,  151,
       33,   34,   33,   34,  318,  156,  315,  157,  309,  154,
       33,   34,   96,   97,   33,   34,  155,   33,   34,  312,
      160,   33,   34,   33,   34,  307,  159,  104,  105,   33,
       34,  161,  164,  158,   33,   34,   33,   34,  304,  168,
      301,   33,   34,   33,   34,  173,  174,  162,   28,   28,
      169,   28,  146,   28,   28,   28,   33,   34,  176,  177,

      191,  167,  171,  191,  170,   33,   34,   33,   34,  294,
      178,   33,   34,   33,   34,   33,   34,  179,  128,  129,
      131,  132,  298,   33,   34,   33,   34,  290,  186,  276,
       33,   34,  184,  180,  181,   33,   34,  182,   28,   28,
      189,   28,   28,   28,   28,   28,  185,   33,   34,  187,
       33,   34,  188,  173,  174,  190,  176,  177,  192,  194,
      195,  192,   33,   34,   33,   34,   33,   34,   33,   34,
      283,  198,  270,  199,   33,   34,   33,   34,  207,  208,
      196,  197,   28,   28,  264,   28,   28,   28,   28,   28,
      201,   33,   34,   33,   34,  202,   33,   34,  211,  212,

      254,  203,  205,  194,  195,  215,   33,   34,  215,   33,
       34,  219,  220,  250,  204,  222,  223,  246,  209,   33,
       34,   33,   34,   33,   34,   33,   34,  226,  222,  216,
       33,   34,  217,  207,  208,  229,  230,   33,   34,  230,
      219,  225,  231,  227,  228,  211,  212,  211,  234,  207,
      233,  234,  173,  174,  176,  177,   33,   34,   33,   34,
      224,  236,  219,  220,  238,  222,  223,  238,  239,   33,
       34,  239,   33,   34,  246,  247,   33,   34,  237,   28,
       28,  244,   28,   28,   28,   28,   28,   33,   34,  241,
      242,  250,  251,  211,  212,  211,  212,  243,  194,  195,

      254,  255,   33,   34,   33,   34,  194,  256,   28,   28,
      176,   28,   28,   28,   28,   28,   33,   34,  173,   33,
       34,  264,  265,  260,  262,  246,  247,  266,  207,  208,
      266,  250,  251,  267,  211,  212,  267,  131,  261,  254,
      255,  268,  270,  271,  268,  219,  220,  222,  223,   28,
       28,  128,   28,   28,   28,   28,   28,   33,   34,   33,
       34,  276,  277,  264,  265,  278,  270,  271,  278,  282,
      274,  104,  282,   33,   34,   33,   34,  276,  277,  273,
      286,  246,  247,  286,   96,  285,   82,  284,  250,  251,
      254,  255,   33,   34,  102,   33,   34,  264,  265,  270,

      271,  276,  277,   33,   34,   33,   34,   79,  297,   33,
       34,   33,   34,   33,   34,  291,  292,  296,   33,   34,
       55,  300,   33,   34,   33,   34,   39,  305,  299,  309,
      310,  302,  306,   33,   34,   36,  303,  309,  310,  313,
       33,   34,  313,   33,   34,  309,  310,   33,   34,  314,
       33,   34,  311,   33,   34,  326,  327,  317,  323,  326,
      327,  329,  321,   33,  329,  319,  326,  327,    8,    8,
        8,   12,   12,   12,   26,   26,   26,   28,   57,   28,
       32,   32,   32,   54,   29,   54,   56,   55,   56,   81,
       81,   81,   95,   95,   95,  103,  103,  103,  123,   31,

      123,  127,  127,  127,  130,  130,  130,  163,   30,  163,
      172,  172,  172,  175,  175,  175,  183,   29,  183,  193,
      193,  193,  200,  333,  200,  206,  206,  206,  210,  210,
      210,  218,  218,  218,  221,  221,  221,  232,  232,  232,
      240,   27,  240,  245,  245,  245,  249,  249,  249,  253,
      253,  253,  259,   27,  259,  263,  263,  263,  269,  269,
      269,  272,  333,  272,  275,  275,  275,  308,  308,  308,
      325,  325,  325,    7,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,

      333,  333,  333,  333
    } ;

static yyconst short int yy_chk[905] =
    {   0,
      389,   33,    1,    2,   33,    1,    2,    3,    3,   12,
       12,   14,   14,  387,    2,    4,    4,   13,   13,   13,
       13,  385,    4,    4,    4,  384,    4,   15,   15,    4,
       19,   19,    4,   18,   18,   15,    4,    4,    4,    4,
      383,    4,   16,   16,   82,   17,   17,   82,   19,  382,
       16,   17,   20,   20,   18,   21,   21,   96,   23,   23,
       96,   16,   20,   24,   24,   21,   22,   22,   25,   25,
      381,   25,   32,   32,   40,   40,   22,   23,   38,   38,
       38,   38,   40,   41,   41,   24,   42,   42,   41,   22,
       22,   43,   43,   44,   44,   45,   45,  380,   45,   46,

       46,   48,   48,  374,   42,   49,   49,  102,   50,   50,
      102,   49,   44,  373,   43,   50,   52,   52,  283,   48,
      283,   46,   47,   47,   51,   51,   52,   56,   56,   51,
       47,   58,   58,   47,   59,   59,   60,   60,  371,   59,
       61,   61,   47,   53,   53,   62,   62,   63,   63,   64,
       64,   65,   65,   53,  369,   62,   66,   66,   67,   67,
       53,   68,   68,   61,   63,   53,   66,  290,   67,  290,
       64,   69,   69,   65,   70,   70,  366,   68,   71,   71,
       69,   72,   72,   73,   73,   74,   74,  362,   75,   75,
       76,   76,  361,   71,   75,   78,   78,   70,   80,   80,

      353,   74,   81,   81,   73,   84,   84,   85,   85,   86,
       86,  352,   85,   76,   86,   84,   87,   87,   88,   88,
       89,   89,   90,   90,   88,  350,   87,   91,   91,   92,
       92,   93,   93,  349,   89,   94,   94,   95,   95,   92,
      346,   98,   98,   90,   98,   94,   99,   99,  100,  100,
      101,  101,  103,  103,   91,   93,  101,  104,  107,  107,
      104,  341,  100,   99,  108,  108,  109,  109,  110,  110,
      111,  111,  112,  112,  113,  113,  107,  114,  114,  330,
      114,  328,  111,  327,  113,  115,  115,  324,  110,  116,
      116,  117,  117,  123,  119,  119,  123,  112,  322,  117,

      119,  120,  120,  121,  121,  320,  115,  122,  122,  125,
      125,  116,  126,  126,  127,  127,  130,  130,  128,  121,
      120,  128,  131,  133,  133,  131,  134,  134,  135,  135,
      122,  136,  136,  137,  137,  126,  134,  318,  135,  133,
      138,  138,  139,  139,  315,  138,  312,  139,  310,  136,
      140,  140,  141,  141,  142,  142,  137,  143,  143,  307,
      143,  144,  144,  145,  145,  304,  142,  147,  147,  148,
      148,  144,  148,  140,  151,  151,  152,  152,  301,  152,
      298,  153,  153,  155,  155,  156,  156,  145,  146,  146,
      153,  146,  146,  146,  146,  146,  154,  154,  157,  157,

      173,  151,  155,  173,  154,  158,  158,  159,  159,  295,
      158,  160,  160,  161,  161,  162,  162,  159,  165,  165,
      166,  166,  294,  164,  164,  167,  167,  289,  167,  277,
      170,  170,  164,  160,  161,  168,  168,  162,  163,  163,
      170,  163,  163,  163,  163,  163,  164,  169,  169,  168,
      171,  171,  169,  172,  172,  171,  175,  175,  176,  178,
      178,  176,  179,  179,  180,  180,  181,  181,  182,  182,
      272,  181,  271,  182,  185,  185,  184,  184,  188,  188,
      179,  180,  183,  183,  265,  183,  183,  183,  183,  183,
      184,  186,  186,  187,  187,  185,  189,  189,  190,  190,

      255,  185,  187,  193,  193,  194,  196,  196,  194,  197,
      197,  198,  198,  251,  186,  199,  199,  247,  189,  201,
      201,  202,  202,  203,  203,  204,  204,  202,  223,  196,
      205,  205,  197,  206,  206,  205,  207,  209,  209,  207,
      220,  201,  209,  203,  204,  210,  210,  212,  211,  208,
      210,  211,  213,  213,  214,  214,  216,  216,  217,  217,
      200,  216,  218,  218,  219,  221,  221,  219,  222,  225,
      225,  222,  226,  226,  229,  229,  228,  228,  217,  224,
      224,  228,  224,  224,  224,  224,  224,  227,  227,  225,
      226,  231,  231,  232,  232,  233,  233,  227,  235,  235,

      236,  236,  237,  237,  241,  241,  195,  237,  240,  240,
      177,  240,  240,  240,  240,  240,  242,  242,  174,  243,
      243,  244,  244,  241,  243,  245,  245,  246,  248,  248,
      246,  249,  249,  250,  252,  252,  250,  132,  242,  253,
      253,  254,  256,  256,  254,  257,  257,  258,  258,  259,
      259,  129,  259,  259,  259,  259,  259,  260,  260,  261,
      261,  262,  262,  263,  263,  264,  269,  269,  264,  270,
      261,  105,  270,  273,  273,  274,  274,  275,  275,  260,
      276,  279,  279,  276,   97,  274,   83,  273,  280,  280,
      281,  281,  284,  284,   79,  285,  285,  287,  287,  288,

      288,  293,  293,  291,  291,  292,  292,   57,  292,  296,
      296,  297,  297,  299,  299,  284,  285,  291,  300,  300,
       55,  297,  302,  302,  303,  303,   39,  302,  296,  305,
      305,  299,  303,  306,  306,   37,  300,  308,  308,  309,
      311,  311,  309,  314,  314,  316,  316,  317,  317,  311,
      319,  319,  306,  321,  321,  323,  323,  314,  321,  325,
      325,  326,  319,   34,  326,  317,  331,  331,  334,  334,
      334,  335,  335,  335,  336,  336,  336,  337,   31,  337,
      338,  338,  338,  339,   29,  339,  340,   27,  340,  342,
      342,  342,  343,  343,  343,  344,  344,  344,  345,   11,

      345,  347,  347,  347,  348,  348,  348,  351,   10,  351,
      354,  354,  354,  355,  355,  355,  356,    9,  356,  357,
      357,  357,  358,    7,  358,  359,  359,  359,  360,  360,
      360,  363,  363,  363,  364,  364,  364,  365,  365,  365,
      367,    6,  367,  368,  368,  368,  370,  370,  370,  372,
      372,  372,  375,    5,  375,  376,  376,  376,  377,  377,
      377,  378,    0,  378,  379,  379,  379,  386,  386,  386,
      388,  388,  388,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,
      333,  333,  333,  333,  333,  333,  333,  333,  333,  333,

      333,  333,  333,  333
    } ;

static yy_state_type yy_last_accepting_state;
static char *yy_last_accepting_cpos;

/* The intent behind this definition is that it'll catch
 * any uses of REJECT which flex missed.
 */
#define REJECT reject_used_but_not_detected
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "mlex.l"
#define INITIAL 0
/* -*- c -*-

   elmo - ELectronic Mail Operator

   Copyright (C) 2002, 2003, 2004 rzyjontko

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

   ------------------------------------------------------------
*/
#line 24 "mlex.l"

#define __USE_XOPEN
#define _GNU_SOURCE

/****************************************************************************
 *    IMPLEMENTATION HEADERS
 ****************************************************************************/

#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <regex.h>

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif

#include "xmalloc.h"  
#include "mlex.h"
#include "mail.h"
#include "mbox.h"
#include "hash.h"
#include "elmo.h"
#include "address.h"
#include "raddress.h"
#include "error.h"
#include "rstring.h"
#include "mime.h"
#include "rmime.h"
#include "compose.h"
#include "misc.h"

/****************************************************************************
 *    IMPLEMENTATION PRIVATE DEFINITIONS / ENUMERATIONS / SIMPLE TYPEDEFS
 ****************************************************************************/
  
#define EXECUTE(fun) ((fun) ? fun (), 0 : 0)
#define YY_DECL  int mlex_scan YY_PROTO ((void))
#define YY_BREAK offset += yyleng; break;


/* this means currently processed message, that is going to be added */
#define a_mail (mail + mail_index)

#define ATEXT "([[:alpha:][:digit:]!#\\$%&\\\\\\'\\*\\+\\/\\=\\?\\^_\\`" \
              "\\{\\}\\~\\|\\-])"
#define DOT_ATOM_TEXT "(" ATEXT "+(\\." ATEXT "+)*)"
#define DOT_ATOM "(" DOT_ATOM_TEXT ")"
#define EMAIL_RE "(" DOT_ATOM "@" DOT_ATOM ")"
#define FOR_EMAIL_RE "for <" EMAIL_RE ">;"
#define WITH_SMTP_RE "with E?SMTP"

#define MAX_BOUNDARY_LEN 80

/****************************************************************************
 *    IMPLEMENTATION PRIVATE CLASS PROTOTYPES / EXTERNAL CLASS REFERENCES
 ****************************************************************************/
/****************************************************************************
 *    IMPLEMENTATION PRIVATE STRUCTURES / UTILITY CLASSES
 ****************************************************************************/

        struct bound {
                char    boundary[MAX_BOUNDARY_LEN];
                int     boundary_len;
                mime_t *mime;
        };

/****************************************************************************
 *    IMPLEMENTATION REQUIRED EXTERNAL REFERENCES (AVOID)
 ****************************************************************************/
/****************************************************************************
 *    IMPLEMENTATION PRIVATE DATA
 ****************************************************************************/

/*
  offset      means how many bytes we have already read
  mail[]      is where we write info about letter currently being read
  the one pointed by newmail (see below) is for reading
  the second one is for writing
  mail_index  may be 0 or 1, says which mail[] is for writing
*/
        static unsigned offset     = 0;
        static mail_t   mail[2];
        static int      mail_index = 0;


        /*
          We use stack to push, and pop all necessary data each time we
          encounter multipart mime type.  It has a constant size for the
          sake of simplicity.
        */
        static struct bound stack[5];
        static int          top;

        /* A regular expression used to get the boundary from the header. */
        static int     re_compiled = 0;
        static regex_t bound_re;
        
        /**
         * This shows if we are going to get EXACTLY ONE mail.  It is possible
         * that a mail in maildir has line beginning with "From_", just like
         * in mbox.  We must reject the rule then.
         */
        static int      only_one = 0;


        /* This is how I determine if custom headers should be saved
           in headers rstring. */
        static int collect_custom_headers = 0;


        /**
         * This holds a pointer to function which should be called after \n\n,
         * which ends header.  It may reset this variable, not to be called
         * once for each mime-header.
         */
        static void (*after_header_action)(void) = NULL;


/****************************************************************************
 *    INTERFACE DATA
 ****************************************************************************/

        mail_t *newmail = mail + 0;

/****************************************************************************
 *    IMPLEMENTATION PRIVATE FUNCTION PROTOTYPES
 ****************************************************************************/

        static char *unfold_content (char *content);
        static void  clear_mail (time_t tm);
        static void  write_headers (void);

        static mime_t *parent_mime (void);
        static mime_t *top_mime (void);
        static mime_t *top_or_parent_mime (void);
        static char   *top_boundary (void);
        static int     top_boundary_len (void);
        static void    pop (void);
        static void    push (char *boundary, int len);
        static void    replace_top_mime (mime_t *mime);

/****************************************************************************
 *    INTERFACE FUNCTIONS
 ****************************************************************************/

#define HEADER 1
#define FINISH 2

#line 865 "mlex.c"

/* Macros after this point can all be overridden by user definitions in
 * section 1.
 */

#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int yywrap YY_PROTO(( void ));
#else
extern int yywrap YY_PROTO(( void ));
#endif
#endif

#ifndef YY_NO_UNPUT
static void yyunput YY_PROTO(( int c, char *buf_ptr ));
#endif

#ifndef yytext_ptr
static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
#endif

#ifdef YY_NEED_STRLEN
static int yy_flex_strlen YY_PROTO(( yyconst char * ));
#endif

#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput YY_PROTO(( void ));
#else
static int input YY_PROTO(( void ));
#endif
#endif

#if YY_STACK_USED
static int yy_start_stack_ptr = 0;
static int yy_start_stack_depth = 0;
static int *yy_start_stack = 0;
#ifndef YY_NO_PUSH_STATE
static void yy_push_state YY_PROTO(( int new_state ));
#endif
#ifndef YY_NO_POP_STATE
static void yy_pop_state YY_PROTO(( void ));
#endif
#ifndef YY_NO_TOP_STATE
static int yy_top_state YY_PROTO(( void ));
#endif

#else
#define YY_NO_PUSH_STATE 1
#define YY_NO_POP_STATE 1
#define YY_NO_TOP_STATE 1
#endif

#ifdef YY_MALLOC_DECL
YY_MALLOC_DECL
#else
#if __STDC__
#ifndef __cplusplus
#include <stdlib.h>
#endif
#else
/* Just try to get by without declaring the routines.  This will fail
 * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
 * or sizeof(void*) != sizeof(int).
 */
#endif
#endif

/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#define YY_READ_BUF_SIZE 8192
#endif

/* Copy whatever the last rule matched to the standard output. */

#ifndef ECHO
/* This used to be an fputs(), but since the string might contain NUL's,
 * we now use fwrite().
 */
#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
#endif

/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
 * is returned in "result".
 */
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
	if ( yy_current_buffer->yy_is_interactive ) \
		{ \
		int c = '*', n; \
		for ( n = 0; n < max_size && \
			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
			buf[n] = (char) c; \
		if ( c == '\n' ) \
			buf[n++] = (char) c; \
		if ( c == EOF && ferror( yyin ) ) \
			YY_FATAL_ERROR( "input in flex scanner failed" ); \
		result = n; \
		} \
	else \
		{ \
		errno=0; \
		while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
			{ \
			if( errno != EINTR) \
				{ \
				YY_FATAL_ERROR( "input in flex scanner failed" ); \
				break; \
				} \
			errno=0; \
			clearerr(yyin); \
			} \
		}
#endif

/* No semi-colon after return; correct usage is to write "yyterminate();" -
 * we don't want an extra ';' after the "return" because that will cause
 * some compilers to complain about unreachable statements.
 */
#ifndef yyterminate
#define yyterminate() return YY_NULL
#endif

/* Number of entries by which start-condition stack grows. */
#ifndef YY_START_STACK_INCR
#define YY_START_STACK_INCR 25
#endif

/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
#endif

/* Default declaration of generated scanner - a define so the user can
 * easily add parameters.
 */
#ifndef YY_DECL
#define YY_DECL int yylex YY_PROTO(( void ))
#endif

/* Code executed at the beginning of each rule, after yytext and yyleng
 * have been set up.
 */
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif

/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK break;
#endif

#define YY_RULE_SETUP \
	if ( yyleng > 0 ) \
		yy_current_buffer->yy_at_bol = \
				(yytext[yyleng - 1] == '\n'); \
	YY_USER_ACTION

YY_DECL
	{
	register yy_state_type yy_current_state;
	register char *yy_cp, *yy_bp;
	register int yy_act;

#line 189 "mlex.l"


#line 1033 "mlex.c"

	if ( yy_init )
		{
		yy_init = 0;

#ifdef YY_USER_INIT
		YY_USER_INIT;
#endif

		if ( ! yy_start )
			yy_start = 1;	/* first start state */

		if ( ! yyin )
			yyin = stdin;

		if ( ! yyout )
			yyout = stdout;

		if ( ! yy_current_buffer )
			yy_current_buffer =
				yy_create_buffer( yyin, YY_BUF_SIZE );

		yy_load_buffer_state();
		}

	while ( 1 )		/* loops until end-of-file is reached */
		{
		yy_cp = yy_c_buf_p;

		/* Support of yytext. */
		*yy_cp = yy_hold_char;

		/* yy_bp points to the position in yy_ch_buf of the start of
		 * the current run.
		 */
		yy_bp = yy_cp;

		yy_current_state = yy_start;
		yy_current_state += YY_AT_BOL();
yy_match:
		do
			{
			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
			if ( yy_accept[yy_current_state] )
				{
				yy_last_accepting_state = yy_current_state;
				yy_last_accepting_cpos = yy_cp;
				}
			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
				{
				yy_current_state = (int) yy_def[yy_current_state];
				if ( yy_current_state >= 334 )
					yy_c = yy_meta[(unsigned int) yy_c];
				}
			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
			++yy_cp;
			}
		while ( yy_base[yy_current_state] != 874 );

yy_find_action:
		yy_act = yy_accept[yy_current_state];
		if ( yy_act == 0 )
			{ /* have to back up */
			yy_cp = yy_last_accepting_cpos;
			yy_current_state = yy_last_accepting_state;
			yy_act = yy_accept[yy_current_state];
			}

		YY_DO_BEFORE_ACTION;


do_action:	/* This label is used only to access EOF actions. */


		switch ( yy_act )
	{ /* beginning of action switch */
			case 0: /* must back up */
			/* undo the effects of YY_DO_BEFORE_ACTION */
			*yy_cp = yy_hold_char;
			yy_cp = yy_last_accepting_cpos;
			yy_current_state = yy_last_accepting_state;
			goto yy_find_action;

case 1:
YY_RULE_SETUP
#line 191 "mlex.l"
{

        struct tm  tm;
        char      *begin;
        char      *tmp;
        mime_t    *mime;
  
        if (only_one){
                YY_BREAK;
        }
  
        newmail    = mail + mail_index;
        mail_index = 1 - mail_index;
  
        /*
          finish last mail
        */
        if (!newmail->reply_to)
                newmail->reply_to = newmail->from;

        mime = top_mime ();
        if (mime){
                mime->off_bound = offset;
                mime->off_end   = offset;
        }

        /* this rule ends with return, so it does not reach YY_BREAK */
        offset += yyleng;

        /*
          begin new mail
        */
        begin = strchr (yytext, ' ');
        begin = strchr (begin + 1, ' ');
        while (*(begin + 1) == ' ')
                begin++;

        tmp   = strptime (begin + 5, "%b %e %T %Y", &tm);

        if (!tmp){
                error_ (0, "wrong time string");
                return BROKEN_MAIL;
        }
        if (*tmp){
                error_ (0, "not all parsed");
                return BROKEN_MAIL;
        }
        else {
                offset++;       /* to workaround \n that doesn't match */
                clear_mail (mktime (&tm));
                offset--;
        }
  
        BEGIN (HEADER);
        return NEXT_MAIL;
}
	YY_BREAK
case 2:
YY_RULE_SETUP
#line 250 "mlex.l"
{
        char *tmp = yytext + 11;

        while (isspace (*tmp))
                tmp++;
  
        if (a_mail->mua == NULL){
                a_mail->mua = unfold_content (tmp);
        }
}
	YY_BREAK
case 3:
YY_RULE_SETUP
#line 262 "mlex.l"
{
        char *tmp = yytext + 10;

        while (isspace (*tmp))
                tmp++;
  
        if (a_mail->mua == NULL){
                a_mail->mua = unfold_content (tmp);
        }
}
	YY_BREAK
case 4:
YY_RULE_SETUP
#line 274 "mlex.l"
{
        int         index;
        int         ret;
        int         len  = 0;
        regmatch_t  matches[4];
        mime_t     *mime = top_mime ();
        char       *str  = yytext + 12;

        mime_set_from_header (mime, str);

        ret = regexec (& bound_re, str, 4, matches, 0);
        
        if (ret == 0){
                index = (matches[2].rm_so != -1) ? 2 : 3;
                len   = matches[index].rm_eo - matches[index].rm_so;
                push (str + matches[index].rm_so, len);
        }
        else if (ret != REG_NOMATCH)
                error_regex (ret, & bound_re, "boundary regexp");
}
	YY_BREAK
case 5:
YY_RULE_SETUP
#line 296 "mlex.l"
{
        mime_t *mime = top_or_parent_mime ();

        if (mime)
                mime_complete_file_name (mime, yytext + 20);
}
	YY_BREAK
case 6:
YY_RULE_SETUP
#line 304 "mlex.l"
{
        mime_t *mime = top_mime ();

        if (mime){
                mime->encoding = MENC_NONE;

                if (strstr (yytext + 26, "uoted")
                    || strstr (yytext + 26, "UOTED"))
                        mime->encoding = MENC_QP;
                else if (strstr (yytext + 26, "ase64")
                         || strstr (yytext + 26, "ASE64"))
                        mime->encoding = MENC_BASE64;
                else if (strstr (yytext + 26, "uencode")
                         || strstr (yytext + 26, "UENCODE"))
                        mime->encoding = MENC_UUENCODE;
                else if (strstr (yytext + 26, "7bit")
                         || strstr (yytext + 26, "7BIT"))
                        mime->encoding = MENC_7BIT;
                else if (strstr (yytext + 26, "8bit")
                         || strstr (yytext + 26, "8BIT"))
                        mime->encoding = MENC_8BIT;
        }
}
	YY_BREAK
case 7:
YY_RULE_SETUP
#line 329 "mlex.l"
{
        char      *tmp  = yytext + 6;
        char      *date = unfold_content (tmp);
        static struct tm tm;

        a_mail->date_str = date;
  
        while (*date && ! isdigit (*date))
                date++;

#ifdef HAVE_LOCALE_H
        setlocale (LC_ALL, "C");
#endif

        /**
         * here is a hack that makes it possible to parse a date with
         * obsolete year notation (2 - digits),  we have to try the obsolete
         * one first, and check if it was possible to get the date
         */
        tmp = strptime (date, "%d %b %y %H:%M:%S", &tm);
        if (tmp == NULL)
                tmp = strptime (date, "%d %b %Y %H:%M:%S", &tm);

#ifdef HAVE_LOCALE_H
        setlocale (LC_ALL, "");
#endif

        a_mail->date = mktime (&tm);
}
	YY_BREAK
case 8:
YY_RULE_SETUP
#line 360 "mlex.l"
{
        char *tmp = yytext + 9;
        a_mail->subject = unfold_content (tmp);
}
	YY_BREAK
case 9:
YY_RULE_SETUP
#line 366 "mlex.l"
{
        char *tmp  = yytext + 6;
        char *from = unfold_content (tmp);

        a_mail->from = address_from_string (from);
        xfree (from);
}
	YY_BREAK
case 10:
YY_RULE_SETUP
#line 375 "mlex.l"
{
        char *tmp    = yytext + 8;
        char *sender = unfold_content (tmp);
  
        if (a_mail->from == NULL)
                a_mail->from = address_from_string (sender);
        xfree (sender);
}
	YY_BREAK
case 11:
YY_RULE_SETUP
#line 385 "mlex.l"
{
        char *tmp = yytext + 4;
        char *to  = unfold_content (tmp);
  
        a_mail->to = raddress_get_from_header (to);
        xfree (to);
}
	YY_BREAK
case 12:
YY_RULE_SETUP
#line 394 "mlex.l"
{
        char *tmp = yytext + 4;
        char *cc  = unfold_content (tmp);

        a_mail->cc = raddress_get_from_header (cc);
        xfree (cc);
}
	YY_BREAK
case 13:
YY_RULE_SETUP
#line 403 "mlex.l"
{
        char *tmp = yytext + 4;
        char *bcc = unfold_content (tmp);

        a_mail->bcc = raddress_get_from_header (bcc);
        xfree (bcc);
}
	YY_BREAK
case 14:
YY_RULE_SETUP
#line 412 "mlex.l"
{
        char  c;
        char *pine;
        char *tmp  = yytext + 12;

        a_mail->msg_id = unfold_content (tmp);
        if (a_mail->mua == NULL){
                tmp = strstr (a_mail->msg_id, "Pine");
                if (tmp){
                        pine = tmp + 13;
                        while (*pine != '.')
                                pine--;
                        c           = *pine;
                        *pine       = '\0';
                        a_mail->mua = xstrdup (tmp);
                        *pine       = c;
                }
        }
}
	YY_BREAK
case 15:
YY_RULE_SETUP
#line 433 "mlex.l"
{
        char      *tmp = yytext + 13;
        char      *irt;
        rstring_t *result;

        if (a_mail->in_reply_to == NULL){
                irt = unfold_content (tmp);
    
                result = rstring_create_size (2);
                result->allocated_first = 1;
                rstring_add (result, irt);
                rstring_shrink (result);
                a_mail->in_reply_to = result;
        }
}
	YY_BREAK
case 16:
YY_RULE_SETUP
#line 450 "mlex.l"
{
        char *tmp = yytext + 12;

        if (a_mail->in_reply_to){
                rstring_delete (a_mail->in_reply_to);
        }
  
        a_mail->in_reply_to = rstring_split_re (unfold_content (tmp), "[ \t\r\n]+");
        a_mail->in_reply_to->allocated_first = 1;
        rstring_shrink (a_mail->in_reply_to);
}
	YY_BREAK
case 17:
YY_RULE_SETUP
#line 463 "mlex.l"
{
        char *tmp      = yytext + 10;
        char *reply_to = unfold_content (tmp);


        a_mail->reply_to = address_from_string (reply_to);
        xfree (reply_to);
}
	YY_BREAK
case 18:
YY_RULE_SETUP
#line 473 "mlex.l"
{
        char *i;
        char *tmp = yytext + 8;

        if (! only_one){
                tmp       = unfold_content (tmp);

                for (i = tmp; *i; i++){
                        switch (*i){
                                case 'R':
                                        a_mail->flags |= FLAG_READ;
                                        break;
                                case 'O':
                                        a_mail->flags |= FLAG_OLD;
                                        break;
                                default:
                                        break;
                        }
                }

                xfree (tmp);
        }
}
	YY_BREAK
case 19:
YY_RULE_SETUP
#line 498 "mlex.l"
{
        char *i;
        char *tmp = yytext + 10;
        tmp       = unfold_content (tmp);

        for (i = tmp; *i; i++){
                switch (*i){
                        case 'A':
                                a_mail->flags |= FLAG_ANSWERED;
                                break;
                        default:
                                break;
                }
        }

        xfree (tmp);
}
	YY_BREAK
case 20:
YY_RULE_SETUP
#line 517 "mlex.l"
{
        int         len;
        char       *tmp;
        char       *recv_for;
        regmatch_t  matches[1];

        if (a_mail->recv_for == NULL){
                tmp      = yytext + 9;
                recv_for = unfold_content (tmp);

                if (misc_regex (WITH_SMTP_RE, recv_for, matches)
                    && misc_regex (FOR_EMAIL_RE, recv_for, matches)){
                        len = matches[0].rm_eo - matches[0].rm_so - 7 + 1;
                        tmp = xmalloc (len);
                        memcpy (tmp, recv_for + matches[0].rm_so + 5, len - 1);
                        tmp[len - 1] = '\0';
                        a_mail->recv_for = address_from_string (tmp);
                        xfree (tmp);
                }
                xfree (recv_for);
        }
}
	YY_BREAK
case 21:
YY_RULE_SETUP
#line 541 "mlex.l"
{
        a_mail->smtp = unfold_content (yytext + 12);
}
	YY_BREAK
case 22:
YY_RULE_SETUP
#line 546 "mlex.l"
{
        mime_t *mime = top_or_parent_mime ();
  
        BEGIN (INITIAL);
        EXECUTE (after_header_action);

        if (mime){
                mime->off_start = offset + yyleng;
        }
}
	YY_BREAK
case 23:
YY_RULE_SETUP
#line 558 "mlex.l"
{
        char *header;

        if (! collect_custom_headers){
                YY_BREAK;
        }

        header = unfold_content (yytext);

        if (a_mail->headers == NULL){
                a_mail->headers = rstring_create ();
                a_mail->headers->allocated_all = 1;
        }

        rstring_add (a_mail->headers, header);
}
	YY_BREAK
case 24:
YY_RULE_SETUP
#line 576 "mlex.l"

	YY_BREAK
case 25:
YY_RULE_SETUP
#line 579 "mlex.l"

	YY_BREAK
case 26:
YY_RULE_SETUP
#line 582 "mlex.l"
{
        int     len;
        char   *boundary;
        char   *seek;
        mime_t *mime;
        mime_t *parent;

        if (top == 0){
                YY_BREAK;
        }

        boundary = top_boundary ();
        len      = top_boundary_len ();
        
        if (boundary == NULL){
                YY_BREAK;
        }
        
        seek = strstr (yytext + 2, boundary);
        if (seek == NULL){
                YY_BREAK;
        }

        if (seek[len] == '-' && seek[len + 1] == '-'){
                mime            = top_or_parent_mime ();
                mime->off_bound = offset + yyleng;
                mime->off_end   = offset;
                pop ();
                YY_BREAK;
        }

        mime            = top_or_parent_mime ();
        mime->off_bound = offset;
        mime->off_end   = offset - 1;
        parent          = parent_mime ();

        if (parent->parts == NULL)
                parent->parts = rmime_create_size (4);

        mime             = mime_create ();
        mime->off_header = offset + yyleng;
        rmime_add (parent->parts, mime);
        replace_top_mime (mime);

        BEGIN (HEADER);
}
	YY_BREAK
case 27:
YY_RULE_SETUP
#line 630 "mlex.l"

	YY_BREAK
case 28:
YY_RULE_SETUP
#line 633 "mlex.l"

	YY_BREAK
case YY_STATE_EOF(HEADER):
#line 636 "mlex.l"
{

        only_one = 0;
        offset   = 0;

        mail_destroy (a_mail, BOX_MAILDIR);

        BEGIN (INITIAL);
        return EOF_AT_HEADER;
}
	YY_BREAK
case 29:
YY_RULE_SETUP
#line 648 "mlex.l"

	YY_BREAK
case 30:
YY_RULE_SETUP
#line 651 "mlex.l"

	YY_BREAK
case YY_STATE_EOF(FINISH):
#line 654 "mlex.l"
{

        BEGIN (INITIAL);
        return END_OF_FILE;

        /**
         * this is to get rid of warnings
         */
        yyunput (0, NULL);
        yy_flex_realloc (0, 0);
}
	YY_BREAK
case YY_STATE_EOF(INITIAL):
#line 667 "mlex.l"
{
        mime_t *mime;

        mime = top_or_parent_mime ();

        if (mime == NULL)
                return END_OF_FILE;

        mime->off_bound = offset;
        mime->off_end   = offset;
        if (! a_mail->reply_to)
                a_mail->reply_to = a_mail->from;

        BEGIN (FINISH);
        newmail  = mail + mail_index;
        only_one = 0;
        offset   = 0;
        return NEXT_MAIL;
}
	YY_BREAK
case 31:
YY_RULE_SETUP
#line 689 "mlex.l"
YY_FATAL_ERROR( "flex scanner jammed" );
	YY_BREAK
#line 1681 "mlex.c"

	case YY_END_OF_BUFFER:
		{
		/* Amount of text matched not including the EOB char. */
		int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;

		/* Undo the effects of YY_DO_BEFORE_ACTION. */
		*yy_cp = yy_hold_char;
		YY_RESTORE_YY_MORE_OFFSET

		if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
			{
			/* We're scanning a new file or input source.  It's
			 * possible that this happened because the user
			 * just pointed yyin at a new source and called
			 * yylex().  If so, then we have to assure
			 * consistency between yy_current_buffer and our
			 * globals.  Here is the right place to do so, because
			 * this is the first action (other than possibly a
			 * back-up) that will match for the new input source.
			 */
			yy_n_chars = yy_current_buffer->yy_n_chars;
			yy_current_buffer->yy_input_file = yyin;
			yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
			}

		/* Note that here we test for yy_c_buf_p "<=" to the position
		 * of the first EOB in the buffer, since yy_c_buf_p will
		 * already have been incremented past the NUL character
		 * (since all states make transitions on EOB to the
		 * end-of-buffer state).  Contrast this with the test
		 * in input().
		 */
		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
			{ /* This was really a NUL. */
			yy_state_type yy_next_state;

			yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;

			yy_current_state = yy_get_previous_state();

			/* Okay, we're now positioned to make the NUL
			 * transition.  We couldn't have
			 * yy_get_previous_state() go ahead and do it
			 * for us because it doesn't know how to deal
			 * with the possibility of jamming (and we don't
			 * want to build jamming into it because then it
			 * will run more slowly).
			 */

			yy_next_state = yy_try_NUL_trans( yy_current_state );

			yy_bp = yytext_ptr + YY_MORE_ADJ;

			if ( yy_next_state )
				{
				/* Consume the NUL. */
				yy_cp = ++yy_c_buf_p;
				yy_current_state = yy_next_state;
				goto yy_match;
				}

			else
				{
				yy_cp = yy_c_buf_p;
				goto yy_find_action;
				}
			}

		else switch ( yy_get_next_buffer() )
			{
			case EOB_ACT_END_OF_FILE:
				{
				yy_did_buffer_switch_on_eof = 0;

				if ( yywrap() )
					{
					/* Note: because we've taken care in
					 * yy_get_next_buffer() to have set up
					 * yytext, we can now set up
					 * yy_c_buf_p so that if some total
					 * hoser (like flex itself) wants to
					 * call the scanner after we return the
					 * YY_NULL, it'll still work - another
					 * YY_NULL will get returned.
					 */
					yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;

					yy_act = YY_STATE_EOF(YY_START);
					goto do_action;
					}

				else
					{
					if ( ! yy_did_buffer_switch_on_eof )
						YY_NEW_FILE;
					}
				break;
				}

			case EOB_ACT_CONTINUE_SCAN:
				yy_c_buf_p =
					yytext_ptr + yy_amount_of_matched_text;

				yy_current_state = yy_get_previous_state();

				yy_cp = yy_c_buf_p;
				yy_bp = yytext_ptr + YY_MORE_ADJ;
				goto yy_match;

			case EOB_ACT_LAST_MATCH:
				yy_c_buf_p =
				&yy_current_buffer->yy_ch_buf[yy_n_chars];

				yy_current_state = yy_get_previous_state();

				yy_cp = yy_c_buf_p;
				yy_bp = yytext_ptr + YY_MORE_ADJ;
				goto yy_find_action;
			}
		break;
		}

	default:
		YY_FATAL_ERROR(
			"fatal flex scanner internal error--no action found" );
	} /* end of action switch */
		} /* end of scanning one token */
	} /* end of yylex */


/* yy_get_next_buffer - try to read in a new buffer
 *
 * Returns a code representing an action:
 *	EOB_ACT_LAST_MATCH -
 *	EOB_ACT_CONTINUE_SCAN - continue scanning from current position
 *	EOB_ACT_END_OF_FILE - end of file
 */

static int yy_get_next_buffer()
	{
	register char *dest = yy_current_buffer->yy_ch_buf;
	register char *source = yytext_ptr;
	register int number_to_move, i;
	int ret_val;

	if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
		YY_FATAL_ERROR(
		"fatal flex scanner internal error--end of buffer missed" );

	if ( yy_current_buffer->yy_fill_buffer == 0 )
		{ /* Don't try to fill the buffer, so this is an EOF. */
		if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
			{
			/* We matched a single character, the EOB, so
			 * treat this as a final EOF.
			 */
			return EOB_ACT_END_OF_FILE;
			}

		else
			{
			/* We matched some text prior to the EOB, first
			 * process it.
			 */
			return EOB_ACT_LAST_MATCH;
			}
		}

	/* Try to read more data. */

	/* First move last chars to start of buffer. */
	number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;

	for ( i = 0; i < number_to_move; ++i )
		*(dest++) = *(source++);

	if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
		/* don't do the read, it's not guaranteed to return an EOF,
		 * just force an EOF
		 */
		yy_current_buffer->yy_n_chars = yy_n_chars = 0;

	else
		{
		int num_to_read =
			yy_current_buffer->yy_buf_size - number_to_move - 1;

		while ( num_to_read <= 0 )
			{ /* Not enough room in the buffer - grow it. */
#ifdef YY_USES_REJECT
			YY_FATAL_ERROR(
"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
#else

			/* just a shorter name for the current buffer */
			YY_BUFFER_STATE b = yy_current_buffer;

			int yy_c_buf_p_offset =
				(int) (yy_c_buf_p - b->yy_ch_buf);

			if ( b->yy_is_our_buffer )
				{
				int new_size = b->yy_buf_size * 2;

				if ( new_size <= 0 )
					b->yy_buf_size += b->yy_buf_size / 8;
				else
					b->yy_buf_size *= 2;

				b->yy_ch_buf = (char *)
					/* Include room in for 2 EOB chars. */
					yy_flex_realloc( (void *) b->yy_ch_buf,
							 b->yy_buf_size + 2 );
				}
			else
				/* Can't grow it, we don't own it. */
				b->yy_ch_buf = 0;

			if ( ! b->yy_ch_buf )
				YY_FATAL_ERROR(
				"fatal error - scanner input buffer overflow" );

			yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];

			num_to_read = yy_current_buffer->yy_buf_size -
						number_to_move - 1;
#endif
			}

		if ( num_to_read > YY_READ_BUF_SIZE )
			num_to_read = YY_READ_BUF_SIZE;

		/* Read in more data. */
		YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
			yy_n_chars, num_to_read );

		yy_current_buffer->yy_n_chars = yy_n_chars;
		}

	if ( yy_n_chars == 0 )
		{
		if ( number_to_move == YY_MORE_ADJ )
			{
			ret_val = EOB_ACT_END_OF_FILE;
			yyrestart( yyin );
			}

		else
			{
			ret_val = EOB_ACT_LAST_MATCH;
			yy_current_buffer->yy_buffer_status =
				YY_BUFFER_EOF_PENDING;
			}
		}

	else
		ret_val = EOB_ACT_CONTINUE_SCAN;

	yy_n_chars += number_to_move;
	yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
	yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;

	yytext_ptr = &yy_current_buffer->yy_ch_buf[0];

	return ret_val;
	}


/* yy_get_previous_state - get the state just before the EOB char was reached */

static yy_state_type yy_get_previous_state()
	{
	register yy_state_type yy_current_state;
	register char *yy_cp;

	yy_current_state = yy_start;
	yy_current_state += YY_AT_BOL();

	for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
		{
		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
		if ( yy_accept[yy_current_state] )
			{
			yy_last_accepting_state = yy_current_state;
			yy_last_accepting_cpos = yy_cp;
			}
		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
			{
			yy_current_state = (int) yy_def[yy_current_state];
			if ( yy_current_state >= 334 )
				yy_c = yy_meta[(unsigned int) yy_c];
			}
		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
		}

	return yy_current_state;
	}


/* yy_try_NUL_trans - try to make a transition on the NUL character
 *
 * synopsis
 *	next_state = yy_try_NUL_trans( current_state );
 */

#ifdef YY_USE_PROTOS
static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
#else
static yy_state_type yy_try_NUL_trans( yy_current_state )
yy_state_type yy_current_state;
#endif
	{
	register int yy_is_jam;
	register char *yy_cp = yy_c_buf_p;

	register YY_CHAR yy_c = 1;
	if ( yy_accept[yy_current_state] )
		{
		yy_last_accepting_state = yy_current_state;
		yy_last_accepting_cpos = yy_cp;
		}
	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
		{
		yy_current_state = (int) yy_def[yy_current_state];
		if ( yy_current_state >= 334 )
			yy_c = yy_meta[(unsigned int) yy_c];
		}
	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
	yy_is_jam = (yy_current_state == 333);

	return yy_is_jam ? 0 : yy_current_state;
	}


#ifndef YY_NO_UNPUT
#ifdef YY_USE_PROTOS
static void yyunput( int c, register char *yy_bp )
#else
static void yyunput( c, yy_bp )
int c;
register char *yy_bp;
#endif
	{
	register char *yy_cp = yy_c_buf_p;

	/* undo effects of setting up yytext */
	*yy_cp = yy_hold_char;

	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
		{ /* need to shift things up to make room */
		/* +2 for EOB chars. */
		register int number_to_move = yy_n_chars + 2;
		register char *dest = &yy_current_buffer->yy_ch_buf[
					yy_current_buffer->yy_buf_size + 2];
		register char *source =
				&yy_current_buffer->yy_ch_buf[number_to_move];

		while ( source > yy_current_buffer->yy_ch_buf )
			*--dest = *--source;

		yy_cp += (int) (dest - source);
		yy_bp += (int) (dest - source);
		yy_current_buffer->yy_n_chars =
			yy_n_chars = yy_current_buffer->yy_buf_size;

		if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
			YY_FATAL_ERROR( "flex scanner push-back overflow" );
		}

	*--yy_cp = (char) c;


	yytext_ptr = yy_bp;
	yy_hold_char = *yy_cp;
	yy_c_buf_p = yy_cp;
	}
#endif	/* ifndef YY_NO_UNPUT */


#ifdef __cplusplus
static int yyinput()
#else
static int input()
#endif
	{
	int c;

	*yy_c_buf_p = yy_hold_char;

	if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
		{
		/* yy_c_buf_p now points to the character we want to return.
		 * If this occurs *before* the EOB characters, then it's a
		 * valid NUL; if not, then we've hit the end of the buffer.
		 */
		if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
			/* This was really a NUL. */
			*yy_c_buf_p = '\0';

		else
			{ /* need more input */
			int offset = yy_c_buf_p - yytext_ptr;
			++yy_c_buf_p;

			switch ( yy_get_next_buffer() )
				{
				case EOB_ACT_LAST_MATCH:
					/* This happens because yy_g_n_b()
					 * sees that we've accumulated a
					 * token and flags that we need to
					 * try matching the token before
					 * proceeding.  But for input(),
					 * there's no matching to consider.
					 * So convert the EOB_ACT_LAST_MATCH
					 * to EOB_ACT_END_OF_FILE.
					 */

					/* Reset buffer status. */
					yyrestart( yyin );

					/* fall through */

				case EOB_ACT_END_OF_FILE:
					{
					if ( yywrap() )
						return EOF;

					if ( ! yy_did_buffer_switch_on_eof )
						YY_NEW_FILE;
#ifdef __cplusplus
					return yyinput();
#else
					return input();
#endif
					}

				case EOB_ACT_CONTINUE_SCAN:
					yy_c_buf_p = yytext_ptr + offset;
					break;
				}
			}
		}

	c = *(unsigned char *) yy_c_buf_p;	/* cast for 8-bit char's */
	*yy_c_buf_p = '\0';	/* preserve yytext */
	yy_hold_char = *++yy_c_buf_p;

	yy_current_buffer->yy_at_bol = (c == '\n');

	return c;
	}


#ifdef YY_USE_PROTOS
void yyrestart( FILE *input_file )
#else
void yyrestart( input_file )
FILE *input_file;
#endif
	{
	if ( ! yy_current_buffer )
		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );

	yy_init_buffer( yy_current_buffer, input_file );
	yy_load_buffer_state();
	}


#ifdef YY_USE_PROTOS
void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
#else
void yy_switch_to_buffer( new_buffer )
YY_BUFFER_STATE new_buffer;
#endif
	{
	if ( yy_current_buffer == new_buffer )
		return;

	if ( yy_current_buffer )
		{
		/* Flush out information for old buffer. */
		*yy_c_buf_p = yy_hold_char;
		yy_current_buffer->yy_buf_pos = yy_c_buf_p;
		yy_current_buffer->yy_n_chars = yy_n_chars;
		}

	yy_current_buffer = new_buffer;
	yy_load_buffer_state();

	/* We don't actually know whether we did this switch during
	 * EOF (yywrap()) processing, but the only time this flag
	 * is looked at is after yywrap() is called, so it's safe
	 * to go ahead and always set it.
	 */
	yy_did_buffer_switch_on_eof = 1;
	}


#ifdef YY_USE_PROTOS
void yy_load_buffer_state( void )
#else
void yy_load_buffer_state()
#endif
	{
	yy_n_chars = yy_current_buffer->yy_n_chars;
	yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
	yyin = yy_current_buffer->yy_input_file;
	yy_hold_char = *yy_c_buf_p;
	}


#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
#else
YY_BUFFER_STATE yy_create_buffer( file, size )
FILE *file;
int size;
#endif
	{
	YY_BUFFER_STATE b;

	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );

	b->yy_buf_size = size;

	/* yy_ch_buf has to be 2 characters longer than the size given because
	 * we need to put in 2 end-of-buffer characters.
	 */
	b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
	if ( ! b->yy_ch_buf )
		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );

	b->yy_is_our_buffer = 1;

	yy_init_buffer( b, file );

	return b;
	}


#ifdef YY_USE_PROTOS
void yy_delete_buffer( YY_BUFFER_STATE b )
#else
void yy_delete_buffer( b )
YY_BUFFER_STATE b;
#endif
	{
	if ( ! b )
		return;

	if ( b == yy_current_buffer )
		yy_current_buffer = (YY_BUFFER_STATE) 0;

	if ( b->yy_is_our_buffer )
		yy_flex_free( (void *) b->yy_ch_buf );

	yy_flex_free( (void *) b );
	}


#ifndef _WIN32
#include <unistd.h>
#else
#ifndef YY_ALWAYS_INTERACTIVE
#ifndef YY_NEVER_INTERACTIVE
extern int isatty YY_PROTO(( int ));
#endif
#endif
#endif

#ifdef YY_USE_PROTOS
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
#else
void yy_init_buffer( b, file )
YY_BUFFER_STATE b;
FILE *file;
#endif


	{
	yy_flush_buffer( b );

	b->yy_input_file = file;
	b->yy_fill_buffer = 1;

#if YY_ALWAYS_INTERACTIVE
	b->yy_is_interactive = 1;
#else
#if YY_NEVER_INTERACTIVE
	b->yy_is_interactive = 0;
#else
	b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
#endif
#endif
	}


#ifdef YY_USE_PROTOS
void yy_flush_buffer( YY_BUFFER_STATE b )
#else
void yy_flush_buffer( b )
YY_BUFFER_STATE b;
#endif

	{
	if ( ! b )
		return;

	b->yy_n_chars = 0;

	/* We always need two end-of-buffer characters.  The first causes
	 * a transition to the end-of-buffer state.  The second causes
	 * a jam in that state.
	 */
	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;

	b->yy_buf_pos = &b->yy_ch_buf[0];

	b->yy_at_bol = 1;
	b->yy_buffer_status = YY_BUFFER_NEW;

	if ( b == yy_current_buffer )
		yy_load_buffer_state();
	}


#ifndef YY_NO_SCAN_BUFFER
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
#else
YY_BUFFER_STATE yy_scan_buffer( base, size )
char *base;
yy_size_t size;
#endif
	{
	YY_BUFFER_STATE b;

	if ( size < 2 ||
	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
	     base[size-1] != YY_END_OF_BUFFER_CHAR )
		/* They forgot to leave room for the EOB's. */
		return 0;

	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
	if ( ! b )
		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );

	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
	b->yy_buf_pos = b->yy_ch_buf = base;
	b->yy_is_our_buffer = 0;
	b->yy_input_file = 0;
	b->yy_n_chars = b->yy_buf_size;
	b->yy_is_interactive = 0;
	b->yy_at_bol = 1;
	b->yy_fill_buffer = 0;
	b->yy_buffer_status = YY_BUFFER_NEW;

	yy_switch_to_buffer( b );

	return b;
	}
#endif


#ifndef YY_NO_SCAN_STRING
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
#else
YY_BUFFER_STATE yy_scan_string( yy_str )
yyconst char *yy_str;
#endif
	{
	int len;
	for ( len = 0; yy_str[len]; ++len )
		;

	return yy_scan_bytes( yy_str, len );
	}
#endif


#ifndef YY_NO_SCAN_BYTES
#ifdef YY_USE_PROTOS
YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
#else
YY_BUFFER_STATE yy_scan_bytes( bytes, len )
yyconst char *bytes;
int len;
#endif
	{
	YY_BUFFER_STATE b;
	char *buf;
	yy_size_t n;
	int i;

	/* Get memory for full buffer, including space for trailing EOB's. */
	n = len + 2;
	buf = (char *) yy_flex_alloc( n );
	if ( ! buf )
		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );

	for ( i = 0; i < len; ++i )
		buf[i] = bytes[i];

	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;

	b = yy_scan_buffer( buf, n );
	if ( ! b )
		YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );

	/* It's okay to grow etc. this buffer, and we should throw it
	 * away when we're done.
	 */
	b->yy_is_our_buffer = 1;

	return b;
	}
#endif


#ifndef YY_NO_PUSH_STATE
#ifdef YY_USE_PROTOS
static void yy_push_state( int new_state )
#else
static void yy_push_state( new_state )
int new_state;
#endif
	{
	if ( yy_start_stack_ptr >= yy_start_stack_depth )
		{
		yy_size_t new_size;

		yy_start_stack_depth += YY_START_STACK_INCR;
		new_size = yy_start_stack_depth * sizeof( int );

		if ( ! yy_start_stack )
			yy_start_stack = (int *) yy_flex_alloc( new_size );

		else
			yy_start_stack = (int *) yy_flex_realloc(
					(void *) yy_start_stack, new_size );

		if ( ! yy_start_stack )
			YY_FATAL_ERROR(
			"out of memory expanding start-condition stack" );
		}

	yy_start_stack[yy_start_stack_ptr++] = YY_START;

	BEGIN(new_state);
	}
#endif


#ifndef YY_NO_POP_STATE
static void yy_pop_state()
	{
	if ( --yy_start_stack_ptr < 0 )
		YY_FATAL_ERROR( "start-condition stack underflow" );

	BEGIN(yy_start_stack[yy_start_stack_ptr]);
	}
#endif


#ifndef YY_NO_TOP_STATE
static int yy_top_state()
	{
	return yy_start_stack[yy_start_stack_ptr - 1];
	}
#endif

#ifndef YY_EXIT_FAILURE
#define YY_EXIT_FAILURE 2
#endif

#ifdef YY_USE_PROTOS
static void yy_fatal_error( yyconst char msg[] )
#else
static void yy_fatal_error( msg )
char msg[];
#endif
	{
	(void) fprintf( stderr, "%s\n", msg );
	exit( YY_EXIT_FAILURE );
	}



/* Redefine yyless() so it works in section 3 code. */

#undef yyless
#define yyless(n) \
	do \
		{ \
		/* Undo effects of setting up yytext. */ \
		yytext[yyleng] = yy_hold_char; \
		yy_c_buf_p = yytext + n; \
		yy_hold_char = *yy_c_buf_p; \
		*yy_c_buf_p = '\0'; \
		yyleng = n; \
		} \
	while ( 0 )


/* Internal utility routines. */

#ifndef yytext_ptr
#ifdef YY_USE_PROTOS
static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
#else
static void yy_flex_strncpy( s1, s2, n )
char *s1;
yyconst char *s2;
int n;
#endif
	{
	register int i;
	for ( i = 0; i < n; ++i )
		s1[i] = s2[i];
	}
#endif

#ifdef YY_NEED_STRLEN
#ifdef YY_USE_PROTOS
static int yy_flex_strlen( yyconst char *s )
#else
static int yy_flex_strlen( s )
yyconst char *s;
#endif
	{
	register int n;
	for ( n = 0; s[n]; ++n )
		;

	return n;
	}
#endif


#ifdef YY_USE_PROTOS
static void *yy_flex_alloc( yy_size_t size )
#else
static void *yy_flex_alloc( size )
yy_size_t size;
#endif
	{
	return (void *) malloc( size );
	}

#ifdef YY_USE_PROTOS
static void *yy_flex_realloc( void *ptr, yy_size_t size )
#else
static void *yy_flex_realloc( ptr, size )
void *ptr;
yy_size_t size;
#endif
	{
	/* The cast to (char *) in the following accommodates both
	 * implementations that use char* generic pointers, and those
	 * that use void* generic pointers.  It works with the latter
	 * because both ANSI C and C++ allow castless assignment from
	 * any pointer type to void*, and deal with argument conversions
	 * as though doing an assignment.
	 */
	return (void *) realloc( (char *) ptr, size );
	}

#ifdef YY_USE_PROTOS
static void yy_flex_free( void *ptr )
#else
static void yy_flex_free( ptr )
void *ptr;
#endif
	{
	free( ptr );
	}

#if YY_MAIN
int main()
	{
	yylex();
	return 0;
	}
#endif
#line 689 "mlex.l"



void
mlex_init (void)
{
        int ret;

        ret = regcomp (& bound_re,
                       "multipart.*boundary=(\"([^\"]+)\"|([^\"][^; \\-]*);?)",
                       REG_ICASE | REG_EXTENDED);

        if (ret)
                error_critical (1, 0, "internal error");
        re_compiled = 1;
}



void
mlex_free_resources (void)
{
        if (re_compiled)
                regfree (& bound_re);
        re_compiled = 0;
}



int
mlex_scan_file (time_t tm)
{
        int ret;
        YY_BUFFER_STATE buffer = yy_create_buffer (yyin, YY_BUF_SIZE);
  
        collect_custom_headers = 0;
        only_one               = 1;
        after_header_action    = NULL;
  
        clear_mail (tm);
        BEGIN (HEADER);
        yy_switch_to_buffer (buffer);
        ret = mlex_scan ();
        yy_delete_buffer (buffer);
        BEGIN (INITIAL);
        return ret;
}


int
mlex_scan_buffer (char *buf)
{
        int             ret;
        YY_BUFFER_STATE state;
        YY_BUFFER_STATE old_state = YY_CURRENT_BUFFER;

        collect_custom_headers = 0;
        only_one               = 1;
        after_header_action    = NULL;
  
        clear_mail (0);
        BEGIN (HEADER);
        state = yy_scan_string (buf);
        ret   = mlex_scan ();
        yy_delete_buffer (state);
        yy_switch_to_buffer (old_state);
        if (ret == EOF_AT_HEADER || ret == NEXT_MAIL)
                return NEXT_MAIL;
        return BROKEN_MAIL;
}



int
mlex_outmail_scan (void)
{
        int    ret;
        time_t tm              = time (NULL);
        YY_BUFFER_STATE buffer = yy_create_buffer (yyin, YY_BUF_SIZE);

        only_one               = 1;
        collect_custom_headers = 1;
        after_header_action    = write_headers;

        clear_mail (tm);
        BEGIN (HEADER);
        yy_switch_to_buffer (buffer);
        ret = mlex_scan ();
        yy_delete_buffer (buffer);
        BEGIN (INITIAL);

        return ret;
}



int
mlex_mbox_scan_start (void)
{
        YY_BUFFER_STATE buffer = yy_create_buffer (yyin, YY_BUF_SIZE);

        collect_custom_headers = 0;
        only_one               = 0;
        after_header_action    = NULL;

        memset (mail, '\0', sizeof (mail));

        BEGIN (INITIAL);
        yy_switch_to_buffer (buffer);
        return mlex_scan ();
}


/****************************************************************************
 *    STACK OPERATIONS
 ****************************************************************************/

static void
pop (void)
{
        stack[top].mime = NULL;
        
        if (top == 0){
                return;
        }
        top--;
}



static void
push (char *boundary, int len)
{
        if (len >= MAX_BOUNDARY_LEN)
                len = MAX_BOUNDARY_LEN - 1;

        memcpy (stack[top].boundary, boundary, len);
        stack[top].boundary[len] = '\0';
        stack[top].boundary_len  = len;
        
        top++;
        stack[top].mime = NULL;
}



static void
replace_top_mime (mime_t *mime)
{
        stack[top].mime = mime;
}



static mime_t *
parent_mime (void)
{
        if (top <= 0)
                return NULL;

        return stack[top - 1].mime;
}



static mime_t *
top_mime (void)
{
        if (top < 0)
                return NULL;
        
        return stack[top].mime;
}



static mime_t *
top_or_parent_mime (void)
{
        mime_t *result = top_mime ();

        if (result)
                return result;

        if (top <= 0)
                return NULL;

        return stack[top - 1].mime;
}



static char *
top_boundary (void)
{
        if (top <= 0)
                return NULL;

        return stack[top - 1].boundary;
}



static int
top_boundary_len (void)
{
        if (top <= 0)
                return -1;

        return stack[top - 1].boundary_len;
}


/****************************************************************************
 *    IMPLEMENTATION PRIVATE FUNCTIONS
 ****************************************************************************/


/*
  This function unfolds header content and returns a string containing just
  one line of plain text.  It allocates memory for string, so it should be
  freed, after use.
*/
static char *
unfold_content (char *content)
{
        char *result     = xmalloc (strlen (content) + 1);
        char *result_ptr = result;
        char *ptr;

        while (*content && isspace (*content))
                content++;
        
        for (ptr = content; *ptr; ptr++){
                switch (*ptr){

                        case '\r':
                                break;
                        
                        default:
                                *result_ptr = *ptr;
                                result_ptr++;
                                break;
                }
        }
        *result_ptr = '\0';
        result = mime_decode_header (result, result_ptr - result, 1);
        return result;
}




static void
clear_mail (time_t tm)
{
        mail_clear (a_mail);

        a_mail->mime                   = mime_info_create ();
        a_mail->mime->mime->off_header = offset;
        a_mail->place.offset_header    = offset;
        a_mail->date                   = tm;

        top           = 0;
        stack[0].mime = a_mail->mime->mime;
}



static void
write_headers (void)
{
        char      *msg_id      = compose_msg_id ();
        rstring_t *in_reply_to = compose_in_reply_to ();
        char      *date;

        if (a_mail->msg_id)
                xfree (a_mail->msg_id);
        if (a_mail->in_reply_to)
                rstring_delete (a_mail->in_reply_to);

        if (a_mail->date_str)
                date = a_mail->date_str;
        else
                date = compose_date ();
        
        a_mail->msg_id      = msg_id;
        a_mail->date_str    = date;
        a_mail->in_reply_to = in_reply_to;
  
        after_header_action = NULL;
}



/****************************************************************************
 *    INTERFACE CLASS BODIES
 ****************************************************************************/
/****************************************************************************
 *
 *    END MODULE mlex.l
 *
 ****************************************************************************/


syntax highlighted by Code2HTML, v. 0.9.1