[dovecot-cvs] dovecot/src/lib-storage/index index-fetch.c,1.48,1.49 index-mail.c,1.11,1.12 index-mail.h,1.3,1.4 index-search.c,1.76,1.77 index-storage.h,1.42,1.43 index-sync.c,1.25,1.26 index-update-flags.c,1.22,1.23

cras at procontrol.fi cras at procontrol.fi
Wed Jul 23 05:44:18 EEST 2003


Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv15228/lib-storage/index

Modified Files:
	index-fetch.c index-mail.c index-mail.h index-search.c 
	index-storage.h index-sync.c index-update-flags.c 
Log Message:
API change for updating message flags.



Index: index-fetch.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-fetch.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- index-fetch.c	23 Jul 2003 00:40:50 -0000	1.48
+++ index-fetch.c	23 Jul 2003 01:44:16 -0000	1.49
@@ -17,13 +17,12 @@
 	struct messageset_context *msgset_ctx;
 	struct index_mail mail;
 
-	int update_seen;
 	enum mail_lock_type old_lock;
 };
 
 struct mail_fetch_context *
 index_storage_fetch_init(struct mailbox *box,
-			 enum mail_fetch_field wanted_fields, int *update_seen,
+			 enum mail_fetch_field wanted_fields, int update_flags,
 			 const char *messageset, int uidset)
 {
 	struct index_mailbox *ibox = (struct index_mailbox *) box;
@@ -33,11 +32,8 @@
 	ctx = i_new(struct mail_fetch_context, 1);
 	ctx->old_lock = ibox->index->lock_type;
 
-	if (box->readonly && update_seen != NULL)
-		*update_seen = FALSE;
-
 	/* need exclusive lock to update the \Seen flags */
-	if (update_seen != NULL && *update_seen) {
+	if (update_flags && !box->readonly) {
 		if (!index_storage_lock(ibox, MAIL_LOCK_EXCLUSIVE))
 			return NULL;
 	}
@@ -48,19 +44,8 @@
 					 MAIL_LOCK_SHARED))
 		return NULL;
 
-	if (update_seen != NULL && *update_seen &&
-	    ibox->index->header->messages_count ==
-	    ibox->index->header->seen_messages_count &&
-	    ctx->old_lock != MAIL_LOCK_EXCLUSIVE) {
-		/* if all messages are already seen, there's no point in
-		   keeping exclusive lock */
-		*update_seen = FALSE;
-		(void)index_storage_lock(ibox, MAIL_LOCK_SHARED);
-	}
-
 	ctx->ibox = ibox;
 	ctx->index = ibox->index;
-	ctx->update_seen = update_seen != NULL && *update_seen;
 
 	index_mail_init(ibox, &ctx->mail, wanted_fields, NULL);
 	ctx->msgset_ctx = index_messageset_init(ibox, messageset, uidset, TRUE);
@@ -89,7 +74,6 @@
 struct mail *index_storage_fetch_next(struct mail_fetch_context *ctx)
 {
 	const struct messageset_mail *msgset_mail;
-	struct mail_index_record *rec;
 	int ret;
 
 	do {
@@ -97,20 +81,11 @@
 		if (msgset_mail == NULL)
 			return NULL;
 
-		rec = msgset_mail->rec;
-		ctx->mail.mail.seen_updated = FALSE;
-		if (ctx->update_seen && (rec->msg_flags & MAIL_SEEN) == 0) {
-			if (ctx->index->update_flags(ctx->index, rec,
-						     msgset_mail->idx_seq,
-						     rec->msg_flags | MAIL_SEEN,
-						     FALSE))
-				ctx->mail.mail.seen_updated = TRUE;
-		}
-
 		ctx->mail.mail.seq = msgset_mail->client_seq;
-		ctx->mail.mail.uid = rec->uid;
+		ctx->mail.mail.uid = msgset_mail->rec->uid;
 
-		ret = index_mail_next(&ctx->mail, rec);
+		ret = index_mail_next(&ctx->mail, msgset_mail->rec,
+				      msgset_mail->idx_seq);
 	} while (ret == 0);
 
 	return ret < 0 ? NULL : &ctx->mail.mail;
@@ -118,13 +93,13 @@
 
 static struct mail *
 fetch_record(struct index_mailbox *ibox, struct mail_index_record *rec,
-	     enum mail_fetch_field wanted_fields)
+	     unsigned int idx_seq, enum mail_fetch_field wanted_fields)
 {
 	if (ibox->fetch_mail.pool != NULL)
 		index_mail_deinit(&ibox->fetch_mail);
 
 	index_mail_init(ibox, &ibox->fetch_mail, wanted_fields, NULL);
-	if (index_mail_next(&ibox->fetch_mail, rec) <= 0)
+	if (index_mail_next(&ibox->fetch_mail, rec, idx_seq) <= 0)
 		return NULL;
 
 	return &ibox->fetch_mail.mail;
@@ -134,15 +109,16 @@
 				     enum mail_fetch_field wanted_fields)
 {
 	struct index_mailbox *ibox = (struct index_mailbox *) box;
-        struct mail_index_record *rec;
+	struct mail_index_record *rec;
+	unsigned int seq;
 
 	i_assert(ibox->index->lock_type != MAIL_LOCK_UNLOCK);
 
-	rec = ibox->index->lookup_uid_range(ibox->index, uid, uid, NULL);
+	rec = ibox->index->lookup_uid_range(ibox->index, uid, uid, &seq);
 	if (rec == NULL)
 		return NULL;
 
-	return fetch_record(ibox, rec, wanted_fields);
+	return fetch_record(ibox, rec, seq, wanted_fields);
 }
 
 struct mail *index_storage_fetch_seq(struct mailbox *box, unsigned int seq,
@@ -158,9 +134,10 @@
 					    &expunges_before) == NULL)
 		return NULL;
 
