dovecot-2.2: shared mailboxes: Per-user flags can now be stored ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jun 11 18:22:17 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/dbd42f7198eb
changeset: 14599:dbd42f7198eb
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jun 11 18:22:06 2012 +0300
description:
shared mailboxes: Per-user flags can now be stored in private index files.
This can be enabled by adding e.g.:

mail_location = mdbox:/var/shared/mdbox:INDEXPVT=~/mdbox/shared

diffstat:

 src/doveadm/doveadm-dump-log.c                     |    4 +-
 src/lib-index/mail-index-private.h                 |    4 +-
 src/lib-index/mail-index-transaction-export.c      |   31 ++-
 src/lib-index/mail-index-transaction-finish.c      |    4 +-
 src/lib-index/mail-index-transaction-private.h     |    8 +-
 src/lib-index/mail-index-transaction-update.c      |   10 +-
 src/lib-index/mail-index-transaction-view.c        |    2 +-
 src/lib-index/mail-index.h                         |    6 +-
 src/lib-index/mail-transaction-log.h               |    3 +-
 src/lib-index/test-mail-index-transaction-finish.c |    4 +-
 src/lib-index/test-mail-index-transaction-update.c |   14 +-
 src/lib-storage/index/Makefile.am                  |    1 +
 src/lib-storage/index/index-mail.c                 |   74 ++++++-
 src/lib-storage/index/index-storage.c              |    6 +
 src/lib-storage/index/index-storage.h              |    1 +
 src/lib-storage/index/index-sync-private.h         |    2 +
 src/lib-storage/index/index-sync-pvt.c             |  221 +++++++++++++++++++++
 src/lib-storage/index/index-sync.c                 |    3 +
 src/lib-storage/index/index-transaction.c          |   51 +++-
 src/lib-storage/index/shared/shared-list.c         |    1 +
 src/lib-storage/list/mailbox-list-fs.c             |    5 +
 src/lib-storage/list/mailbox-list-maildir.c        |    5 +
 src/lib-storage/mail-storage-private.h             |   11 +
 src/lib-storage/mail-storage.c                     |    8 +-
 src/lib-storage/mailbox-list-private.h             |    2 +
 src/lib-storage/mailbox-list.c                     |   42 ++-
 src/lib-storage/mailbox-list.h                     |    7 +-
 27 files changed, 466 insertions(+), 64 deletions(-)

diffs (truncated from 1035 to 300 lines):

diff -r 7d0ce7586c36 -r dbd42f7198eb src/doveadm/doveadm-dump-log.c
--- a/src/doveadm/doveadm-dump-log.c	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/doveadm/doveadm-dump-log.c	Mon Jun 11 18:22:06 2012 +0300
@@ -284,8 +284,8 @@
 		const struct mail_transaction_flag_update *u = data;
 
 		for (; size > 0; size -= sizeof(*u), u++) {
-			printf(" - uids=%u-%u (flags +%x-%x)\n",
-			       u->uid1, u->uid2, u->add_flags, u->remove_flags);
+			printf(" - uids=%u-%u (flags +%x-%x, modseq_inc_flag=%d)\n",
+			       u->uid1, u->uid2, u->add_flags, u->remove_flags, u->modseq_inc_flag);
 		}
 		break;
 	}
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/mail-index-private.h	Mon Jun 11 18:22:06 2012 +0300
@@ -39,8 +39,8 @@
 	 PTR_OFFSET((map)->rec_map->records, (idx) * (map)->hdr.record_size))
 
 #define MAIL_TRANSACTION_FLAG_UPDATE_IS_INTERNAL(u) \
-	((((u)->add_flags | (u)->remove_flags) & \
-	  MAIL_INDEX_FLAGS_MASK) == 0)
+	((((u)->add_flags | (u)->remove_flags) & MAIL_INDEX_FLAGS_MASK) == 0 && \
+	 (u)->modseq_inc_flag == 0)
 
 #define MAIL_INDEX_EXT_KEYWORDS "keywords"
 
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-export.c
--- a/src/lib-index/mail-index-transaction-export.c	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/mail-index-transaction-export.c	Mon Jun 11 18:22:06 2012 +0300
@@ -20,6 +20,34 @@
 					buf->data, buf->used);
 }
 
