dovecot-2.1: mbox: Added mbox_md5 setting to select headers for ...

dovecot at dovecot.org dovecot at dovecot.org
Thu Feb 9 02:58:53 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/2500de8f1f51
changeset: 14088:2500de8f1f51
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Feb 09 02:58:36 2012 +0200
description:
mbox: Added mbox_md5 setting to select headers for MD5 generation.

diffstat:

 doc/example-config/conf.d/10-mail.conf       |    6 +
 src/lib-storage/index/mbox/Makefile.am       |    3 +-
 src/lib-storage/index/mbox/mbox-md5-all.c    |   40 +++++++++
 src/lib-storage/index/mbox/mbox-md5-apop3d.c |  120 +++++++++++++++++++++++++++
 src/lib-storage/index/mbox/mbox-md5.c        |  114 -------------------------
 src/lib-storage/index/mbox/mbox-md5.h        |   17 ++-
 src/lib-storage/index/mbox/mbox-save.c       |    8 +-
 src/lib-storage/index/mbox/mbox-settings.c   |    4 +-
 src/lib-storage/index/mbox/mbox-settings.h   |    1 +
 src/lib-storage/index/mbox/mbox-storage.c    |    9 ++
 src/lib-storage/index/mbox/mbox-storage.h    |    3 +
 src/lib-storage/index/mbox/mbox-sync-parse.c |   12 +-
 12 files changed, 206 insertions(+), 131 deletions(-)

diffs (truncated from 500 to 300 lines):

diff -r 408350532a18 -r 2500de8f1f51 doc/example-config/conf.d/10-mail.conf
--- a/doc/example-config/conf.d/10-mail.conf	Thu Feb 09 02:34:23 2012 +0200
+++ b/doc/example-config/conf.d/10-mail.conf	Thu Feb 09 02:58:36 2012 +0200
@@ -305,6 +305,12 @@
 # If an index file already exists it's still read, just not updated.
 #mbox_min_index_size = 0
 
+# Mail header selection algorithm to use for MD5 POP3 UIDLs when
+# pop3_uidl_format=%m. For backwards compatibility we use apop3d inspired
+# algorithm, but it fails if the first Received: header isn't unique in all
+# mails. An alternative algorithm is "all" that selects all headers.
+#mbox_md5 = apop3d
+
 ##
 ## mdbox-specific settings
 ##
diff -r 408350532a18 -r 2500de8f1f51 src/lib-storage/index/mbox/Makefile.am
--- a/src/lib-storage/index/mbox/Makefile.am	Thu Feb 09 02:34:23 2012 +0200
+++ b/src/lib-storage/index/mbox/Makefile.am	Thu Feb 09 02:58:36 2012 +0200
@@ -15,7 +15,8 @@
 	mbox-file.c \
 	mbox-lock.c \
 	mbox-mail.c \
-	mbox-md5.c \
+	mbox-md5-apop3d.c \
+	mbox-md5-all.c \
 	mbox-save.c \
 	mbox-settings.c \
 	mbox-sync-parse.c \
