]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail, dsync: Moved dsync_mail_hash_more() to lib-mail/message-header-hash.*
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 28 Jan 2016 22:08:33 +0000 (00:08 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 1 Feb 2016 15:45:48 +0000 (17:45 +0200)
src/doveadm/dsync/Makefile.am
src/doveadm/dsync/dsync-mail.c
src/doveadm/dsync/dsync-mail.h
src/lib-mail/Makefile.am
src/lib-mail/message-header-hash.c [new file with mode: 0644]
src/lib-mail/message-header-hash.h [new file with mode: 0644]
src/lib-mail/test-message-header-hash.c [moved from src/doveadm/dsync/test-dsync-mail.c with 90% similarity]

index 99349175b259151efe8edd344648cc8fa0f6a417..16d88bf962a999212e3cf266fdd77fb62b6f1c2e 100644 (file)
@@ -58,7 +58,6 @@ noinst_HEADERS = \
        dsync-transaction-log-scan.h
 
 test_programs = \
-       test-dsync-mail \
        test-dsync-mailbox-tree-sync
 
 noinst_PROGRAMS = $(test_programs)
@@ -67,10 +66,6 @@ test_libs = \
        ../../lib-test/libtest.la \
        ../../lib/liblib.la
 
-test_dsync_mail_SOURCES = test-dsync-mail.c
-test_dsync_mail_LDADD = $(pkglib_LTLIBRARIES) $(test_libs)
-test_dsync_mail_DEPENDENCIES = $(pkglib_LTLIBRARIES) $(test_libs)
-
 test_dsync_mailbox_tree_sync_SOURCES = test-dsync-mailbox-tree-sync.c
 test_dsync_mailbox_tree_sync_LDADD = dsync-mailbox-tree-sync.lo dsync-mailbox-tree.lo $(test_libs)
 test_dsync_mailbox_tree_sync_DEPENDENCIES = $(pkglib_LTLIBRARIES) $(test_libs)
index 7550a57a85d2dfebee0a25647161024098911036..351a2f2a4b5d3733df18eb4d1874711b689b2059 100644 (file)
@@ -6,6 +6,7 @@
 #include "md5.h"
 #include "istream.h"
 #include "istream-crlf.h"
+#include "message-header-hash.h"
 #include "message-size.h"
 #include "mail-storage.h"
 #include "dsync-mail.h"
@@ -24,45 +25,6 @@ dsync_mail_get_hash_headers(struct mailbox *box)
        return mailbox_header_lookup_init(box, hashed_headers);
 }
 
