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);
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);
}
}
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);
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':
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;
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);
(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)
#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;
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++;
}
}
}
+ if (!fix_text) {
+ extra = 0;
+ modify = FALSE;
+ }
+
if (!literal) {
/* no 8bit chars or imapspecials, return as "string" */
str_append_c(str, '"');
break;
case ' ':
case '\t':
- if (!last_lwsp || !compress_lwsp)
+ if (!last_lwsp)
str_append_c(str, ' ');
last_lwsp = TRUE;
break;
}
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;
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)
#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);