static const char *
hdr_strdup(pool_t pool, const unsigned char *data, size_t size)
{
- char *dest = p_malloc(pool, size+1);
-
if (memchr(data, '\0', size) == NULL) {
/* fast path */
+ char *dest = p_malloc(pool, size+1);
memcpy(dest, data, size);
- } else {
- /* slow path - this could be made faster, but it should be
- rare so keep it simple */
- for (size_t i = 0; i < size; i++)
- dest[i] = data[i] == '\0' ? 0x80 : data[i];
+ return dest;
+ }
+
+ /* slow path - this could be made faster, but it should be
+ rare so keep it simple */
+ string_t *str = str_new(pool, size+2);
+ for (size_t i = 0; i < size; i++) {
+ if (data[i] != '\0')
+ str_append_c(str, data[i]);
+ else
+ str_append(str, UNICODE_REPLACEMENT_CHAR_UTF8);
}
- return dest;
+ return str_c(str);
}
void message_part_envelope_parse_from_header(pool_t pool,
/* Parse all content parameters using rfc822_parse_content_param() and return
them as a NULL-terminated [key, value] array. RFC 2231-style continuations
- are merged to a single key. NULs are converted into 0x80. Returns -1 if some
- of the input was invalid (but valid key/value pairs are still returned), 0
- if everything looked ok. */
+ are merged to a single key. NULs are converted into unicode replacement
+ character (U+FFFD). Returns -1 if some of the input was invalid (but valid
+ key/value pairs are still returned), 0 if everything looked ok. */
int ATTR_NOWARN_UNUSED_RESULT
rfc2231_parse(struct rfc822_parser_context *ctx,
const char *const **result_r);
#ifndef RFC822_PARSER_H
#define RFC822_PARSER_H
+#include "unichar.h"
+
/* This can be used as a common NUL replacement character */
-#define RFC822_NUL_REPLACEMENT_STR "\x80"
+#define RFC822_NUL_REPLACEMENT_STR UNICODE_REPLACEMENT_CHAR_UTF8
struct rfc822_parser_context {
const unsigned char *data, *end;
const unsigned char input[] =
"\"user\0nuls\"@[domain\0nuls] (comment\0nuls)";
const struct message_address output = {
- NULL, "comment\x80nuls", NULL, "user\x80nuls",
- "[domain\x80nuls]", FALSE
+ NULL, "comment\xEF\xBF\xBDnuls", NULL, "user\xEF\xBF\xBDnuls",
+ "[domain\xEF\xBF\xBDnuls]", FALSE
};
const struct message_address *addr;
"; key*1=baz";
const char *output[] = {
"key",
- "f\x80oobazba%",
+ "f\xEF\xBF\xBDoobazba%",
"key2*",
"''ab%25",
"key3*",