diff -urwpN dovecot-2.0.9.orig/src/lib-storage/index/mbox/mbox-mail.c dovecot-2.0.9/src/lib-storage/index/mbox/mbox-mail.c
--- dovecot-2.0.9.orig/src/lib-storage/index/mbox/mbox-mail.c	2010-12-30 14:42:54.000000000 +0500
+++ dovecot-2.0.9/src/lib-storage/index/mbox/mbox-mail.c	2011-02-07 17:38:57.000000000 +0500
@@ -146,6 +146,26 @@ static int mbox_mail_get_save_date(struc
 	return 0;
 }
 
+static const char *
+popa3d_uidl(const unsigned char *data, size_t size)
+{
+	char *buf;
+	int bufsz = size * 2 + 1;
+
+	buf = t_malloc(bufsz);
+
+	(void)i_snprintf(buf, bufsz,
+		"%02x%02x%02x%02x%02x%02x%02x%02x",
+		data[3], data[2],
+		data[1], data[0],
+		data[7], data[6],
+		data[5], data[4]
+	);
+
+	return buf;
+}
+
+
 static bool
 mbox_mail_get_md5_header(struct index_mail *mail, const char **value_r)
 {
@@ -162,7 +182,7 @@ mbox_mail_get_md5_header(struct index_ma
 			      &ext_data, NULL);
 	if (ext_data != NULL && memcmp(ext_data, empty_md5, 16) != 0) {
 		mail->data.guid = p_strdup(mail->data_pool,
-					   binary_to_hex(ext_data, 16));
+					   popa3d_uidl(ext_data, 8));
 		*value_r = mail->data.guid;
 		return TRUE;
 	} else {
diff -urwpN dovecot-2.0.9.orig/src/lib-storage/index/mbox/mbox-md5.c dovecot-2.0.9/src/lib-storage/index/mbox/mbox-md5.c
--- dovecot-2.0.9.orig/src/lib-storage/index/mbox/mbox-md5.c	2010-01-25 04:16:12.000000000 +0500
+++ dovecot-2.0.9/src/lib-storage/index/mbox/mbox-md5.c	2011-02-07 17:35:25.000000000 +0500
@@ -23,7 +23,11 @@ static bool parse_date(struct mbox_md5_c
 {
 	if (!ctx->seen_received_hdr) {
 		/* Received-header contains date too, and more trusted one */
-		md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
+		md5_update(&ctx->hdr_md5_ctx, hdr->name, hdr->name_len);
+		md5_update(&ctx->hdr_md5_ctx, ": ", 2);
+		md5_update(&ctx->hdr_md5_ctx, hdr->full_value, hdr->full_value_len);
+		if (!hdr->no_newline)
+			md5_update(&ctx->hdr_md5_ctx, "\n", 1);
 	}
 	return TRUE;
 }
@@ -31,7 +35,11 @@ static bool parse_date(struct mbox_md5_c
 static bool parse_delivered_to(struct mbox_md5_context *ctx,
 			       struct message_header_line *hdr)
 {
-	md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
+	md5_update(&ctx->hdr_md5_ctx, hdr->name, hdr->name_len);
+	md5_update(&ctx->hdr_md5_ctx, ": ", 2);
+	md5_update(&ctx->hdr_md5_ctx, hdr->full_value, hdr->full_value_len);
+	if (!hdr->no_newline)
+		md5_update(&ctx->hdr_md5_ctx, "\n", 1);
 	return TRUE;
 }
 
@@ -41,7 +49,11 @@ static bool parse_message_id(struct mbox
 	if (!ctx->seen_received_hdr) {
 		/* Received-header contains unique ID too,
 		   and more trusted one */
-		md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
+		md5_update(&ctx->hdr_md5_ctx, hdr->name, hdr->name_len);
+		md5_update(&ctx->hdr_md5_ctx, ": ", 2);
+		md5_update(&ctx->hdr_md5_ctx, hdr->full_value, hdr->full_value_len);
+		if (!hdr->no_newline)
+			md5_update(&ctx->hdr_md5_ctx, "\n", 1);
 	}
 	return TRUE;
 }
@@ -51,7 +63,11 @@ static bool parse_received(struct mbox_m
 {
 	if (!ctx->seen_received_hdr) {
 		/* get only the first received-header */
-		md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
+		md5_update(&ctx->hdr_md5_ctx, hdr->name, hdr->name_len);
+		md5_update(&ctx->hdr_md5_ctx, ": ", 2);
+		md5_update(&ctx->hdr_md5_ctx, hdr->full_value, hdr->full_value_len);
+		if (!hdr->no_newline)
+			md5_update(&ctx->hdr_md5_ctx, "\n", 1);
 		if (!hdr->continues)
 			ctx->seen_received_hdr = TRUE;
 	}
@@ -64,7 +80,11 @@ static bool parse_x_delivery_id(struct m
 	/* Let the local delivery agent help generate unique ID's but don't
 	   blindly trust this header alone as it could just as easily come from
 	   the remote. */
-	md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
+	md5_update(&ctx->hdr_md5_ctx, hdr->name, hdr->name_len);
+	md5_update(&ctx->hdr_md5_ctx, ": ", 2);
+	md5_update(&ctx->hdr_md5_ctx, hdr->full_value, hdr->full_value_len);
+	if (!hdr->no_newline)
+		md5_update(&ctx->hdr_md5_ctx, "\n", 1);
 	return TRUE;
 }
 
@@ -102,9 +122,14 @@ void mbox_md5_continue(struct mbox_md5_c
 	func = bsearch(hdr->name, md5_header_funcs,
 		       N_ELEMENTS(md5_header_funcs), sizeof(*md5_header_funcs),
 		       bsearch_header_func_cmp);
-	if (func != NULL)
+	if (func != NULL) {
+		if (hdr->continues) {
+			hdr->use_full_value = TRUE;
+		} else {
 		(void)func->func(ctx, hdr);
 }
+	}
+}
 
 void mbox_md5_finish(struct mbox_md5_context *ctx,
 		     unsigned char result[16])
