changeset 15745:f7a0ef7fdaad

dsync: When looking up header hashes, use only Date: and Message-Id: headers This makes it more efficient, at least in future when imapc backend optimizes this.
author Timo Sirainen <tss@iki.fi>
date Sun, 10 Feb 2013 23:27:49 +0200
parents b4e2b3b54f0a
children 2aa20ea42d6d
files src/doveadm/dsync/dsync-mail.c
diffstat 1 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-mail.c	Sun Feb 10 23:11:52 2013 +0200
+++ b/src/doveadm/dsync/dsync-mail.c	Sun Feb 10 23:27:49 2013 +0200
@@ -9,32 +9,41 @@
 #include "mail-storage.h"
 #include "dsync-mail.h"
 
+/* These should be good enough to identify all normal mails. Received: header
+   would make it even better, but those can be somewhat large. Also these
+   fields can be looked up using IMAP ENVELOPE, which is more efficient in
+   some IMAP servers. */
+static const char *hashed_headers[] = {
+	"Date", "Message-ID", NULL
+};
+
 int dsync_mail_get_hdr_hash(struct mail *mail, const char **hdr_hash_r)
 {
-	struct message_size hdr_size;
-	struct istream *input, *hdr_input;
+	struct istream *input;
+	struct mailbox_header_lookup_ctx *hdr_ctx;
 	struct md5_context md5_ctx;
 	unsigned char md5_result[MD5_RESULTLEN];
 	const unsigned char *data;
 	size_t size;
 	int ret = 0;
-	
-	if (mail_get_hdr_stream(mail, &hdr_size, &input) < 0)
+
+	hdr_ctx = mailbox_header_lookup_init(mail->box, hashed_headers);
+	ret = mail_get_header_stream(mail, hdr_ctx, &input);
+	mailbox_header_lookup_unref(&hdr_ctx);
+	if (ret < 0)
 		return -1;
 
 	md5_init(&md5_ctx);
-	hdr_input = i_stream_create_limit(input, hdr_size.physical_size);
-	while (!i_stream_is_eof(hdr_input)) {
-		if (i_stream_read_data(hdr_input, &data, &size, 0) == -1)
+	while (!i_stream_is_eof(input)) {
+		if (i_stream_read_data(input, &data, &size, 0) == -1)
 			break;
 		if (size == 0)
 			break;
 		md5_update(&md5_ctx, data, size);
-		i_stream_skip(hdr_input, size);
+		i_stream_skip(input, size);
 	}
-	if (hdr_input->stream_errno != 0)
+	if (input->stream_errno != 0)
 		ret = -1;
-	i_stream_unref(&hdr_input);
 
 	md5_final(&md5_ctx, md5_result);
 	*hdr_hash_r = binary_to_hex(md5_result, sizeof(md5_result));