+static void log_append_flag_updates(struct mail_index_export_context *ctx,
+				    struct mail_index_transaction *t)
+{
+	ARRAY_DEFINE(log_updates, struct mail_transaction_flag_update);
+	const struct mail_index_flag_update *updates;
+	struct mail_transaction_flag_update *log_update;
+	unsigned int i, count;
+
+	updates = array_get(&t->updates, &count);
+	if (count == 0)
+		return;
+
+	i_array_init(&log_updates, count);
+
+	for (i = 0; i < count; i++) {
+		log_update = array_append_space(&log_updates);
+		log_update->uid1 = updates[i].uid1;
+		log_update->uid2 = updates[i].uid2;
+		log_update->add_flags = updates[i].add_flags & 0xff;
+		log_update->remove_flags = updates[i].remove_flags & 0xff;
+		if ((updates[i].add_flags & MAIL_INDEX_MAIL_FLAG_UPDATE_MODSEQ) != 0)
+			log_update->modseq_inc_flag = 1;
+	}
+	log_append_buffer(ctx, log_updates.arr.buffer,
+			  MAIL_TRANSACTION_FLAG_UPDATE);
+	array_free(&log_updates);
+}
+
 static const buffer_t *
 log_get_hdr_update_buffer(struct mail_index_transaction *t, bool prepend)
 {
@@ -373,8 +401,7 @@
 
 	if (array_is_created(&t->updates)) {
 		change_mask |= MAIL_INDEX_SYNC_TYPE_FLAGS;
-		log_append_buffer(&ctx, t->updates.arr.buffer, 
-				  MAIL_TRANSACTION_FLAG_UPDATE);
+		log_append_flag_updates(&ctx, t);
 	}
 
 	if (array_is_created(&t->ext_rec_updates)) {
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-finish.c
--- a/src/lib-index/mail-index-transaction-finish.c	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/mail-index-transaction-finish.c	Mon Jun 11 18:22:06 2012 +0300
@@ -80,7 +80,7 @@
 
 static unsigned int
 mail_transaction_drop_range(struct mail_index_transaction *t,
-			    struct mail_transaction_flag_update update,
+			    struct mail_index_flag_update update,
 			    unsigned int update_idx,
 			    ARRAY_TYPE(seq_range) *keeps)
 {
@@ -109,7 +109,7 @@
 static void
 mail_index_transaction_finish_flag_updates(struct mail_index_transaction *t)
 {
-	const struct mail_transaction_flag_update *updates, *u;
+	const struct mail_index_flag_update *updates, *u;
 	const struct mail_index_record *rec;
 	unsigned int i, count;
 	ARRAY_TYPE(seq_range) keeps;
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-private.h
--- a/src/lib-index/mail-index-transaction-private.h	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/mail-index-transaction-private.h	Mon Jun 11 18:22:06 2012 +0300
@@ -29,6 +29,12 @@
 	struct mail_index_module_register *reg;
 };
 
+struct mail_index_flag_update {
+	uint32_t uid1, uid2;
+	uint16_t add_flags;
+	uint16_t remove_flags;
+};
+
 struct mail_index_transaction {
 	int refcount;
 
@@ -47,7 +53,7 @@
 
 	ARRAY_DEFINE(modseq_updates, struct mail_transaction_modseq_update);
 	ARRAY_DEFINE(expunges, struct mail_transaction_expunge_guid);
-	ARRAY_DEFINE(updates, struct mail_transaction_flag_update);
+	ARRAY_DEFINE(updates, struct mail_index_flag_update);
 	size_t last_update_idx;
 
 	unsigned char pre_hdr_change[sizeof(struct mail_index_header)];
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-update.c
--- a/src/lib-index/mail-index-transaction-update.c	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/mail-index-transaction-update.c	Mon Jun 11 18:22:06 2012 +0300
@@ -388,7 +388,7 @@
 					   unsigned int right_idx,
 					   uint32_t seq)
 {
-	const struct mail_transaction_flag_update *updates;
+	const struct mail_index_flag_update *updates;
 	unsigned int idx, count;
 
 	updates = array_get(&t->updates, &count);
@@ -414,10 +414,10 @@
 
 static void
 mail_index_insert_flag_update(struct mail_index_transaction *t,
-			      struct mail_transaction_flag_update u,
+			      struct mail_index_flag_update u,
 			      unsigned int idx)
 {
-	struct mail_transaction_flag_update *updates, tmp_update;
+	struct mail_index_flag_update *updates, tmp_update;
 	unsigned int count, first_idx, max;
 
 	updates = array_get_modifiable(&t->updates, &count);
@@ -543,7 +543,7 @@
 				   enum mail_flags flags)
 {
 	struct mail_index_record *rec;
-	struct mail_transaction_flag_update u, *last_update;
+	struct mail_index_flag_update u, *last_update;
 	unsigned int idx, first_idx, count;
 
 	update_minmax_flagupdate_seq(t, seq1, seq2);
@@ -1108,7 +1108,7 @@
 bool mail_index_cancel_flag_updates(struct mail_index_transaction *t,
 				    uint32_t seq)
 {
-	struct mail_transaction_flag_update *updates, tmp_update;
+	struct mail_index_flag_update *updates, tmp_update;
 	unsigned int i, count;
 
 	if (!array_is_created(&t->updates))
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-view.c
--- a/src/lib-index/mail-index-transaction-view.c	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/mail-index-transaction-view.c	Mon Jun 11 18:22:06 2012 +0300
@@ -85,7 +85,7 @@
 			 const struct mail_index_record *rec, uint32_t seq)
 {
 	struct mail_index_transaction *t = tview->t;
-	const struct mail_transaction_flag_update *updates;
+	const struct mail_index_flag_update *updates;
 	struct mail_index_record *trec;
 	unsigned int idx, count;
 
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/mail-index.h	Mon Jun 11 18:22:06 2012 +0300
@@ -42,9 +42,11 @@
 
 enum mail_index_mail_flags {
 	/* For private use by backend. Replacing flags doesn't change this. */
-	MAIL_INDEX_MAIL_FLAG_BACKEND	= 0x40,
+	MAIL_INDEX_MAIL_FLAG_BACKEND		= 0x40,
 	/* Message flags haven't been written to backend */
-	MAIL_INDEX_MAIL_FLAG_DIRTY	= 0x80
+	MAIL_INDEX_MAIL_FLAG_DIRTY		= 0x80,
+	/* Force updating this message's modseq via a flag update record */
+	MAIL_INDEX_MAIL_FLAG_UPDATE_MODSEQ	= 0x100
 };
 
 #define MAIL_INDEX_FLAGS_MASK \
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-transaction-log.h
--- a/src/lib-index/mail-transaction-log.h	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/mail-transaction-log.h	Mon Jun 11 18:22:06 2012 +0300
@@ -90,7 +90,8 @@
 	uint32_t uid1, uid2;
 	uint8_t add_flags;
 	uint8_t remove_flags;
-	uint16_t padding;
+	uint8_t modseq_inc_flag;
+	uint8_t padding;
 };
 
 struct mail_transaction_keyword_update {
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/test-mail-index-transaction-finish.c
--- a/src/lib-index/test-mail-index-transaction-finish.c	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/test-mail-index-transaction-finish.c	Mon Jun 11 18:22:06 2012 +0300
@@ -60,8 +60,8 @@
 static void test_mail_index_transaction_finish_flag_updates(void)
 {
 	struct mail_index_transaction *t;
-	const struct mail_transaction_flag_update *updates;
-	struct mail_transaction_flag_update u;
+	const struct mail_index_flag_update *updates;
+	struct mail_index_flag_update u;
 	unsigned int count;
 
 	t = t_new(struct mail_index_transaction, 1);
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/test-mail-index-transaction-update.c
--- a/src/lib-index/test-mail-index-transaction-update.c	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-index/test-mail-index-transaction-update.c	Mon Jun 11 18:22:06 2012 +0300
@@ -139,7 +139,7 @@
 static void test_mail_index_flag_update_fastpath(void)
 {
 	struct mail_index_transaction *t;
-	const struct mail_transaction_flag_update *updates;
+	const struct mail_index_flag_update *updates;
 	unsigned int count;
 
 	hdr.messages_count = 20;
@@ -168,12 +168,10 @@
 	test_assert(updates[0].add_flags == MAIL_DELETED);
 	test_assert(updates[0].remove_flags ==
 		    (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_SEEN | MAIL_DRAFT));
-	test_assert(updates[0].padding == 0);
 	test_assert(updates[1].uid1 == 16);
 	test_assert(updates[1].uid2 == 16);
 	test_assert(updates[1].add_flags == MAIL_DELETED);
 	test_assert(updates[1].remove_flags == 0);
-	test_assert(updates[1].padding == 0);
 	test_assert(!t->log_updates);
 	test_end();
 }
@@ -181,7 +179,7 @@
 static void test_mail_index_flag_update_simple_merges(void)
 {
 	struct mail_index_transaction *t;
-	const struct mail_transaction_flag_update *updates;
+	const struct mail_index_flag_update *updates;
 	unsigned int count;
 
 	hdr.messages_count = 20;
@@ -224,7 +222,7 @@
 static void test_mail_index_flag_update_complex_merges(void)
 {
 	struct mail_index_transaction *t;
-	const struct mail_transaction_flag_update *updates;
+	const struct mail_index_flag_update *updates;
 	unsigned int count;
 
 	hdr.messages_count = 20;
@@ -283,7 +281,7 @@
 flags_array_check(struct mail_index_transaction *t,
 		  const enum mail_flags *flags, unsigned int msg_count)
 {
-	const struct mail_transaction_flag_update *updates;
+	const struct mail_index_flag_update *updates;
 	unsigned int i, count, seq;
 
 	if (array_is_created(&t->updates))
@@ -357,7 +355,7 @@
 static void test_mail_index_cancel_flag_updates(void)
 {
 	struct mail_index_transaction *t;
-	const struct mail_transaction_flag_update *updates;
+	const struct mail_index_flag_update *updates;
 	unsigned int count;
 
 	hdr.messages_count = 20;
@@ -390,7 +388,7 @@
 {
 	struct mail_index_transaction *t;
 	const struct mail_index_record *appends;
-	const struct mail_transaction_flag_update *updates;
+	const struct mail_index_flag_update *updates;
 	unsigned int count;
 	uint32_t seq;
 
diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-storage/index/Makefile.am
--- a/src/lib-storage/index/Makefile.am	Tue Jun 05 00:34:32 2012 +0300
+++ b/src/lib-storage/index/Makefile.am	Mon Jun 11 18:22:06 2012 +0300
@@ -26,6 +26,7 @@
 	index-storage.c \
 	index-sync.c \
 	index-sync-changes.c \
+	index-sync-pvt.c \
 	index-sync-search.c \


More information about the dovecot-cvs mailing list