[dovecot-cvs] dovecot/src/lib-mail rfc822-parser.c, 1.2, 1.3 rfc822-parser.h, 1.1, 1.2

cras at dovecot.org cras at dovecot.org
Sun Jun 5 22:32:35 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib-mail
In directory talvi:/tmp/cvs-serv32728

Modified Files:
	rfc822-parser.c rfc822-parser.h 
Log Message:
Added rfc822_parse_mime_token() to rfc822-parser API.



Index: rfc822-parser.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/rfc822-parser.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rfc822-parser.c	13 Jan 2005 17:52:17 -0000	1.2
+++ rfc822-parser.c	5 Jun 2005 19:32:33 -0000	1.3
@@ -16,14 +16,25 @@
                         "`" / "{" /
                         "|" / "}" /
                         "~"
+
+  MIME:
+
+  token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
+              or tspecials>
+  tspecials :=  "(" / ")" / "<" / ">" / "@" /
+                "," / ";" / ":" / "\" / <">
+                "/" / "[" / "]" / "?" / "="
+
+  So token is same as dot-atom, except stops also at '/', '?' and '='.
 */
 
-/* atext chars are marked with 1, alpha and digits with 2 */
+/* atext chars are marked with 1, alpha and digits with 2,
+   atext-but-mime-tspecials with 4 */
 static unsigned char atext_chars[256] = {
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0-15 */
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-31 */
-	0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, /* 32-47 */
-	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 0, 1, /* 48-63 */
+	0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 4, /* 32-47 */
+	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 4, 0, 4, /* 48-63 */
 	0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 64-79 */
 	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 1, /* 80-95 */
 	1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 96-111 */
@@ -40,6 +51,8 @@
 };
 #define IS_ATEXT(c) \
 	(atext_chars[(int)(unsigned char)(c)] != 0)
+#define IS_ATEXT_NON_TSPECIAL(c) \
+	((atext_chars[(int)(unsigned char)(c)] & 3) != 0)
 
 void rfc822_parser_init(struct rfc822_parser_context *ctx,
 			const unsigned char *data, size_t size,
@@ -108,7 +121,7 @@
 			break;
 
 		if (rfc822_skip_comment(ctx) < 0)
-			break;
+			return -1;
 	}
 	return ctx->data != ctx->end;
 }
@@ -172,6 +185,22 @@
 	return 0;
 }
 
+int rfc822_parse_mime_token(struct rfc822_parser_context *ctx, string_t *str)
+{
+	const unsigned char *start;
+
+	for (start = ctx->data; ctx->data != ctx->end; ctx->data++) {
+		if (IS_ATEXT_NON_TSPECIAL(*ctx->data) || *ctx->data == '.')
+			continue;
+
+		str_append_n(str, start, ctx->data - start);
+		return rfc822_skip_lwsp(ctx);
+	}
+
+	str_append_n(str, start, ctx->data - start);
+	return 0;
+}
+
 int rfc822_parse_quoted_string(struct rfc822_parser_context *ctx, string_t *str)
 {
 	const unsigned char *start;

Index: rfc822-parser.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/rfc822-parser.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rfc822-parser.h	6 Jan 2005 18:14:28 -0000	1.1
+++ rfc822-parser.h	5 Jun 2005 19:32:33 -0000	1.2
@@ -10,13 +10,23 @@
 			const unsigned char *data, size_t size,
 			string_t *last_comment);
 
+/* Parse comment. Assumes parser's data points to '(' */
 int rfc822_skip_comment(struct rfc822_parser_context *ctx);
+/* Skip LWSP if there is any */
 int rfc822_skip_lwsp(struct rfc822_parser_context *ctx);
+/* Stop at next non-atext char */
 int rfc822_parse_atom(struct rfc822_parser_context *ctx, string_t *str);
+/* Like parse_atom() but don't stop at '.' */
 int rfc822_parse_dot_atom(struct rfc822_parser_context *ctx, string_t *str);
+/* Like parse_dot_atom() but stops for '/', '?' and '='.
+   Also it doesn't allow LWSP around '.' chars. */
+int rfc822_parse_mime_token(struct rfc822_parser_context *ctx, string_t *str);
+/* "quoted string" */
 int rfc822_parse_quoted_string(struct rfc822_parser_context *ctx,
 			       string_t *str);
+/* atom or quoted-string */
 int rfc822_parse_phrase(struct rfc822_parser_context *ctx, string_t *str);
+/* dot-atom / domain-literal */
 int rfc822_parse_domain(struct rfc822_parser_context *ctx, string_t *str);
 
 #endif



More information about the dovecot-cvs mailing list