#line 1 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"

#line 53 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"


#include "smtp_parsers.h"
#include "mime_headers.h"


#line 8 "/build/rspamd/src/build/src/rfc2047.rl.c"
static const int rfc2047_parser_start = 1;
static const int rfc2047_parser_first_final = 17;
static const int rfc2047_parser_error = 0;

static const int rfc2047_parser_en_main = 1;


#line 58 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"


gboolean
rspamd_rfc2047_parser (const char *in, gsize len, int *pencoding,
const char **charset, gsize *charset_len,
const char **encoded, gsize *encoded_len)
{
	const char *p = in, *pe = in + len,
	*encoded_start = NULL, *encoded_end = NULL,
	*charset_start = NULL, *charset_end = NULL,
	*eof = in + len;
	int encoding = RSPAMD_RFC2047_QP, cs = 0;
	

#line 28 "/build/rspamd/src/build/src/rfc2047.rl.c"
	{
		cs = (int)rfc2047_parser_start;
	}
	
#line 71 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"


#line 33 "/build/rspamd/src/build/src/rfc2047.rl.c"
{
		switch ( cs ) {
			case 1:
			goto st_case_1;
			case 0:
			goto st_case_0;
			case 2:
			goto st_case_2;
			case 3:
			goto st_case_3;
			case 4:
			goto st_case_4;
			case 5:
			goto st_case_5;
			case 6:
			goto st_case_6;
			case 7:
			goto st_case_7;
			case 8:
			goto st_case_8;
			case 9:
			goto st_case_9;
			case 17:
			goto st_case_17;
			case 18:
			goto st_case_18;
			case 19:
			goto st_case_19;
			case 20:
			goto st_case_20;
			case 10:
			goto st_case_10;
			case 11:
			goto st_case_11;
			case 12:
			goto st_case_12;
			case 13:
			goto st_case_13;
			case 14:
			goto st_case_14;
			case 15:
			goto st_case_15;
			case 16:
			goto st_case_16;
		}
		_st1:
		if ( p == eof )
			goto _out1;
		p+= 1;
		st_case_1:
		if ( p == pe && p != eof )
			goto _out1;
		if ( p == eof ) {
			goto _st1;}
		else {
			if ( ( (*( p))) == 61 ) {
				goto _st2;
			}
			goto _st0;
		}
		_st0:
		if ( p == eof )
			goto _out0;
		st_case_0:
		goto _out0;
		_st2:
		if ( p == eof )
			goto _out2;
		p+= 1;
		st_case_2:
		if ( p == pe && p != eof )
			goto _out2;
		if ( p == eof ) {
			goto _st2;}
		else {
			if ( ( (*( p))) == 63 ) {
				goto _st3;
			}
			goto _st0;
		}
		_st3:
		if ( p == eof )
			goto _out3;
		p+= 1;
		st_case_3:
		if ( p == pe && p != eof )
			goto _out3;
		if ( p == eof ) {
			goto _st3;}
		else {
			switch( ( (*( p))) ) {
				case 33: {
					goto _ctr4;
				}
				case 43: {
					goto _ctr4;
				}
				case 45: {
					goto _ctr4;
				}
				case 92: {
					goto _ctr4;
				}
			}
			if ( ( (*( p))) < 48 ) {
				if ( 35 <= ( (*( p))) && ( (*( p))) <= 39 ) {
					goto _ctr4;
				}
			} else if ( ( (*( p))) > 57 ) {
				if ( ( (*( p))) > 90 ) {
					if ( 94 <= ( (*( p))) && ( (*( p))) <= 126 ) {
						goto _ctr4;
					}
				} else if ( ( (*( p))) >= 65 ) {
					goto _ctr4;
				}
			} else {
				goto _ctr4;
			}
			goto _st0;
		}
		_ctr4:
			{
#line 5 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			charset_start = p;
		}
		
#line 161 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st4;
		_st4:
		if ( p == eof )
			goto _out4;
		p+= 1;
		st_case_4:
		if ( p == pe && p != eof )
			goto _out4;
		if ( p == eof ) {
			goto _st4;}
		else {
			switch( ( (*( p))) ) {
				case 33: {
					goto _st4;
				}
				case 42: {
					goto _ctr6;
				}
				case 43: {
					goto _st4;
				}
				case 45: {
					goto _st4;
				}
				case 63: {
					goto _ctr7;
				}
				case 92: {
					goto _st4;
				}
			}
			if ( ( (*( p))) < 48 ) {
				if ( 35 <= ( (*( p))) && ( (*( p))) <= 39 ) {
					goto _st4;
				}
			} else if ( ( (*( p))) > 57 ) {
				if ( ( (*( p))) > 90 ) {
					if ( 94 <= ( (*( p))) && ( (*( p))) <= 126 ) {
						goto _st4;
					}
				} else if ( ( (*( p))) >= 65 ) {
					goto _st4;
				}
			} else {
				goto _st4;
			}
			goto _st0;
		}
		_ctr6:
			{
#line 9 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			if (charset_start && p > charset_start) {
				charset_end = p;
			}
		}
		
#line 219 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st5;
		_st5:
		if ( p == eof )
			goto _out5;
		p+= 1;
		st_case_5:
		if ( p == pe && p != eof )
			goto _out5;
		if ( p == eof ) {
			goto _st5;}
		else {
			if ( ( (*( p))) > 90 ) {
				if ( 97 <= ( (*( p))) && ( (*( p))) <= 122 ) {
					goto _st6;
				}
			} else if ( ( (*( p))) >= 65 ) {
				goto _st6;
			}
			goto _st0;
		}
		_st6:
		if ( p == eof )
			goto _out6;
		p+= 1;
		st_case_6:
		if ( p == pe && p != eof )
			goto _out6;
		if ( p == eof ) {
			goto _st6;}
		else {
			switch( ( (*( p))) ) {
				case 45: {
					goto _st5;
				}
				case 63: {
					goto _st7;
				}
			}
			if ( ( (*( p))) > 90 ) {
				if ( 97 <= ( (*( p))) && ( (*( p))) <= 122 ) {
					goto _st10;
				}
			} else if ( ( (*( p))) >= 65 ) {
				goto _st10;
			}
			goto _st0;
		}
		_ctr7:
			{
#line 9 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			if (charset_start && p > charset_start) {
				charset_end = p;
			}
		}
		
