]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Quoting didn't remove CR and LF characters, so it could have caused
authorTimo Sirainen <tss@iki.fi>
Thu, 13 Feb 2003 21:07:44 +0000 (23:07 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 13 Feb 2003 21:07:44 +0000 (23:07 +0200)
corrupted ENVELOPE/BODY replies.

--HG--
branch : HEAD

src/lib-imap/imap-quote.c

index 9530e06a101d5736d84ed2925423cf779c8d7b64..66c15a5e61eb015d1e37587be11e068f1f3145b5 100644 (file)
@@ -7,7 +7,7 @@
 void imap_quote_append(string_t *str, const unsigned char *value,
                       size_t value_len)
 {
-       size_t i;
+       size_t i, linefeeds = 0;
        int literal = FALSE;
 
        for (i = 0; i < value_len; i++) {
@@ -16,6 +16,9 @@ void imap_quote_append(string_t *str, const unsigned char *value,
                        break;
                }
 
+               if (value[i] == 13 || value[i] == 10)
+                        linefeeds++;
+
                if ((value[i] & 0x80) != 0)
                        literal = TRUE;
        }
@@ -23,13 +26,22 @@ void imap_quote_append(string_t *str, const unsigned char *value,
        if (!literal) {
                /* no 8bit chars, return as "string" */
                str_append_c(str, '"');
-               str_append_n(str, value, value_len);
-               str_append_c(str, '"');
        } else {
                /* return as literal */
-               str_printfa(str, "{%"PRIuSIZE_T"}\r\n", value_len);
+               str_printfa(str, "{%"PRIuSIZE_T"}\r\n", value_len - linefeeds);
+       }
+
+       if (linefeeds == 0)
                str_append_n(str, value, value_len);
+       else {
+               for (i = 0; i < value_len; i++) {
+                       if (value[i] != 13 && value[i] != 10)
+                               str_append_c(str, value[i]);
+               }
        }
+
+       if (!literal)
+               str_append_c(str, '"');
 }
 
 const char *imap_quote_str_nil(const char *value)