diff -urNp dovecot-1.0.beta9/src/lib-storage/index/index-mail.c dovecot-1.0.beta9-boco/src/lib-storage/index/index-mail.c
--- dovecot-1.0.beta9/src/lib-storage/index/index-mail.c	Mon May  8 17:40:57 2006
+++ dovecot-1.0.beta9-boco/src/lib-storage/index/index-mail.c	Thu Jun 22 17:31:18 2006
@@ -599,6 +599,24 @@ index_mail_get_plain_bodystructure(struc
 		str_append(str, " NIL NIL NIL");
 }
 
+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;
+}
+
 const char *index_mail_get_special(struct mail *_mail,
 				   enum mail_fetch_field field)
 {
@@ -703,7 +721,7 @@ const char *index_mail_get_special(struc
 		}
 		if (ext_data == NULL)
 			return NULL;
-		return binary_to_hex(ext_data, 16);
+		return popa3d_uidl(ext_data, 8);
 	default:
 		i_unreached();
 		return NULL;
diff -urNp dovecot-1.0.beta9/src/lib-storage/index/mbox/mbox-mail.c dovecot-1.0.beta9-boco/src/lib-storage/index/mbox/mbox-mail.c
--- dovecot-1.0.beta9/src/lib-storage/index/mbox/mbox-mail.c	Thu Jan 19 03:16:40 2006
+++ dovecot-1.0.beta9-boco/src/lib-storage/index/mbox/mbox-mail.c	Thu Jun 22 17:32:47 2006
@@ -114,7 +114,7 @@ static time_t mbox_mail_get_received_dat
 static const char *
 mbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field)
 {
-#define EMPTY_MD5_SUM "00000000000000000000000000000000"
+#define EMPTY_MD5_SUM "0000000000000000"
 	struct index_mail *mail = (struct index_mail *)_mail;
 	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
 	const char *value;
diff -urNp dovecot-1.0.beta9/src/lib-storage/index/mbox/mbox-md5.c dovecot-1.0.beta9-boco/src/lib-storage/index/mbox/mbox-md5.c
--- dovecot-1.0.beta9/src/lib-storage/index/mbox/mbox-md5.c	Sat Jan 14 01:26:37 2006
+++ dovecot-1.0.beta9-boco/src/lib-storage/index/mbox/mbox-md5.c	Thu Jun 22 17:27:52 2006
@@ -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;
 }
 
@@ -104,8 +124,13 @@ void mbox_md5_continue(struct mbox_md5_c
 	func = bsearch(hdr->name, md5_header_funcs,
 		       MD5_HEADER_FUNCS_COUNT, sizeof(*md5_header_funcs),
 		       bsearch_header_func_cmp);
-	if (func != NULL)
-		(void)func->func(ctx, hdr);
+	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,