#line 276 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st7;
		_st7:
		if ( p == eof )
			goto _out7;
		p+= 1;
		st_case_7:
		if ( p == pe && p != eof )
			goto _out7;
		if ( p == eof ) {
			goto _st7;}
		else {
			switch( ( (*( p))) ) {
				case 66: {
					goto _st8;
				}
				case 81: {
					goto _st8;
				}
				case 98: {
					goto _st8;
				}
				case 113: {
					goto _st8;
				}
			}
			goto _st0;
		}
		_st8:
		if ( p == eof )
			goto _out8;
		p+= 1;
		st_case_8:
		if ( p == pe && p != eof )
			goto _out8;
		if ( p == eof ) {
			goto _st8;}
		else {
			if ( ( (*( p))) == 63 ) {
				goto _ctr13;
			}
			goto _st0;
		}
		_ctr13:
			{
#line 15 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			if (p > in) {
				switch (*(p - 1)) {
					case 'B':
					case 'b':
					encoding = RSPAMD_RFC2047_BASE64;
					break;
					default:
					encoding = RSPAMD_RFC2047_QP;
					break;
				}
			}
		}
		
#line 336 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st9;
		_st9:
		if ( p == eof )
			goto _out9;
		p+= 1;
		st_case_9:
		if ( p == pe && p != eof )
			goto _out9;
		if ( p == eof ) {
			goto _st9;}
		else {
			if ( ( (*( p))) == 63 ) {
				goto _ctr16;
			}
			if ( 32 <= ( (*( p))) && ( (*( p))) <= 126 ) {
				goto _ctr15;
			}
			goto _st0;
		}
		_ctr15:
			{
#line 29 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			encoded_start = p;
		}
		