-	rec = ibox->index->lookup(ibox->index, seq - expunges_before);
+	seq -= expunges_before;
+	rec = ibox->index->lookup(ibox->index, seq);
 	if (rec == NULL)
 		return NULL;
 
-	return fetch_record(ibox, rec, wanted_fields);
+	return fetch_record(ibox, rec, seq, wanted_fields);
 }

Index: index-mail.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- index-mail.c	23 Jul 2003 00:40:50 -0000	1.11
+++ index-mail.c	23 Jul 2003 01:44:16 -0000	1.12
@@ -637,7 +637,7 @@
 }
 
 static struct mail index_mail = {
-	0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0,
 
 	get_flags,
 	get_parts,
@@ -649,6 +649,7 @@
 	get_first_mailbox,
 	get_stream,
 	get_special,
+	index_storage_update_flags,
 	index_storage_copy
 };
 
@@ -668,7 +669,8 @@
 		ibox->mail_init(mail);
 }
 
-int index_mail_next(struct index_mail *mail, struct mail_index_record *rec)
+int index_mail_next(struct index_mail *mail, struct mail_index_record *rec,
+		    unsigned int idx_seq)
 {
 	struct index_mail_data *data = &mail->data;
 	int ret, open_mail, parse_header, envelope_headers;
@@ -688,6 +690,7 @@
 		(rec->index_flags & INDEX_MAIL_FLAG_HAS_NO_NULS) != 0;
 
 	data->rec = rec;
+	data->idx_seq = idx_seq;
 	data->size = (uoff_t)-1;
 	data->received_date = data->sent_time = (time_t)-1;
 

Index: index-mail.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mail.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- index-mail.h	26 Mar 2003 17:29:02 -0000	1.3
+++ index-mail.h	23 Jul 2003 01:44:16 -0000	1.4
@@ -22,6 +22,8 @@
         struct message_part_envelope_data *envelope_data;
 
 	struct mail_index_record *rec;
+	unsigned int idx_seq;
+
 	struct istream *stream;
         struct message_size hdr_size, body_size;
 
@@ -47,7 +49,8 @@
 void index_mail_init(struct index_mailbox *ibox, struct index_mail *mail,
 		     enum mail_fetch_field wanted_fields,
 		     const char *const wanted_headers[]);
-int index_mail_next(struct index_mail *mail, struct mail_index_record *rec);
+int index_mail_next(struct index_mail *mail, struct mail_index_record *rec,
+		    unsigned int idx_seq);
 void index_mail_deinit(struct index_mail *mail);
 
 void index_mail_init_parse_header(struct index_mail *mail);

Index: index-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- index-search.c	9 Jul 2003 15:23:40 -0000	1.76
+++ index-search.c	23 Jul 2003 01:44:16 -0000	1.77
@@ -1003,7 +1003,8 @@
 
 		ctx->mail->seq = msgset_mail->client_seq;
 		ctx->mail->uid = msgset_mail->rec->uid;
-		ret = index_mail_next(&ctx->imail, msgset_mail->rec);
+		ret = index_mail_next(&ctx->imail, msgset_mail->rec,
+				      msgset_mail->idx_seq);
 
 		if (ret < 0)
 			return NULL;

Index: index-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- index-storage.h	23 Jul 2003 00:40:50 -0000	1.42
+++ index-storage.h	23 Jul 2003 01:44:16 -0000	1.43
@@ -88,14 +88,10 @@
 			     enum mailbox_status_items items,
 			     struct mailbox_status *status);
 int index_storage_sync(struct mailbox *box, enum mail_sync_flags flags);
