# HG changeset patch # User Timo Sirainen # Date 1041686549 -7200 # Node ID e27267f227e653506b61aecac77e1827b6f73498 # Parent 21ffcce83c7029bbaacc961a9b6e096b084dc236 Rfc822 tokenizer cleanups diff -r 21ffcce83c70 -r e27267f227e6 src/lib-imap/imap-bodystructure.c --- a/src/lib-imap/imap-bodystructure.c Fri Jan 03 17:57:12 2003 +0200 +++ b/src/lib-imap/imap-bodystructure.c Sat Jan 04 15:22:29 2003 +0200 @@ -110,11 +110,7 @@ str = t_str_new(256); quoted = FALSE; - while (rfc822_tokenize_next(ctx)) { - token = rfc822_tokenize_get(ctx); - if (token == TOKEN_LAST) - break; - + while ((token = rfc822_tokenize_next(ctx)) != TOKEN_LAST) { if (token == ',') { /* list separator */ if (quoted) { diff -r 21ffcce83c70 -r e27267f227e6 src/lib-mail/message-content-parser.c --- a/src/lib-mail/message-content-parser.c Fri Jan 03 17:57:12 2003 +0200 +++ b/src/lib-mail/message-content-parser.c Sat Jan 04 15:22:29 2003 +0200 @@ -24,7 +24,7 @@ str = t_str_new(256); /* first ';' separates the parameters */ - (void)rfc822_tokenize_get_string(ctx, str, NULL, stop_tokens); + rfc822_tokenize_get_string(ctx, str, NULL, stop_tokens); if (func != NULL) func(str_c(str), str_len(str), context); @@ -33,21 +33,17 @@ if (param_func != NULL && rfc822_tokenize_get(ctx) == ';') { /* parse the parameters */ - while (rfc822_tokenize_next(ctx)) { - token = rfc822_tokenize_get(ctx); - + while ((token = rfc822_tokenize_next(ctx)) != TOKEN_LAST) { /* "=" | */ if (token != TOKEN_ATOM) continue; key = rfc822_tokenize_get_value(ctx, &key_len); - (void)rfc822_tokenize_next(ctx); - if (rfc822_tokenize_get(ctx) != '=') + if (rfc822_tokenize_next(ctx) != '=') continue; - (void)rfc822_tokenize_next(ctx); - token = rfc822_tokenize_get(ctx); + token = rfc822_tokenize_next(ctx); if (token != TOKEN_ATOM && token != TOKEN_QSTRING) continue; diff -r 21ffcce83c70 -r e27267f227e6 src/lib-mail/rfc822-address.c --- a/src/lib-mail/rfc822-address.c Fri Jan 03 17:57:12 2003 +0200 +++ b/src/lib-mail/rfc822-address.c Sat Jan 04 15:22:29 2003 +0200 @@ -82,8 +82,8 @@ } else { len = 0; } - (void)rfc822_tokenize_get_string(ctx, next_phrase, comment, - stop_tokens); + rfc822_tokenize_get_string(ctx, next_phrase, comment, + stop_tokens); if (next_phrase == name && len > 0 && len == str_len(name)) { /* nothing appeneded, remove the space */ @@ -152,18 +152,18 @@ } /* mailbox */ - (void)rfc822_tokenize_get_string(ctx, - mailbox, NULL, stop_tokens_addr_mailbox); + rfc822_tokenize_get_string(ctx, mailbox, NULL, + stop_tokens_addr_mailbox); if (rfc822_tokenize_get(ctx) == '@' && str_len(mailbox) == 0) { /* route is given */ - (void)rfc822_tokenize_get_string(ctx, + rfc822_tokenize_get_string(ctx, route, NULL, stop_tokens_addr_route); if (rfc822_tokenize_get(ctx) == ':') { /* mailbox comes next */ - (void)rfc822_tokenize_get_string(ctx, + rfc822_tokenize_get_string(ctx, mailbox, NULL, stop_tokens_addr_mailbox); } @@ -171,7 +171,7 @@ if (rfc822_tokenize_get(ctx) == '@') { /* domain */ - (void)rfc822_tokenize_get_string(ctx, + rfc822_tokenize_get_string(ctx, domain, NULL, stop_tokens_addr_domain); } diff -r 21ffcce83c70 -r e27267f227e6 src/lib-mail/rfc822-date.c --- a/src/lib-mail/rfc822-date.c Fri Jan 03 17:57:12 2003 +0200 +++ b/src/lib-mail/rfc822-date.c Sat Jan 04 15:22:29 2003 +0200 @@ -91,9 +91,7 @@ { Rfc822Token token; - (void)rfc822_tokenize_next(ctx); - - token = rfc822_tokenize_get(ctx); + token = rfc822_tokenize_next(ctx); if (token == 'A') *value = rfc822_tokenize_get_value(ctx, value_len); return token; diff -r 21ffcce83c70 -r e27267f227e6 src/lib-mail/rfc822-tokenize.c --- a/src/lib-mail/rfc822-tokenize.c Fri Jan 03 17:57:12 2003 +0200 +++ b/src/lib-mail/rfc822-tokenize.c Sat Jan 04 15:22:29 2003 +0200 @@ -25,15 +25,19 @@ #define PARSE_ERROR() \ STMT_START { \ if (ctx->error_func != NULL && \ - !ctx->error_func(data, i, '\0', ctx->error_context)) \ - return FALSE; \ + !ctx->error_func(data, i, '\0', ctx->error_context)) { \ + ctx->token = TOKEN_LAST; \ + return TOKEN_LAST; \ + } \ } STMT_END #define PARSE_ERROR_MISSING(c) \ STMT_START { \ if (ctx->error_func != NULL && \ - !ctx->error_func(data, i, c, ctx->error_context)) \ - return FALSE; \ + !ctx->error_func(data, i, c, ctx->error_context)) { \ + ctx->token = TOKEN_LAST; \ + return TOKEN_LAST; \ + } \ } STMT_END @@ -72,14 +76,14 @@ ctx->dot_token = set; } -int rfc822_tokenize_next(Rfc822TokenizeContext *ctx) +Rfc822Token rfc822_tokenize_next(Rfc822TokenizeContext *ctx) { int token, level, last_atom; const char *data; size_t i, size; if (ctx->token == TOKEN_LAST) - return FALSE; + return TOKEN_LAST; data = ctx->data; size = ctx->size; @@ -259,11 +263,11 @@ if (ctx->token == TOKEN_LAST && ctx->in_bracket && ctx->error_func != NULL) { - if (!ctx->error_func(data, i, '>', ctx->error_context)) - return FALSE; + if (ctx->error_func(data, i, '>', ctx->error_context)) + ctx->token = TOKEN_LAST; } - return TRUE; + return ctx->token; } Rfc822Token rfc822_tokenize_get(const Rfc822TokenizeContext *ctx) @@ -280,9 +284,9 @@ return ctx->data + ctx->token_pos; } -int rfc822_tokenize_get_string(Rfc822TokenizeContext *ctx, - String *str, String *comments, - const Rfc822Token *stop_tokens) +void rfc822_tokenize_get_string(Rfc822TokenizeContext *ctx, + String *str, String *comments, + const Rfc822Token *stop_tokens) { Rfc822Token token; const char *value; @@ -290,14 +294,10 @@ int i, token_str, last_str; last_str = FALSE; - while (rfc822_tokenize_next(ctx)) { - token = rfc822_tokenize_get(ctx); - if (token == TOKEN_LAST) - return TRUE; - + while ((token = rfc822_tokenize_next(ctx)) != TOKEN_LAST) { for (i = 0; stop_tokens[i] != TOKEN_LAST; i++) if (token == stop_tokens[i]) - return TRUE; + return; if (token == TOKEN_COMMENT) { /* handle comment specially */ @@ -341,6 +341,4 @@ last_str = token_str; } - - return FALSE; } diff -r 21ffcce83c70 -r e27267f227e6 src/lib-mail/rfc822-tokenize.h --- a/src/lib-mail/rfc822-tokenize.h Fri Jan 03 17:57:12 2003 +0200 +++ b/src/lib-mail/rfc822-tokenize.h Sat Jan 04 15:22:29 2003 +0200 @@ -45,13 +45,10 @@ /* Specify whether '.' should be treated as a separate token (default yes). */ void rfc822_tokenize_dot_token(Rfc822TokenizeContext *ctx, int set); -/* Parse the next token. Returns FALSE if parsing error occured and error - function wanted to abort. It's not required to check the return value, - rfc822_tokenize_get() will return TOKEN_LAST after errors. Returns FALSE - also when last token was already read. */ -int rfc822_tokenize_next(Rfc822TokenizeContext *ctx); +/* Parse the next token and return it. */ +Rfc822Token rfc822_tokenize_next(Rfc822TokenizeContext *ctx); -/* Return the next token. */ +/* Return the current token. */ Rfc822Token rfc822_tokenize_get(const Rfc822TokenizeContext *ctx); /* - not including enclosing "", () or [] @@ -60,11 +57,10 @@ const char *rfc822_tokenize_get_value(const Rfc822TokenizeContext *ctx, size_t *len); -/* Return tokens as a string, all quoted strings will be unquoted. - Reads until stop_token is found. Returns FALSE if rfc822_tokenize_next() - failed. */ -int rfc822_tokenize_get_string(Rfc822TokenizeContext *ctx, - String *str, String *comments, - const Rfc822Token *stop_tokens); +/* Read tokens as a string, all quoted strings will be unquoted. + Reads until stop_token is found. */ +void rfc822_tokenize_get_string(Rfc822TokenizeContext *ctx, + String *str, String *comments, + const Rfc822Token *stop_tokens); #endif