]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: Make message_header_strdup() public
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Aug 2018 11:33:50 +0000 (14:33 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 17 Aug 2018 17:18:23 +0000 (20:18 +0300)
Also move it to a better file.

src/lib-mail/message-header-parser.c
src/lib-mail/message-header-parser.h
src/lib-mail/message-part-data.c

index e6ea377458a37bb72f863bcf87dd15c593d930eb..f8f99747620fa91553ac69af82a4d8d4cd69a658 100644 (file)
@@ -4,6 +4,7 @@
 #include "buffer.h"
 #include "istream.h"
 #include "str.h"
+#include "unichar.h"
 #include "message-size.h"
 #include "message-header-parser.h"
 
@@ -411,3 +412,25 @@ void message_header_line_write(buffer_t *output,
                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);
+}
index d6863524aabf2279adc8026612754ef30d8808b0..3f3d24d44cdd7ad87166e34c7904bd5dafac2528 100644 (file)
@@ -74,4 +74,9 @@ void message_parse_header(struct istream *input, struct message_size *hdr_size,
 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
index 57a0f3e36d22156b78f25823b3c707633178511f..1263ab30dda1f92d40ed764f4457458390f379db 100644 (file)
@@ -170,28 +170,6 @@ envelope_get_field(const char *name)
        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)