-int index_storage_update_flags(struct mailbox *box, const char *messageset,
-			       int uidset, const struct mail_full_flags *flags,
-			       enum modify_type modify_type, int notify,
-			       int *all_found);
 
 struct mail_fetch_context *
 index_storage_fetch_init(struct mailbox *box,
-			 enum mail_fetch_field wanted_fields, int *update_seen,
+			 enum mail_fetch_field wanted_fields, int update_flags,
 			 const char *messageset, int uidset);
 int index_storage_fetch_deinit(struct mail_fetch_context *ctx, int *all_found);
 struct mail *index_storage_fetch_next(struct mail_fetch_context *ctx);
@@ -119,5 +115,9 @@
 struct mail_copy_context *index_storage_copy_init(struct mailbox *box);
 int index_storage_copy_deinit(struct mail_copy_context *ctx, int rollback);
 int index_storage_copy(struct mail *mail, struct mail_copy_context *ctx);
+
+int index_storage_update_flags(struct mail *mail,
+			       const struct mail_full_flags *flags,
+			       enum modify_type modify_type);
 
 #endif

Index: index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-sync.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- index-sync.c	15 Jun 2003 03:42:29 -0000	1.25
+++ index-sync.c	23 Jul 2003 01:44:16 -0000	1.26
@@ -99,10 +99,9 @@
 {
 	const struct modify_log_record *log1, *log2, *log, *first_flag_log;
 	struct mail_index_record *rec;
-	enum mail_flags flags;
+	struct mail_full_flags flags;
         struct mail_storage_callbacks *sc;
 	void *sc_context;
-	const char **custom_flags;
 	unsigned int count1, count2, total_count, seq, seq_count, i, messages;
 	unsigned int first_flag_change, first_flag_messages_count;
 
@@ -159,7 +158,9 @@
 
 	/* now show the flags */
 	messages = first_flag_messages_count;
-	custom_flags = mail_custom_flags_list_get(ibox->index->custom_flags);
+	flags.custom_flags =
+		mail_custom_flags_list_get(ibox->index->custom_flags);
+	flags.custom_flags_count = MAIL_CUSTOM_FLAGS_COUNT;
 
 	if (sc->update_flags == NULL) {
 		/* don't bother going through, we're not printing them anyway */
@@ -185,19 +186,17 @@
 							    log->uid1,
 							    log->uid2, &seq);
 			while (rec != NULL && rec->uid <= log->uid2) {
-				flags = rec->msg_flags;
+				flags.flags = rec->msg_flags;
 				if (rec->uid >= ibox->index->first_recent_uid)
-					flags |= MAIL_RECENT;
+					flags.flags |= MAIL_RECENT;
 
 				/* \Deleted-hiding is useful when syncing just
 				   before doing EXPUNGE. */
-				if ((flags & MAIL_DELETED) == 0 ||
+				if ((flags.flags & MAIL_DELETED) == 0 ||
 				    !hide_deleted) {
-					sc->update_flags(
-						&ibox->box, seq, rec->uid,
-						flags, custom_flags,
-						MAIL_CUSTOM_FLAGS_COUNT,
-						sc_context);
+					sc->update_flags(&ibox->box, seq,
+							 rec->uid, &flags,
+							 sc_context);
 				}
 
                                 seq++;

Index: index-update-flags.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-update-flags.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- index-update-flags.c	15 Jun 2003 03:42:29 -0000	1.22
+++ index-update-flags.c	23 Jul 2003 01:44:16 -0000	1.23
@@ -5,97 +5,54 @@
 #include "index-messageset.h"
 #include "mail-custom-flags.h"
 
-static int update_messageset(struct messageset_context *ctx,
-			     struct index_mailbox *ibox, enum mail_flags flags,
-			     enum modify_type modify_type, int notify)
-{
-	struct mail_storage *storage;
-	const struct messageset_mail *mail;
-	const char **custom_flags;
-	enum mail_flags new_flags;
-
-	storage = ibox->box.storage;
-	custom_flags = mail_custom_flags_list_get(ibox->index->custom_flags);
-
-	while ((mail = index_messageset_next(ctx)) != NULL) {
-		switch (modify_type) {
-		case MODIFY_ADD:
-			new_flags = mail->rec->msg_flags | flags;
-			break;
-		case MODIFY_REMOVE:
-			new_flags = mail->rec->msg_flags & ~flags;
-			break;
-		case MODIFY_REPLACE:
-			new_flags = flags;
-			break;
-		default:
-			i_unreached();
-		}
-
-		if (!ibox->index->update_flags(ibox->index, mail->rec,
-					       mail->idx_seq, new_flags, FALSE))
-			return -1;
-
-		if (mail_custom_flags_has_changes(ibox->index->custom_flags)) {
-			storage->callbacks->new_custom_flags(&ibox->box,
-				custom_flags, MAIL_CUSTOM_FLAGS_COUNT,
-				storage->callback_context);
-		}
-
-		if (notify) {
-			if (mail->rec->uid >= ibox->index->first_recent_uid)
-				new_flags |= MAIL_RECENT;
-
-			storage->callbacks->update_flags(&ibox->box,
-				mail->client_seq, mail->rec->uid, new_flags,
-				custom_flags, MAIL_CUSTOM_FLAGS_COUNT,
-				storage->callback_context);
-		}
-	}
-
-	return 1;
-}
-
-int index_storage_update_flags(struct mailbox *box, const char *messageset,
-			       int uidset, const struct mail_full_flags *flags,
-			       enum modify_type modify_type, int notify,
-			       int *all_found)
+int index_storage_update_flags(struct mail *mail,
+			       const struct mail_full_flags *flags,
+			       enum modify_type modify_type)
 {
-	struct index_mailbox *ibox = (struct index_mailbox *) box;
-        struct messageset_context *ctx;
-	enum mail_flags mail_flags;
-	int ret, ret2;
+	struct index_mail *imail = (struct index_mail *) mail;
+	struct index_mailbox *ibox = imail->ibox;
+	struct mail_storage *storage = mail->box->storage;
+	enum mail_flags modify_flags, new_flags;
 
-	if (box->readonly) {
-		box->storage->callbacks->
+	if (mail->box->readonly) {
+		storage->callbacks->
 			notify_no(&ibox->box,
-				  "Mailbox is read-only, ignoring store",
-				  box->storage->callback_context);
+				  "Mailbox is read-only, ignoring flag changes",
+				  storage->callback_context);
 		return TRUE;
 	}
 
-	mail_flags = flags->flags;
-	if (!index_mailbox_fix_custom_flags(ibox, &mail_flags,
+	/* \Recent can't be changed */
+	modify_flags = flags->flags & ~MAIL_RECENT;
+
+	if (!index_mailbox_fix_custom_flags(ibox, &modify_flags,
 					    flags->custom_flags,
 					    flags->custom_flags_count))
 		return FALSE;
 
-	if (!index_storage_lock(ibox, MAIL_LOCK_EXCLUSIVE))
-		return FALSE;
+	switch (modify_type) {
+	case MODIFY_ADD:
+		new_flags = imail->data.rec->msg_flags | modify_flags;
+		break;
+	case MODIFY_REMOVE:
+		new_flags = imail->data.rec->msg_flags & ~modify_flags;
+		break;
+	case MODIFY_REPLACE:
+		new_flags = modify_flags;
+		break;
+	default:
+		i_unreached();
+	}
 
-	if (!index_storage_sync_and_lock(ibox, TRUE, TRUE, MAIL_LOCK_UNLOCK))
+	if (!ibox->index->update_flags(ibox->index, imail->data.rec,
+				       imail->data.idx_seq, new_flags, FALSE))
 		return FALSE;
 
-	mail_flags &= ~MAIL_RECENT; /* \Recent can't be changed */
-
-	ctx = index_messageset_init(ibox, messageset, uidset, TRUE);
-	ret = update_messageset(ctx, ibox, mail_flags, modify_type, notify);
-	ret2 = index_messageset_deinit(ctx);
-
-	if (!index_storage_lock(ibox, MAIL_LOCK_UNLOCK))
-		return FALSE;
+	if (mail_custom_flags_has_changes(ibox->index->custom_flags)) {
+		storage->callbacks->new_custom_flags(&ibox->box,
+			mail_custom_flags_list_get(ibox->index->custom_flags),
+			MAIL_CUSTOM_FLAGS_COUNT, storage->callback_context);
+	}
 
-	if (all_found != NULL)
-		*all_found = ret2 > 0;
-	return ret >= 0 && ret2 >= 0;
+	return TRUE;
 }



More information about the dovecot-cvs mailing list