Mercurial > dovecot > original-hg > dovecot-1.2
view src/lib-mail/message-content-parser.c @ 896:21ffcce83c70 HEAD
Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
take memory, maybe also a bit faster. This caused pretty large changes all
around.
Also moved all string (un)escaping code to lib/strescape.c.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 03 Jan 2003 17:57:12 +0200 |
parents | de8683b5bb16 |
children | e27267f227e6 |
line wrap: on
line source
/* Copyright (C) 2002 Timo Sirainen */ #include "lib.h" #include "str.h" #include "rfc822-tokenize.h" #include "message-content-parser.h" void message_content_parse_header(const char *data, size_t size, ParseContentFunc func, ParseContentParamFunc param_func, void *context) { static const Rfc822Token stop_tokens[] = { ';', TOKEN_LAST }; Rfc822TokenizeContext *ctx; Rfc822Token token; String *str; const char *key, *value; size_t key_len, value_len; ctx = rfc822_tokenize_init(data, size, NULL, NULL); rfc822_tokenize_dot_token(ctx, FALSE); t_push(); str = t_str_new(256); /* first ';' separates the parameters */ (void)rfc822_tokenize_get_string(ctx, str, NULL, stop_tokens); if (func != NULL) func(str_c(str), str_len(str), context); t_pop(); if (param_func != NULL && rfc822_tokenize_get(ctx) == ';') { /* parse the parameters */ while (rfc822_tokenize_next(ctx)) { token = rfc822_tokenize_get(ctx); /* <token> "=" <token> | <quoted-string> */ if (token != TOKEN_ATOM) continue; key = rfc822_tokenize_get_value(ctx, &key_len); (void)rfc822_tokenize_next(ctx); if (rfc822_tokenize_get(ctx) != '=') continue; (void)rfc822_tokenize_next(ctx); token = rfc822_tokenize_get(ctx); if (token != TOKEN_ATOM && token != TOKEN_QSTRING) continue; value = rfc822_tokenize_get_value(ctx, &value_len); param_func(key, key_len, value, value_len, token == TOKEN_QSTRING, context); } } rfc822_tokenize_deinit(ctx); }