dovecot-2.2: mbox: Handle broken Status: and X-Status: headers w...

dovecot at dovecot.org dovecot at dovecot.org
Tue Apr 16 20:08:24 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/c473f8d2540e
changeset: 16292:c473f8d2540e
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 16 20:08:18 2013 +0300
description:
mbox: Handle broken Status: and X-Status: headers without sync errors.

diffstat:

 src/lib-storage/index/mbox/mbox-sync-parse.c   |  18 +++++++++++++-----
 src/lib-storage/index/mbox/mbox-sync-private.h |   2 ++
 src/lib-storage/index/mbox/mbox-sync-update.c  |   6 ++++--
 3 files changed, 19 insertions(+), 7 deletions(-)

diffs (84 lines):

diff -r 854469baa57c -r c473f8d2540e src/lib-storage/index/mbox/mbox-sync-parse.c
--- a/src/lib-storage/index/mbox/mbox-sync-parse.c	Tue Apr 16 16:20:30 2013 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-parse.c	Tue Apr 16 20:08:18 2013 +0300
@@ -79,24 +79,31 @@
 	return 0;
 }
 
-static void parse_status_flags(struct mbox_sync_mail_context *ctx,
+static bool parse_status_flags(struct mbox_sync_mail_context *ctx,
 			       struct message_header_line *hdr,
 			       struct mbox_flag_type *flags_list)
 {
+	enum mail_flags flag;
 	size_t i;
+	bool duplicates = FALSE;
 
 	ctx->mail.flags ^= MBOX_NONRECENT_KLUDGE;
 	for (i = 0; i < hdr->full_value_len; i++) {
-		ctx->mail.flags |=
-			mbox_flag_find(flags_list, hdr->full_value[i]);
+		flag = mbox_flag_find(flags_list, hdr->full_value[i]);
+		if ((ctx->mail.flags & flag) != 0)
+			duplicates = TRUE;
+		else
+			ctx->mail.flags |= flag;
 	}
 	ctx->mail.flags ^= MBOX_NONRECENT_KLUDGE;
+	return duplicates;
 }
 
 static bool parse_status(struct mbox_sync_mail_context *ctx,
 			 struct message_header_line *hdr)
 {
-	parse_status_flags(ctx, hdr, mbox_status_flags);
+	if (parse_status_flags(ctx, hdr, mbox_status_flags))
+		ctx->mail.status_broken = TRUE;
 	ctx->hdr_pos[MBOX_HDR_STATUS] = str_len(ctx->header);
 	return TRUE;
 }
@@ -104,7 +111,8 @@
 static bool parse_x_status(struct mbox_sync_mail_context *ctx,
 			   struct message_header_line *hdr)
 {
-	parse_status_flags(ctx, hdr, mbox_xstatus_flags);
+	if (parse_status_flags(ctx, hdr, mbox_xstatus_flags))
+		ctx->mail.xstatus_broken = TRUE;
 	ctx->hdr_pos[MBOX_HDR_X_STATUS] = str_len(ctx->header);
 	return TRUE;
 }
diff -r 854469baa57c -r c473f8d2540e src/lib-storage/index/mbox/mbox-sync-private.h
--- a/src/lib-storage/index/mbox/mbox-sync-private.h	Tue Apr 16 16:20:30 2013 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-private.h	Tue Apr 16 20:08:18 2013 +0300
@@ -52,6 +52,8 @@
 	unsigned int uid_broken:1;
 	unsigned int expunged:1;
 	unsigned int pseudo:1;
+	unsigned int status_broken:1;
+	unsigned int xstatus_broken:1;
 
 	uoff_t from_offset;
 	uoff_t body_size;
diff -r 854469baa57c -r c473f8d2540e src/lib-storage/index/mbox/mbox-sync-update.c
--- a/src/lib-storage/index/mbox/mbox-sync-update.c	Tue Apr 16 16:20:30 2013 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-update.c	Tue Apr 16 20:08:18 2013 +0300
@@ -409,7 +409,8 @@
 mbox_sync_update_header_from_real(struct mbox_sync_mail_context *ctx,
 				  const struct mbox_sync_mail *mail)
 {
-	if ((ctx->mail.flags & STATUS_FLAGS_MASK) !=
+	if (mail->status_broken ||
+	    (ctx->mail.flags & STATUS_FLAGS_MASK) !=
 	    (mail->flags & STATUS_FLAGS_MASK) ||
 	    (ctx->mail.flags & MAIL_RECENT) != 0) {
 		ctx->mail.flags = (ctx->mail.flags & ~STATUS_FLAGS_MASK) |
@@ -418,7 +419,8 @@
                         ctx->mail.flags &= ~MAIL_RECENT;
 		mbox_sync_update_status(ctx);
 	}
-	if ((ctx->mail.flags & XSTATUS_FLAGS_MASK) !=
+	if (mail->xstatus_broken ||
+	    (ctx->mail.flags & XSTATUS_FLAGS_MASK) !=
 	    (mail->flags & XSTATUS_FLAGS_MASK)) {
 		ctx->mail.flags = (ctx->mail.flags & ~XSTATUS_FLAGS_MASK) |
 			(mail->flags & XSTATUS_FLAGS_MASK);


More information about the dovecot-cvs mailing list