Also move it to a better file.
#include "buffer.h"
#include "istream.h"
#include "str.h"
+#include "unichar.h"
#include "message-size.h"
#include "message-header-parser.h"
buffer_append_c(output, '\n');
}
}
+
+const char *
+message_header_strdup(pool_t pool, const unsigned char *data, size_t size)
+{
+ if (memchr(data, '\0', size) == NULL) {
+ /* fast path */
+ char *dest = p_malloc(pool, size+1);
+ memcpy(dest, data, size);
+ 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 str_c(str);
+}
void message_header_line_write(buffer_t *output,
const struct message_header_line *hdr);
+/* Duplicate the given header value data and return it. Replaces any NULs with
+ UNICODE_REPLACEMENT_CHAR_UTF8. */
+const char *
+message_header_strdup(pool_t pool, const unsigned char *data, size_t size);
+
#endif
return ENVELOPE_FIELD_UNKNOWN;
}
-static const char *
-message_header_strdup(pool_t pool, const unsigned char *data, size_t size)
-{
- if (memchr(data, '\0', size) == NULL) {
- /* fast path */
- char *dest = p_malloc(pool, size+1);
- memcpy(dest, data, size);
- 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 str_c(str);
-}
-
void message_part_envelope_parse_from_header(pool_t pool,
struct message_part_envelope **data,
struct message_header_line *hdr)