#line 363 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st17;
		_ctr23:
			{
#line 33 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			if (encoded_start && p > encoded_start) {
				encoded_end = p;
			}
		}
		
#line 374 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st17;
		_st17:
		if ( p == eof )
			goto _out17;
		p+= 1;
		st_case_17:
		if ( p == pe && p != eof )
			goto _out17;
		if ( p == eof ) {
			goto _ctr23;}
		else {
			if ( ( (*( p))) == 63 ) {
				goto _ctr25;
			}
			if ( 32 <= ( (*( p))) && ( (*( p))) <= 126 ) {
				goto _st17;
			}
			goto _st0;
		}
		_ctr25:
			{
#line 33 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			if (encoded_start && p > encoded_start) {
				encoded_end = p;
			}
		}
		
#line 403 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st18;
		_st18:
		if ( p == eof )
			goto _out18;
		p+= 1;
		st_case_18:
		if ( p == pe && p != eof )
			goto _out18;
		if ( p == eof ) {
			goto _ctr25;}
		else {
			switch( ( (*( p))) ) {
				case 61: {
					goto _st19;
				}
				case 63: {
					goto _ctr25;
				}
			}
			if ( 32 <= ( (*( p))) && ( (*( p))) <= 126 ) {
				goto _st17;
			}
			goto _st0;
		}
		_st19:
		if ( p == eof )
			goto _out19;
		p+= 1;
		st_case_19:
		if ( p == pe && p != eof )
			goto _out19;
		if ( p == eof ) {
			goto _st19;}
		else {
			goto _st0;
		}
		_ctr16:
			{
#line 29 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			encoded_start = p;
		}
		
#line 447 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st20;
		_ctr27:
			{
#line 33 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"
			
			if (encoded_start && p > encoded_start) {
				encoded_end = p;
			}
		}
		