-void dsync_mail_hash_more(struct md5_context *md5_ctx, unsigned int version,
-                         const unsigned char *data, size_t size)
-{
-       size_t i, start;
-
-       i_assert(version == 1 || version == 2);
-
-       if (version == 1) {
-               md5_update(md5_ctx, data, size);
-               return;
-       }
-       /* - Dovecot IMAP replaces NULs with 0x80 character.
-          - Dovecot POP3 with outlook-no-nuls workaround replaces NULs
-          with 0x80 character.
-          - Zimbra replaces 8bit chars with '?' in header fetches,
-          but not body fetches.
-          - Yahoo replaces 8bit chars with '?' in partial header
-          fetches, but not POP3 TOP. UTF-8 character sequence writes only a
-          single '?'
-
-          So we'll just replace all control and 8bit chars with '?' and
-          remove any repeated '?', which hopefully will satisfy everybody.
-
-          (Keep this code in sync with pop3-migration plugin.)
-          */
-       for (i = start = 0; i < size; i++) {
-               if ((data[i] < 0x20 || data[i] >= 0x7f || data[i] == '?') &&
-                   (data[i] != '\t' && data[i] != '\n')) {
-                       /* remove repeated '?' */
-                       if (start < i || i == 0) {
-                               md5_update(md5_ctx, data + start, i-start);
-                               md5_update(md5_ctx, "?", 1);
-                       }
-                       start = i+1;
-               }
-       }
-       md5_update(md5_ctx, data + start, i-start);
-}
-
 int dsync_mail_get_hdr_hash(struct mail *mail, unsigned int version,
                            const char **hdr_hash_r)
 {
@@ -88,7 +50,7 @@ int dsync_mail_get_hdr_hash(struct mail *mail, unsigned int version,
                        break;
                if (size == 0)
                        break;
-               dsync_mail_hash_more(&md5_ctx, version, data, size);
+               message_header_hash_more(&md5_ctx, version, data, size);
                i_stream_skip(input, size);
        }
        if (input->stream_errno != 0)
index 0b1ce9f1f99b12c4ebdb55e0bd5facd34fa04372..78a1a25084551763b2f90d6e7d22d7c6e861b40f 100644 (file)
@@ -96,8 +96,4 @@ int dsync_mail_fill_nonminimal(struct mail *mail, struct dsync_mail *dmail_r,
 void dsync_mail_change_dup(pool_t pool, const struct dsync_mail_change *src,
                           struct dsync_mail_change *dest_r);
 
-/* private: */
-void dsync_mail_hash_more(struct md5_context *md5_ctx, unsigned int version,
-                         const unsigned char *data, size_t size);
-
 #endif
index 7ae5a9d3ea2b1e044c1c3fca177346108fd728ea..6da8b9e63cff79e315e95e00992e25388b28fc10 100644 (file)
@@ -22,6 +22,7 @@ libmail_la_SOURCES = \
        message-decoder.c \
        message-header-decode.c \
        message-header-encode.c \
+       message-header-hash.c \
        message-header-parser.c \
        message-id.c \
        message-parser.c \
@@ -57,6 +58,7 @@ headers = \
        message-decoder.h \
        message-header-decode.h \
        message-header-encode.h \
+       message-header-hash.h \
        message-header-parser.h \
        message-id.h \
        message-parser.h \
@@ -87,6 +89,7 @@ test_programs = \
        test-message-decoder \
        test-message-header-decode \
        test-message-header-encode \
+       test-message-header-hash \
        test-message-header-parser \
        test-message-id \
        test-message-parser \
@@ -157,6 +160,10 @@ test_message_header_encode_SOURCES = test-message-header-encode.c
 test_message_header_encode_LDADD = message-header-encode.lo $(test_libs)
 test_message_header_encode_DEPENDENCIES = $(test_deps)
 
+test_message_header_hash_SOURCES = test-message-header-hash.c
+test_message_header_hash_LDADD = message-header-hash.lo $(test_libs)
+test_message_header_hash_DEPENDENCIES = $(test_deps)
+
 test_message_header_parser_SOURCES = test-message-header-parser.c
 test_message_header_parser_LDADD = message-header-parser.lo $(test_libs)
 test_message_header_parser_DEPENDENCIES = $(test_deps)
diff --git a/src/lib-mail/message-header-hash.c b/src/lib-mail/message-header-hash.c
new file mode 100644 (file)
index 0000000..289ef20
--- /dev/null
@@ -0,0 +1,45 @@
+/* Copyright (c) 2013-2016 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "md5.h"
+#include "message-header-hash.h"
+
+void message_header_hash_more(struct md5_context *md5_ctx,
+                             unsigned int version,
+                             const unsigned char *data, size_t size)
+{
+       size_t i, start;
+
+       i_assert(version == 1 || version == 2);
+
+       if (version == 1) {
+               md5_update(md5_ctx, data, size);
+               return;
+       }
+       /* - Dovecot IMAP replaces NULs with 0x80 character.
+          - Dovecot POP3 with outlook-no-nuls workaround replaces NULs
+          with 0x80 character.
+          - Zimbra replaces 8bit chars with '?' in header fetches,
+          but not body fetches.
+          - Yahoo replaces 8bit chars with '?' in partial header
+          fetches, but not POP3 TOP. UTF-8 character sequence writes only a
+          single '?'
+
+          So we'll just replace all control and 8bit chars with '?' and
+          remove any repeated '?', which hopefully will satisfy everybody.
+
+          (Keep this code in sync with pop3-migration plugin.)
+          */
+       for (i = start = 0; i < size; i++) {
+               if ((data[i] < 0x20 || data[i] >= 0x7f || data[i] == '?') &&
+                   (data[i] != '\t' && data[i] != '\n')) {
+                       /* remove repeated '?' */
+                       if (start < i || i == 0) {
+                               md5_update(md5_ctx, data + start, i-start);
+                               md5_update(md5_ctx, "?", 1);
+                       }
+                       start = i+1;
+               }
+       }
+       md5_update(md5_ctx, data + start, i-start);
+}
diff --git a/src/lib-mail/message-header-hash.h b/src/lib-mail/message-header-hash.h
new file mode 100644 (file)
index 0000000..3e5625c
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef MESSAGE_HEADER_HASH_H
+#define MESSAGE_HEADER_HASH_H
+
+struct md5_context;
+
+void message_header_hash_more(struct md5_context *md5_ctx,
+                             unsigned int version,
+                             const unsigned char *data, size_t size);
+
+#endif
similarity index 90%
rename from src/doveadm/dsync/test-dsync-mail.c
rename to src/lib-mail/test-message-header-hash.c
index a35ee64f0d6efc1b27280c6fb957a9f9de3b97f4..8133ad18418aa0257122a8a65f9b5f88dea6d034 100644 (file)
@@ -1,9 +1,9 @@
 /* Copyright (c) 2016 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "md5.h"
-#include "dsync-mail.h"
 #include "test-common.h"
+#include "md5.h"
+#include "message-header-hash.h"
 
 static const unsigned char test_input[] =
        "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
@@ -19,7 +19,7 @@ static void test_dsync_mail_hash_more(void)
 
        test_begin("dsync_mail_hash_more v2");
        md5_init(&md5_ctx);
-       dsync_mail_hash_more(&md5_ctx, 2, test_input, sizeof(test_input)-1);
+       message_header_hash_more(&md5_ctx, 2, test_input, sizeof(test_input)-1);
        md5_final(&md5_ctx, md5_input);
 
        md5_init(&md5_ctx);