diff -urNb dovecot-1.1.11.orig/src/lib-storage/index/index-mail.c dovecot-1.1.11/src/lib-storage/index/index-mail.c
--- dovecot-1.1.11.orig/src/lib-storage/index/index-mail.c	Tue Jan  6 19:33:51 2009
+++ dovecot-1.1.11/src/lib-storage/index/index-mail.c	Wed Apr 22 09:44:32 2009
@@ -898,6 +898,24 @@
 		str_append(str, " NIL 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;
+}
+
 int index_mail_get_special(struct mail *_mail,
 			   enum mail_fetch_field field, const char **value_r)
 {
@@ -1011,7 +1029,7 @@
 			*value_r = "";
 			return 0;
 		}
-		*value_r = binary_to_hex(ext_data, 16);
+		*value_r = popa3d_uidl(ext_data, 8);
 		return 0;
 	default:
 		i_unreached();
diff -urNb dovecot-1.1.11.orig/src/lib-storage/index/mbox/mbox-mail.c dovecot-1.1.11/src/lib-storage/index/mbox/mbox-mail.c
--- dovecot-1.1.11.orig/src/lib-storage/index/mbox/mbox-mail.c	Tue Jan  6 19:33:51 2009
+++ dovecot-1.1.11/src/lib-storage/index/mbox/mbox-mail.c	Wed Apr 22 09:42:56 2009
@@ -145,7 +145,7 @@
 mbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
 		      const char **value_r)
 {
-#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;
 
diff -urNb dovecot-1.1.11.orig/src/lib-storage/index/mbox/mbox-md5.c dovecot-1.1.11/src/lib-storage/index/mbox/mbox-md5.c
--- dovecot-1.1.11.orig/src/lib-storage/index/mbox/mbox-md5.c	Tue Jan  6 19:33:51 2009
+++ dovecot-1.1.11/src/lib-storage/index/mbox/mbox-md5.c	Wed Apr 22 09:42:56 2009
@@ -23,7 +23,11 @@
 {
 	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_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 @@
 	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 @@
 {
 	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 @@
 	/* 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,8 +122,13 @@
 	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,
