dovecot-2.2: imap parser: Added support for parsing literal8 (fo...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 20 02:45:39 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/68a8b650578e
changeset: 14607:68a8b650578e
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 20 02:44:35 2012 +0300
description:
imap parser: Added support for parsing literal8 (for BINARY extension)

diffstat:

 src/lib-imap/imap-arg.h    |   1 +
 src/lib-imap/imap-parser.c |  25 +++++++++++++++++++++++++
 src/lib-imap/imap-parser.h |   4 +++-
 3 files changed, 29 insertions(+), 1 deletions(-)

diffs (99 lines):

diff -r 7b1378fe8820 -r 68a8b650578e src/lib-imap/imap-arg.h
--- a/src/lib-imap/imap-arg.h	Wed Jun 20 02:23:42 2012 +0300
+++ b/src/lib-imap/imap-arg.h	Wed Jun 20 02:44:35 2012 +0300
@@ -44,6 +44,7 @@
 		uoff_t literal_size;
 		ARRAY_TYPE(imap_arg_list) list;
 	} _data;
+	unsigned int literal8:1; /* BINARY literal8 used */
 };
 
 /* RFC 3501's astring type */
diff -r 7b1378fe8820 -r 68a8b650578e src/lib-imap/imap-parser.c
--- a/src/lib-imap/imap-parser.c	Wed Jun 20 02:23:42 2012 +0300
+++ b/src/lib-imap/imap-parser.c	Wed Jun 20 02:44:35 2012 +0300
@@ -16,6 +16,7 @@
 	ARG_PARSE_ATOM,
 	ARG_PARSE_STRING,
 	ARG_PARSE_LITERAL,
+	ARG_PARSE_LITERAL8,
 	ARG_PARSE_LITERAL_DATA,
 	ARG_PARSE_LITERAL_DATA_FORCED
 };
@@ -45,6 +46,7 @@
 
 	unsigned int literal_skip_crlf:1;
 	unsigned int literal_nonsync:1;
+	unsigned int literal8:1;
 	unsigned int literal_size_return:1;
 	unsigned int eol:1;
 	unsigned int fatal_error:1;
@@ -248,6 +250,7 @@
 				IMAP_ARG_LITERAL_SIZE_NONSYNC :
 				IMAP_ARG_LITERAL_SIZE;
 			arg->_data.literal_size = parser->literal_size;
+			arg->literal8 = parser->literal8;
 			break;
 		}
 		/* fall through */
@@ -257,6 +260,7 @@
 		else
 			arg->type = IMAP_ARG_STRING;
 		arg->_data.str = imap_parser_strdup(parser, data, size);
+		arg->literal8 = parser->literal8;
 		arg->str_len = size;
 		break;
 	default:
@@ -514,10 +518,21 @@
 			parser->cur_type = ARG_PARSE_STRING;
 			parser->str_first_escape = -1;
 			break;
+		case '~':
+			if ((parser->flags & IMAP_PARSE_FLAG_LITERAL8) != 0) {
+				parser->error = "literal8 not allowed here";
+				return FALSE;
+			}
+			parser->cur_type = ARG_PARSE_LITERAL8;
+			parser->literal_size = 0;
+			parser->literal_nonsync = FALSE;
+			parser->literal8 = TRUE;
+			break;
 		case '{':
 			parser->cur_type = ARG_PARSE_LITERAL;
 			parser->literal_size = 0;
 			parser->literal_nonsync = FALSE;
+			parser->literal8 = FALSE;
 			break;
 		case '(':
 			imap_parser_open_list(parser);
@@ -553,6 +568,16 @@
 		if (!imap_parser_read_string(parser, data, data_size))
 			return FALSE;
 		break;
+	case ARG_PARSE_LITERAL8:
+		if (parser->cur_pos == data_size)
+			return FALSE;
+		if (data[parser->cur_pos] != '{') {
+			parser->error = "Expected '{'";
+			return FALSE;
+		}
+		parser->cur_type = ARG_PARSE_LITERAL8;
+		parser->cur_pos++;
+		/* fall through */
 	case ARG_PARSE_LITERAL:
 		if (!imap_parser_read_literal(parser, data, data_size))
 			return FALSE;
diff -r 7b1378fe8820 -r 68a8b650578e src/lib-imap/imap-parser.h
--- a/src/lib-imap/imap-parser.h	Wed Jun 20 02:23:42 2012 +0300
+++ b/src/lib-imap/imap-parser.h	Wed Jun 20 02:44:35 2012 +0300
@@ -18,7 +18,9 @@
 	/* Allow strings to contain CRLFs */
 	IMAP_PARSE_FLAG_MULTILINE_STR	= 0x10,
 	/* Parse in list context; ')' parses as EOL */
-	IMAP_PARSE_FLAG_INSIDE_LIST	= 0x20
+	IMAP_PARSE_FLAG_INSIDE_LIST	= 0x20,
+	/* Parse literal8 and set it as flag to imap_arg. */
+	IMAP_PARSE_FLAG_LITERAL8	= 0x40
 };
 
 struct imap_parser;


More information about the dovecot-cvs mailing list