diff -r 408350532a18 -r 2500de8f1f51 src/lib-storage/index/mbox/mbox-md5-all.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/index/mbox/mbox-md5-all.c	Thu Feb 09 02:58:36 2012 +0200
@@ -0,0 +1,40 @@
+/* Copyright (c) 2004-2011 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "md5.h"
+#include "message-parser.h"
+#include "mbox-md5.h"
+
+#include <stdlib.h>
+
+struct mbox_md5_context {
+	struct md5_context hdr_md5_ctx;
+};
+
+static struct mbox_md5_context *mbox_md5_all_init(void)
+{
+	struct mbox_md5_context *ctx;
+
+	ctx = i_new(struct mbox_md5_context, 1);
+	md5_init(&ctx->hdr_md5_ctx);
+	return ctx;
+}
+
+static void mbox_md5_all_more(struct mbox_md5_context *ctx,
+			      struct message_header_line *hdr)
+{
+	md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
+}
+
+static void mbox_md5_all_finish(struct mbox_md5_context *ctx,
+				unsigned char result[16])
+{
+	md5_final(&ctx->hdr_md5_ctx, result);
+	i_free(ctx);
+}
+
+struct mbox_md5_vfuncs mbox_md5_all = {
+	mbox_md5_all_init,
+	mbox_md5_all_more,
+	mbox_md5_all_finish
+};
diff -r 408350532a18 -r 2500de8f1f51 src/lib-storage/index/mbox/mbox-md5-apop3d.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-storage/index/mbox/mbox-md5-apop3d.c	Thu Feb 09 02:58:36 2012 +0200
@@ -0,0 +1,120 @@
+/* Copyright (c) 2004-2011 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "md5.h"
+#include "message-parser.h"
+#include "mbox-md5.h"
+
+#include <stdlib.h>
+
+struct mbox_md5_context {
+	struct md5_context hdr_md5_ctx;
+	bool seen_received_hdr;
+};
+
+struct mbox_md5_header_func {
+	const char *header;
+	bool (*func)(struct mbox_md5_context *ctx,
+		     struct message_header_line *hdr);
+};
+
+static bool parse_date(struct mbox_md5_context *ctx,
+		       struct message_header_line *hdr)
+{
+	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);
+	}
+	return TRUE;
+}
+
+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);
+	return TRUE;
+}
+
+static bool parse_message_id(struct mbox_md5_context *ctx,
+			     struct message_header_line *hdr)
+{
+	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);
+	}
+	return TRUE;
+}
+
+static bool parse_received(struct mbox_md5_context *ctx,
+			   struct message_header_line *hdr)
+{
+	if (!ctx->seen_received_hdr) {
+		/* get only the first received-header */
+		md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
+		if (!hdr->continues)
+			ctx->seen_received_hdr = TRUE;
+	}
+	return TRUE;
+}
+
+static bool parse_x_delivery_id(struct mbox_md5_context *ctx,
+				struct message_header_line *hdr)
+{
+	/* 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);
+	return TRUE;
+}
+
+
+static struct mbox_md5_header_func md5_header_funcs[] = {
+	{ "Date", parse_date },
+	{ "Delivered-To", parse_delivered_to },
+	{ "Message-ID", parse_message_id },
+	{ "Received", parse_received },
+	{ "X-Delivery-ID", parse_x_delivery_id }
+};
+
+static int bsearch_header_func_cmp(const void *p1, const void *p2)
+{
+	const char *key = p1;
+	const struct mbox_md5_header_func *func = p2;
+
+	return strcasecmp(key, func->header);
+}
+
+static struct mbox_md5_context *mbox_md5_apop3d_init(void)
+{
+	struct mbox_md5_context *ctx;
+
+	ctx = i_new(struct mbox_md5_context, 1);
+	md5_init(&ctx->hdr_md5_ctx);
+	return ctx;
+}
+
+static void mbox_md5_apop3d_more(struct mbox_md5_context *ctx,
+				 struct message_header_line *hdr)
+{
+	struct mbox_md5_header_func *func;
+
+	func = bsearch(hdr->name, md5_header_funcs,
+		       N_ELEMENTS(md5_header_funcs), sizeof(*md5_header_funcs),
+		       bsearch_header_func_cmp);
+	if (func != NULL)
+		(void)func->func(ctx, hdr);
+}
+
+static void mbox_md5_apop3d_finish(struct mbox_md5_context *ctx,
+				   unsigned char result[16])
+{
+	md5_final(&ctx->hdr_md5_ctx, result);
+	i_free(ctx);
+}
+
+struct mbox_md5_vfuncs mbox_md5_apop3d = {
+	mbox_md5_apop3d_init,
+	mbox_md5_apop3d_more,
+	mbox_md5_apop3d_finish
+};
diff -r 408350532a18 -r 2500de8f1f51 src/lib-storage/index/mbox/mbox-md5.c
--- a/src/lib-storage/index/mbox/mbox-md5.c	Thu Feb 09 02:34:23 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-/* Copyright (c) 2004-2011 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "md5.h"
-#include "message-parser.h"
-#include "mbox-md5.h"
-
-#include <stdlib.h>
-
-struct mbox_md5_context {
-	struct md5_context hdr_md5_ctx;
-	bool seen_received_hdr;
-};
-
-struct mbox_md5_header_func {
-	const char *header;
-	bool (*func)(struct mbox_md5_context *ctx,
-		     struct message_header_line *hdr);
-};
-
-static bool parse_date(struct mbox_md5_context *ctx,
-		       struct message_header_line *hdr)
-{
-	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);
-	}
-	return TRUE;
-}
-
-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);
-	return TRUE;
-}
-
-static bool parse_message_id(struct mbox_md5_context *ctx,
-			     struct message_header_line *hdr)
-{
-	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);
-	}
-	return TRUE;
-}
-
-static bool parse_received(struct mbox_md5_context *ctx,
-			   struct message_header_line *hdr)
-{
-	if (!ctx->seen_received_hdr) {
-		/* get only the first received-header */
-		md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
-		if (!hdr->continues)
-			ctx->seen_received_hdr = TRUE;
-	}
-	return TRUE;
-}
-
-static bool parse_x_delivery_id(struct mbox_md5_context *ctx,
-				struct message_header_line *hdr)
-{
-	/* 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);
-	return TRUE;
-}
-
-
-static struct mbox_md5_header_func md5_header_funcs[] = {
-	{ "Date", parse_date },
-	{ "Delivered-To", parse_delivered_to },
-	{ "Message-ID", parse_message_id },
-	{ "Received", parse_received },
-	{ "X-Delivery-ID", parse_x_delivery_id }
-};
-
-static int bsearch_header_func_cmp(const void *p1, const void *p2)
-{
-	const char *key = p1;
-	const struct mbox_md5_header_func *func = p2;
-
-	return strcasecmp(key, func->header);
-}
-
-struct mbox_md5_context *mbox_md5_init(void)
-{
-	struct mbox_md5_context *ctx;
-
-	ctx = i_new(struct mbox_md5_context, 1);
-	md5_init(&ctx->hdr_md5_ctx);
-	return ctx;
-}
-
-void mbox_md5_continue(struct mbox_md5_context *ctx,
-		       struct message_header_line *hdr)
-{


More information about the dovecot-cvs mailing list