]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap_quote*() now have fix_text parameter. If it's not set, input isn't modified...
authorTimo Sirainen <tss@iki.fi>
Fri, 28 Aug 2009 21:27:08 +0000 (17:27 -0400)
committerTimo Sirainen <tss@iki.fi>
Fri, 28 Aug 2009 21:27:08 +0000 (17:27 -0400)
--HG--
branch : HEAD

src/lib-imap/imap-bodystructure.c
src/lib-imap/imap-envelope.c
src/lib-imap/imap-quote.c
src/lib-imap/imap-quote.h

index 41475d1f17197854822727d834a68a6106a39c51..1076cecac2e67b4ef3fbb4f3256bbacaabbe5bfe 100644 (file)
@@ -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);
index 81ae7d996f05fdc1c88c94d9c2d48830f1bf09f7..bec1ffd29ca08ab89d940a2d014415a079beaa4e 100644 (file)
@@ -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)
index 3fe9451037b50314b7986e0898733de1cae38f06..592b4c1a48a5f9f0e21d3c296d07b5a9c108fa22 100644 (file)
@@ -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)
index 7ee5afa290b9028db15750fd67592c6ef374ed30..ab65b34fbdf528d3c20f1bb67bbf4a0fc117617c 100644 (file)
@@ -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);