From: Timo Sirainen Date: Fri, 28 Aug 2009 21:27:08 +0000 (-0400) Subject: imap_quote*() now have fix_text parameter. If it's not set, input isn't modified... X-Git-Tag: 2.0.alpha1~225 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d5407d7d00ed9b602c2bfd168a364382e5211d7;p=thirdparty%2Fdovecot%2Fcore.git imap_quote*() now have fix_text parameter. If it's not set, input isn't modified at all. --HG-- branch : HEAD --- diff --git a/src/lib-imap/imap-bodystructure.c b/src/lib-imap/imap-bodystructure.c index 41475d1f17..1076cecac2 100644 --- a/src/lib-imap/imap-bodystructure.c +++ b/src/lib-imap/imap-bodystructure.c @@ -56,12 +56,11 @@ static void parse_content_type(struct message_part_body_data *data, if (value[i] == '/') { data->content_subtype = imap_quote(data->pool, str_data(str) + i + 1, - str_len(str) - (i + 1)); + str_len(str) - (i + 1), TRUE); break; } } - data->content_type = - imap_quote(data->pool, str_data(str), i); + data->content_type = imap_quote(data->pool, str_data(str), i, TRUE); /* parse parameters and save them */ str_truncate(str, 0); @@ -100,7 +99,8 @@ static void parse_content_transfer_encoding(struct message_part_body_data *data, str = t_str_new(256); if (rfc822_parse_mime_token(&parser, str) >= 0) { data->content_transfer_encoding = - imap_quote(data->pool, str_data(str), str_len(str)); + imap_quote(data->pool, str_data(str), + str_len(str), TRUE); } } @@ -118,7 +118,7 @@ static void parse_content_disposition(struct message_part_body_data *data, if (rfc822_parse_mime_token(&parser, str) < 0) return; data->content_disposition = - imap_quote(data->pool, str_data(str), str_len(str)); + imap_quote(data->pool, str_data(str), str_len(str), TRUE); /* parse parameters and save them */ str_truncate(str, 0); @@ -186,14 +186,18 @@ static void parse_content_header(struct message_part_body_data *d, switch (*name) { case 'i': case 'I': - if (strcasecmp(name, "ID") == 0 && d->content_id == NULL) - d->content_id = imap_quote(pool, value, value_len); + if (strcasecmp(name, "ID") == 0 && d->content_id == NULL) { + d->content_id = + imap_quote(pool, value, value_len, TRUE); + } break; case 'm': case 'M': - if (strcasecmp(name, "MD5") == 0 && d->content_md5 == NULL) - d->content_md5 = imap_quote(pool, value, value_len); + if (strcasecmp(name, "MD5") == 0 && d->content_md5 == NULL) { + d->content_md5 = + imap_quote(pool, value, value_len, TRUE); + } break; case 't': @@ -213,7 +217,7 @@ static void parse_content_header(struct message_part_body_data *d, else if (strcasecmp(name, "Location") == 0 && d->content_location == NULL) { d->content_location = - imap_quote(pool, value, value_len); + imap_quote(pool, value, value_len, TRUE); } break; @@ -222,7 +226,7 @@ static void parse_content_header(struct message_part_body_data *d, if (strcasecmp(name, "Description") == 0 && d->content_description == NULL) { d->content_description = - imap_quote(pool, value, value_len); + imap_quote(pool, value, value_len, TRUE); } else if (strcasecmp(name, "Disposition") == 0 && d->content_disposition_params == NULL) { parse_content_disposition(d, hdr); diff --git a/src/lib-imap/imap-envelope.c b/src/lib-imap/imap-envelope.c index 81ae7d996f..bec1ffd29c 100644 --- a/src/lib-imap/imap-envelope.c +++ b/src/lib-imap/imap-envelope.c @@ -149,8 +149,10 @@ void imap_envelope_parse_header(pool_t pool, (unsigned int)-1, TRUE); } - if (str_p != NULL) - *str_p = imap_quote(pool, hdr->full_value, hdr->full_value_len); + if (str_p != NULL) { + *str_p = imap_quote(pool, hdr->full_value, + hdr->full_value_len, TRUE); + } } static void imap_write_address(string_t *str, struct message_address *addr) diff --git a/src/lib-imap/imap-quote.c b/src/lib-imap/imap-quote.c index 3fe9451037..592b4c1a48 100644 --- a/src/lib-imap/imap-quote.c +++ b/src/lib-imap/imap-quote.c @@ -5,7 +5,7 @@ #include "imap-quote.h" void imap_quote_append(string_t *str, const unsigned char *value, - size_t value_len, bool compress_lwsp) + size_t value_len, bool fix_text) { size_t i, extra = 0; bool last_lwsp = TRUE, literal = FALSE, modify = FALSE; @@ -23,14 +23,14 @@ void imap_quote_append(string_t *str, const unsigned char *value, case 0: /* it's converted to 8bit char */ literal = TRUE; - modify = TRUE; last_lwsp = FALSE; + modify = TRUE; break; case '\t': modify = TRUE; /* fall through */ case ' ': - if (last_lwsp && compress_lwsp) { + if (last_lwsp && fix_text) { modify = TRUE; extra++; } @@ -49,6 +49,11 @@ void imap_quote_append(string_t *str, const unsigned char *value, } } + if (!fix_text) { + extra = 0; + modify = FALSE; + } + if (!literal) { /* no 8bit chars or imapspecials, return as "string" */ str_append_c(str, '"'); @@ -69,7 +74,7 @@ void imap_quote_append(string_t *str, const unsigned char *value, break; case ' ': case '\t': - if (!last_lwsp || !compress_lwsp) + if (!last_lwsp) str_append_c(str, ' '); last_lwsp = TRUE; break; @@ -89,7 +94,7 @@ void imap_quote_append(string_t *str, const unsigned char *value, } const char *imap_quote(pool_t pool, const unsigned char *value, - size_t value_len) + size_t value_len, bool fix_text) { string_t *str; char *ret; @@ -101,7 +106,7 @@ const char *imap_quote(pool_t pool, const unsigned char *value, t_push(); str = t_str_new(value_len + MAX_INT_STRLEN + 5); - imap_quote_append(str, value, value_len, TRUE); + imap_quote_append(str, value, value_len, fix_text); ret = p_strndup(pool, str_data(str), str_len(str)); if (!pool->datastack_pool) diff --git a/src/lib-imap/imap-quote.h b/src/lib-imap/imap-quote.h index 7ee5afa290..ab65b34fbd 100644 --- a/src/lib-imap/imap-quote.h +++ b/src/lib-imap/imap-quote.h @@ -1,19 +1,19 @@ #ifndef IMAP_QUOTE_H #define IMAP_QUOTE_H -/* Return value suitable for sending to client, either as quoted-string or - literal. Note that this also converts TABs into spaces, multiple spaces - into single space and NULs to #128. */ -const char *imap_quote(pool_t pool, const unsigned char *value, - size_t value_len); - -/* Append to existing string. */ +/* Append to existing string. If fix_text=TRUE, it converts TABs to spaces, + multiple spaces into a single space and NULs to #128. */ void imap_quote_append(string_t *str, const unsigned char *value, - size_t value_len, bool compress_lwsp); + size_t value_len, bool fix_text); -#define imap_quote_append_string(str, value, compress_lwsp) \ +#define imap_quote_append_string(str, value, fix_text) \ imap_quote_append(str, (const unsigned char *)(value), \ - (size_t)-1, compress_lwsp) + (size_t)-1, fix_text) + +/* Return value suitable for sending to client, either as quoted-string or + literal. */ +const char *imap_quote(pool_t pool, const unsigned char *value, + size_t value_len, bool fix_text); /* Append data to destination string quoted using "". */ void imap_dquote_append(string_t *dest, const char *src);