#line 458 "/build/rspamd/src/build/src/rfc2047.rl.c"

		goto _st20;
		_st20:
		if ( p == eof )
			goto _out20;
		p+= 1;
		st_case_20:
		if ( p == pe && p != eof )
			goto _out20;
		if ( p == eof ) {
			goto _ctr27;}
		else {
			if ( ( (*( p))) == 63 ) {
				goto _ctr25;
			}
			if ( ( (*( p))) > 60 ) {
				if ( 62 <= ( (*( p))) && ( (*( p))) <= 126 ) {
					goto _st17;
				}
			} else if ( ( (*( p))) >= 32 ) {
				goto _st17;
			}
			goto _st0;
		}
		_st10:
		if ( p == eof )
			goto _out10;
		p+= 1;
		st_case_10:
		if ( p == pe && p != eof )
			goto _out10;
		if ( p == eof ) {
			goto _st10;}
		else {
			switch( ( (*( p))) ) {
				case 45: {
					goto _st5;
				}
				case 63: {
					goto _st7;
				}
			}
			if ( ( (*( p))) > 90 ) {
				if ( 97 <= ( (*( p))) && ( (*( p))) <= 122 ) {
					goto _st11;
				}
			} else if ( ( (*( p))) >= 65 ) {
				goto _st11;
			}
			goto _st0;
		}
		_st11:
		if ( p == eof )
			goto _out11;
		p+= 1;
		st_case_11:
		if ( p == pe && p != eof )
			goto _out11;
		if ( p == eof ) {
			goto _st11;}
		else {
			switch( ( (*( p))) ) {
				case 45: {
					goto _st5;
				}
				case 63: {
					goto _st7;
				}
			}
			if ( ( (*( p))) > 90 ) {
				if ( 97 <= ( (*( p))) && ( (*( p))) <= 122 ) {
					goto _st12;
				}
			} else if ( ( (*( p))) >= 65 ) {
				goto _st12;
			}
			goto _st0;
		}
		_st12:
		if ( p == eof )
			goto _out12;
		p+= 1;
		st_case_12:
		if ( p == pe && p != eof )
			goto _out12;
		if ( p == eof ) {
			goto _st12;}
		else {
			switch( ( (*( p))) ) {
				case 45: {
					goto _st5;
				}
				case 63: {
					goto _st7;
				}
			}
			if ( ( (*( p))) > 90 ) {
				if ( 97 <= ( (*( p))) && ( (*( p))) <= 122 ) {
					goto _st13;
				}
			} else if ( ( (*( p))) >= 65 ) {
				goto _st13;
			}
			goto _st0;
		}
		_st13:
		if ( p == eof )
			goto _out13;
		p+= 1;
		st_case_13:
		if ( p == pe && p != eof )
			goto _out13;
		if ( p == eof ) {
			goto _st13;}
		else {
			switch( ( (*( p))) ) {
				case 45: {
					goto _st5;
				}
				case 63: {
					goto _st7;
				}
			}
			if ( ( (*( p))) > 90 ) {
				if ( 97 <= ( (*( p))) && ( (*( p))) <= 122 ) {
					goto _st14;
				}
			} else if ( ( (*( p))) >= 65 ) {
				goto _st14;
			}
			goto _st0;
		}
		_st14:
		if ( p == eof )
			goto _out14;
		p+= 1;
		st_case_14:
		if ( p == pe && p != eof )
			goto _out14;
		if ( p == eof ) {
			goto _st14;}
		else {
			switch( ( (*( p))) ) {
				case 45: {
					goto _st5;
				}
				case 63: {
					goto _st7;
				}
			}
			if ( ( (*( p))) > 90 ) {
				if ( 97 <= ( (*( p))) && ( (*( p))) <= 122 ) {
					goto _st15;
				}
			} else if ( ( (*( p))) >= 65 ) {
				goto _st15;
			}
			goto _st0;
		}
		_st15:
		if ( p == eof )
			goto _out15;
		p+= 1;
		st_case_15:
		if ( p == pe && p != eof )
			goto _out15;
		if ( p == eof ) {
			goto _st15;}
		else {
			switch( ( (*( p))) ) {
				case 45: {
					goto _st5;
				}
				case 63: {
					goto _st7;
				}
			}
			if ( ( (*( p))) > 90 ) {
				if ( 97 <= ( (*( p))) && ( (*( p))) <= 122 ) {
					goto _st16;
				}
			} else if ( ( (*( p))) >= 65 ) {
				goto _st16;
			}
			goto _st0;
		}
		_st16:
		if ( p == eof )
			goto _out16;
		p+= 1;
		st_case_16:
		if ( p == pe && p != eof )
			goto _out16;
		if ( p == eof ) {
			goto _st16;}
		else {
			switch( ( (*( p))) ) {
				case 45: {
					goto _st5;
				}
				case 63: {
					goto _st7;
				}
			}
			goto _st0;
		}
		_out1: cs = 1; goto _out; 
		_out0: cs = 0; goto _out; 
		_out2: cs = 2; goto _out; 
		_out3: cs = 3; goto _out; 
		_out4: cs = 4; goto _out; 
		_out5: cs = 5; goto _out; 
		_out6: cs = 6; goto _out; 
		_out7: cs = 7; goto _out; 
		_out8: cs = 8; goto _out; 
		_out9: cs = 9; goto _out; 
		_out17: cs = 17; goto _out; 
		_out18: cs = 18; goto _out; 
		_out19: cs = 19; goto _out; 
		_out20: cs = 20; goto _out; 
		_out10: cs = 10; goto _out; 
		_out11: cs = 11; goto _out; 
		_out12: cs = 12; goto _out; 
		_out13: cs = 13; goto _out; 
		_out14: cs = 14; goto _out; 
		_out15: cs = 15; goto _out; 
		_out16: cs = 16; goto _out; 
		_out: {}
	}
	
#line 72 "/build/rspamd/src/rspamd/src/ragel/rfc2047_parser.rl"

	
	if (encoded_end) {
		*pencoding = encoding;
		*charset = charset_start;
		*charset_len = charset_end - charset_start;
		*encoded = encoded_start;
		*encoded_len = encoded_end - encoded_start;
		
		return TRUE;
	}
	
	return FALSE;
}
