[dovecot-cvs] dovecot/src/lib-index Makefile.am, 1.17, 1.18 mail-cache-lookup.c, 1.4, 1.5 mail-cache-transaction.c, 1.5, 1.6 mail-index-transaction-private.h, 1.5, 1.6 mail-index-transaction-view.c, NONE, 1.1 mail-index-transaction.c, 1.13, 1.14 mail-index-view-private.h, 1.6, 1.7 mail-index-view.c, 1.16, 1.17 mail-index.h, 1.118, 1.119

cras at procontrol.fi cras at procontrol.fi
Tue Jun 22 10:36:36 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv17660/lib-index

Modified Files:
	Makefile.am mail-cache-lookup.c mail-cache-transaction.c 
	mail-index-transaction-private.h mail-index-transaction.c 
	mail-index-view-private.h mail-index-view.c mail-index.h 
Added Files:
	mail-index-transaction-view.c 
Log Message:
Added mail_index_transaction_get_updated_view() which can be used to access
uncommitted messages.



Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/Makefile.am,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- Makefile.am	1 May 2004 16:30:58 -0000	1.17
+++ Makefile.am	22 Jun 2004 07:36:33 -0000	1.18
@@ -12,6 +12,7 @@
         mail-index-fsck.c \
         mail-index-lock.c \
         mail-index-transaction.c \
+        mail-index-transaction-view.c \
         mail-index-sync.c \
         mail-index-sync-update.c \
         mail-index-view.c \

Index: mail-cache-lookup.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache-lookup.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mail-cache-lookup.c	21 Jun 2004 14:44:47 -0000	1.4
+++ mail-cache-lookup.c	22 Jun 2004 07:36:33 -0000	1.5
@@ -175,11 +175,6 @@
 	if (view->cache->disabled)
 		return NULL;
 
-	if (seq > mail_index_view_get_message_count(view->view)) {
-		/* it's being appended in some transaction */
-		return NULL;
-	}
-
 	if (mail_index_lookup_full(view->view, seq, &map, &rec) < 0)
 		return NULL;
 

Index: mail-cache-transaction.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache-transaction.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mail-cache-transaction.c	21 Jun 2004 14:44:47 -0000	1.5
+++ mail-cache-transaction.c	22 Jun 2004 07:36:33 -0000	1.6
@@ -220,7 +220,7 @@
 	struct mail_cache_record *cache_rec, *next;
 	const struct mail_index_record *rec;
 	struct mail_index_map *map;
-	uint32_t messages_count, write_offset, update_offset;
+	uint32_t write_offset, update_offset;
 	const void *buf;
 	size_t size, buf_size;
 	int ret;
@@ -230,15 +230,8 @@
 	size = sizeof(*cache_rec) + buf_size;
 	ctx->cache_rec.size = uint32_to_nbo(size);
 
-        messages_count = mail_index_view_get_message_count(ctx->view->view);
-	if (ctx->prev_seq <= messages_count) {
-		ret = mail_index_lookup_full(ctx->view->view, ctx->prev_seq,
-					     &map, &rec);
-	} else {
-		ret = mail_index_transaction_lookup(ctx->trans,
-						    ctx->prev_seq, &rec);
-		map = cache->index->map;
-	}
+	ret = mail_index_lookup_full(ctx->view->view, ctx->prev_seq,
+				     &map, &rec);
 	if (ret < 0)
 		return -1;
 

Index: mail-index-transaction-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-transaction-private.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mail-index-transaction-private.h	20 Jun 2004 09:13:14 -0000	1.5
+++ mail-index-transaction-private.h	22 Jun 2004 07:36:33 -0000	1.6
@@ -1,8 +1,10 @@
 #ifndef __MAIL_INDEX_TRANSACTION_PRIVATE_H
 #define __MAIL_INDEX_TRANSACTION_PRIVATE_H
 
+#include "mail-transaction-log.h"
+
 struct mail_index_transaction {
-	struct mail_index_view *view;
+	struct mail_index_view *view, *updated_view;
 
         buffer_t *appends;
 	uint32_t first_new_seq, last_new_seq;
@@ -24,4 +26,7 @@
 	unsigned int hdr_changed:1;
 };
 
+struct mail_index_record *
+mail_index_transaction_lookup(struct mail_index_transaction *t, uint32_t seq);
+
 #endif

--- NEW FILE: mail-index-transaction-view.c ---
/* Copyright (C) 2004 Timo Sirainen */

#include "lib.h"
#include "buffer.h"
#include "mail-index-private.h"
#include "mail-index-view-private.h"
#include "mail-index-transaction-private.h"

struct mail_index_view_transaction {
	struct mail_index_view view;
	struct mail_index_view_methods *parent;
	struct mail_index_transaction *t;
};

static void _tview_close(struct mail_index_view *view)
{
	struct mail_index_view_transaction *tview =
		(struct mail_index_view_transaction *)view;

	tview->t->updated_view = NULL;

	return tview->parent->close(view);
}

static uint32_t _tview_get_message_count(struct mail_index_view *view)
{
	struct mail_index_view_transaction *tview =
                (struct mail_index_view_transaction *)view;

	return view->messages_count +
		(tview->t->last_new_seq == 0 ? 0 :
		 tview->t->last_new_seq - tview->t->first_new_seq);
}

static int _tview_get_header(struct mail_index_view *view,
			     const struct mail_index_header **hdr_r)
{
	struct mail_index_view_transaction *tview =
                (struct mail_index_view_transaction *)view;

	if (tview->parent->get_header(view, hdr_r) < 0)
		return -1;

	if ((*hdr_r)->messages_count != view->messages_count) {
		/* messages_count differs, use a modified copy.
		   FIXME: same problems as with _view_get_header().. */
		view->tmp_hdr_copy = **hdr_r;
		view->tmp_hdr_copy.messages_count = view->messages_count;
		*hdr_r = &view->tmp_hdr_copy;
	}
	return 0;
}

static int _tview_lookup_full(struct mail_index_view *view, uint32_t seq,
			      struct mail_index_map **map_r,
			      const struct mail_index_record **rec_r)
{
	struct mail_index_view_transaction *tview =
                (struct mail_index_view_transaction *)view;

	if (seq >= tview->t->first_new_seq) {
		/* FIXME: is this right to return index map..?
		   it's not there yet. */
		*map_r = view->index->map;
		*rec_r = mail_index_transaction_lookup(tview->t, seq);
		return 1;
	} else {
		return tview->parent->lookup_full(view, seq, map_r, rec_r);
	}
}

static int _tview_lookup_uid(struct mail_index_view *view, uint32_t seq,
			     uint32_t *uid_r)
{
	struct mail_index_view_transaction *tview =
		(struct mail_index_view_transaction *)view;

	if (seq >= tview->t->first_new_seq) {
		*uid_r = mail_index_transaction_lookup(tview->t, seq)->uid;
		return 0;
	} else {
		return tview->parent->lookup_uid(view, seq, uid_r);
	}
}

static int _tview_lookup_uid_range(struct mail_index_view *view,
				   uint32_t first_uid, uint32_t last_uid,
				   uint32_t *first_seq_r, uint32_t *last_seq_r)
{
	struct mail_index_view_transaction *tview =
		(struct mail_index_view_transaction *)view;

	if (tview->parent->lookup_uid_range(view, first_uid, last_uid,
					    first_seq_r, last_seq_r) < 0)
		return -1;

	/* FIXME: we don't need this function yet.. new UIDs might be 0 as
	   well.. */

	if (*first_seq_r == 0) {
		/* nothing found, either doesn't exist or it's completely
		   newly appended. */
	} else if (*last_seq_r + 1 == tview->t->first_new_seq) {
		/* last_seq_r may be growed from transactions */
	}

	return 0;
}

static int _tview_lookup_first(struct mail_index_view *view,
			       enum mail_flags flags, uint8_t flags_mask,
			       uint32_t *seq_r)
{
	struct mail_index_view_transaction *tview =
		(struct mail_index_view_transaction *)view;
	const struct mail_index_record *rec;
	uint32_t seq, message_count;

	if (tview->parent->lookup_first(view, flags, flags_mask, seq_r) < 0)
		return -1;

	if (*seq_r != 0)
		return 0;

	rec = buffer_get_data(tview->t->appends, NULL);
	seq = tview->t->first_new_seq;
	message_count = tview->t->last_new_seq;
	for (; seq <= message_count; seq++) {
		if ((rec->flags & flags_mask) == (uint8_t)flags) {
			*seq_r = seq;
			break;
		}
		rec = CONST_PTR_OFFSET(rec, view->index->record_size);
	}

	return 0;
}

static struct mail_index_view_methods view_methods = {
	_tview_close,
        _tview_get_message_count,
	_tview_get_header,
	_tview_lookup_full,
	_tview_lookup_uid,
	_tview_lookup_uid_range,
	_tview_lookup_first
};

struct mail_index_view *
mail_index_transaction_get_updated_view(struct mail_index_transaction *t)
{
	struct mail_index_view_transaction *tview;

	if (t->updated_view == NULL) {
		tview = i_new(struct mail_index_view_transaction, 1);
		mail_index_view_clone(&tview->view, t->view);
		tview->view.methods = view_methods;
		tview->parent = &t->view->methods;
		tview->t = t;

		t->updated_view = &tview->view;
	}

	return t->updated_view;
}

Index: mail-index-transaction.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-transaction.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- mail-index-transaction.c	21 Jun 2004 14:44:47 -0000	1.13
+++ mail-index-transaction.c	22 Jun 2004 07:36:33 -0000	1.14
@@ -25,6 +25,7 @@
 	t = i_new(struct mail_index_transaction, 1);
 	t->view = view;
 	t->hide_transaction = hide;
+	t->first_new_seq = mail_index_view_get_message_count(t->view)+1;
 	return t;
 }
 
@@ -47,6 +48,8 @@
 		buffer_free(t->updates);
 	if (t->cache_updates != NULL)
 		buffer_free(t->cache_updates);
+	if (t->updated_view != NULL)
+		mail_index_view_close(t->updated_view);
 	i_free(t);
 }
 
@@ -136,8 +139,8 @@
         mail_index_transaction_free(t);
 }
 
-static struct mail_index_record *
-mail_index_lookup_append(struct mail_index_transaction *t, uint32_t seq)
+struct mail_index_record *
+mail_index_transaction_lookup(struct mail_index_transaction *t, uint32_t seq)
 {
 	size_t pos;
 
@@ -148,18 +151,6 @@
 				       t->view->index->record_size);
 }
 
-int mail_index_transaction_lookup(struct mail_index_transaction *t,
-				  uint32_t seq,
-				  const struct mail_index_record **rec_r)
-{
-	if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
-		*rec_r = mail_index_lookup_append(t, seq);
-		return 1;
-	} else {
-		return mail_index_lookup(t->view, seq, rec_r);
-	}
-}
-
 void mail_index_append(struct mail_index_transaction *t, uint32_t uid,
 		       uint32_t *seq_r)
 {
@@ -174,10 +165,8 @@
 	   so let it generate it */
 	if (t->last_new_seq != 0)
 		*seq_r = ++t->last_new_seq;
-	else {
-		*seq_r = t->first_new_seq = t->last_new_seq =
-			mail_index_view_get_message_count(t->view)+1;
-	}
+	else
+		*seq_r = t->last_new_seq = t->first_new_seq;
 
 	rec = buffer_append_space_unsafe(t->appends,
 					 t->view->index->record_size);
@@ -313,9 +302,9 @@
 {
 	struct mail_index_record *rec;
 
-	if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
+	if (seq >= t->first_new_seq) {
 		/* just appended message, modify it directly */
-                rec = mail_index_lookup_append(t, seq);
+                rec = mail_index_transaction_lookup(t, seq);
 		mail_index_record_modify_flags(rec, modify_type,
 					       flags, keywords);
 		return;
@@ -497,9 +486,9 @@
 {
 	struct mail_index_record *rec;
 
-	if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
+	if (seq >= t->first_new_seq) {
 		/* just appended message, modify it directly */
-		rec = mail_index_lookup_append(t, seq);
+		rec = mail_index_transaction_lookup(t, seq);
 		rec->cache_offset = offset;
 	} else {
 		mail_index_update_seq_buffer(&t->cache_updates, seq,
@@ -516,10 +505,10 @@
 
 	i_assert(data_id < index->extra_records_count);
 
-	if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
+	if (seq >= t->first_new_seq) {
 		/* just appended message, modify it directly */
 		/* FIXME: do data_id mapping conversion */
-		rec = mail_index_lookup_append(t, seq);
+		rec = mail_index_transaction_lookup(t, seq);
 		memcpy(PTR_OFFSET(rec, index->extra_records[data_id].offset),
 		       data, index->extra_records[data_id].size);
 	} else {

Index: mail-index-view-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-view-private.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mail-index-view-private.h	24 May 2004 01:50:16 -0000	1.6
+++ mail-index-view-private.h	22 Jun 2004 07:36:33 -0000	1.7
@@ -3,7 +3,25 @@
 
 #include "mail-index-private.h"
 
+struct mail_index_view_methods {
+	void (*close)(struct mail_index_view *view);
+	uint32_t (*get_message_count)(struct mail_index_view *view);
+	int (*get_header)(struct mail_index_view *view,
+			  const struct mail_index_header **hdr_r);
+	int (*lookup_full)(struct mail_index_view *view, uint32_t seq,
+			   struct mail_index_map **map_r,
+			   const struct mail_index_record **rec_r);
+	int (*lookup_uid)(struct mail_index_view *view, uint32_t seq,
+			  uint32_t *uid_r);
+	int (*lookup_uid_range)(struct mail_index_view *view,
+				uint32_t first_uid, uint32_t last_uid,
+				uint32_t *first_seq_r, uint32_t *last_seq_r);
+	int (*lookup_first)(struct mail_index_view *view, enum mail_flags flags,
+			    uint8_t flags_mask, uint32_t *seq_r);
+};
+
 struct mail_index_view {
+	struct mail_index_view_methods methods;
 	struct mail_index *index;
         struct mail_transaction_log_view *log_view;
 
@@ -27,6 +45,8 @@
 	unsigned int map_protected:1;
 };
 
+void mail_index_view_clone(struct mail_index_view *dest,
+			   const struct mail_index_view *src);
 int mail_index_view_lock(struct mail_index_view *view);
 int mail_index_view_lock_head(struct mail_index_view *view, int update_index);
 void mail_index_view_add_synced_transaction(struct mail_index_view *view,

Index: mail-index-view.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- mail-index-view.c	20 Jun 2004 12:23:27 -0000	1.16
+++ mail-index-view.c	22 Jun 2004 07:36:33 -0000	1.17
@@ -6,25 +6,24 @@
 #include "mail-index-view-private.h"
 #include "mail-transaction-log.h"
 
-struct mail_index_view *mail_index_view_open(struct mail_index *index)
+void mail_index_view_clone(struct mail_index_view *dest,
+			   const struct mail_index_view *src)
 {
-	struct mail_index_view *view;
-
-	view = i_new(struct mail_index_view, 1);
-	view->index = index;
-	view->log_view = mail_transaction_log_view_open(index->log);
+	memset(dest, 0, sizeof(dest));
+	dest->methods = src->methods;
+	dest->index = src->index;
+	dest->log_view = mail_transaction_log_view_open(src->index->log);
 
-	view->indexid = index->indexid;
-	view->map = index->map;
-	view->map->refcount++;
-	view->messages_count = view->map->records_count;
+	dest->indexid = src->indexid;
+	dest->map = src->map;
+	dest->map->refcount++;
+	dest->messages_count = src->messages_count;
 
-	view->log_file_seq = view->map->log_file_seq;
-	view->log_file_offset = view->map->log_file_offset;
-	return view;
+	dest->log_file_seq = src->log_file_seq;
+	dest->log_file_offset = src->log_file_offset;
 }
 
-void mail_index_view_close(struct mail_index_view *view)
+static void _view_close(struct mail_index_view *view)
 {
 	mail_index_view_unlock(view);
 	mail_transaction_log_view_close(view->log_view);
@@ -117,11 +116,6 @@
 	}
 }
 
-uint32_t mail_index_view_get_message_count(struct mail_index_view *view)
-{
-	return view->messages_count;
-}
-
 int mail_index_view_is_inconsistent(struct mail_index_view *view)
 {
 	if (view->index->indexid != view->indexid)
@@ -146,8 +140,13 @@
 	view->transactions--;
 }
 
-int mail_index_get_header(struct mail_index_view *view,
-			  const struct mail_index_header **hdr_r)
+static uint32_t _view_get_message_count(struct mail_index_view *view)
+{
+	return view->messages_count;
+}
+
+static int _view_get_header(struct mail_index_view *view,
+			    const struct mail_index_header **hdr_r)
 {
 	if (mail_index_view_lock(view) < 0)
 		return -1;
@@ -155,7 +154,10 @@
 	if (view->map->hdr->messages_count == view->messages_count)
 		*hdr_r = view->map->hdr;
 	else {
-		/* messages_count differs, use a modified copy */
+		/* messages_count differs, use a modified copy.
+		   FIXME: so might seen_messages_count, etc. and they're
+		   more difficult to fix. maybe grab a copy of the header
+		   when opening the view initially?.. */
 		view->tmp_hdr_copy = *view->map->hdr;
 		view->tmp_hdr_copy.messages_count = view->messages_count;
 		*hdr_r = &view->tmp_hdr_copy;
@@ -163,16 +165,15 @@
 	return 0;
 }
 
-int mail_index_lookup_full(struct mail_index_view *view, uint32_t seq,
-			   struct mail_index_map **map_r,
-			   const struct mail_index_record **rec_r)
+static int _view_lookup_full(struct mail_index_view *view, uint32_t seq,
+			     struct mail_index_map **map_r,
+			     const struct mail_index_record **rec_r)
 {
 	struct mail_index_map *map;
 	const struct mail_index_record *rec, *n_rec;
 	uint32_t uid;
 
-	i_assert(seq > 0);
-	i_assert(seq <= view->messages_count);
+	i_assert(seq > 0 && seq <= mail_index_view_get_message_count(view));
 
 	if (mail_index_view_lock(view) < 0)
 		return -1;
@@ -216,19 +217,10 @@
 	}
 }
 
-int mail_index_lookup(struct mail_index_view *view, uint32_t seq,
-		      const struct mail_index_record **rec_r)
-{
-	struct mail_index_map *map;
-
-	return mail_index_lookup_full(view, seq, &map, rec_r);
-}
-
-int mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
-			  uint32_t *uid_r)
+static int _view_lookup_uid(struct mail_index_view *view, uint32_t seq,
+			    uint32_t *uid_r)
 {
-	i_assert(seq > 0);
-	i_assert(seq <= view->messages_count);
+	i_assert(seq > 0 && seq <= mail_index_view_get_message_count(view));
 
 	if (mail_index_view_lock(view) < 0)
 		return -1;
@@ -237,29 +229,6 @@
 	return 0;
 }
 
-int mail_index_lookup_extra(struct mail_index_view *view, uint32_t seq,
-			    uint32_t data_id, const void **data_r)
-{
-	const struct mail_index_record *rec;
-	struct mail_index_map *map;
-	uint32_t offset;
-	int ret;
-
-	if ((ret = mail_index_lookup_full(view, seq, &map, &rec)) < 0)
-		return -1;
-
-	if (rec == NULL) {
-		*data_r = NULL;
-		return ret;
-	}
-
-	/* FIXME: do data_id mapping conversion */
-
-	offset = view->index->extra_records[data_id].offset;
-	*data_r = CONST_PTR_OFFSET(rec, offset);
-	return ret;
-}
-
 static uint32_t mail_index_bsearch_uid(struct mail_index_view *view,
 				       uint32_t uid, uint32_t *left_idx_p,
 				       int nearest_side)
@@ -267,6 +236,8 @@
 	const struct mail_index_record *rec_base, *rec;
 	uint32_t idx, left_idx, right_idx, record_size;
 
+	i_assert(view->messages_count <= view->map->records_count);
+
 	rec_base = view->map->records;
 	record_size = view->index->record_size;
 
@@ -306,9 +277,9 @@
 	return idx+1;
 }
 
-int mail_index_lookup_uid_range(struct mail_index_view *view,
-				uint32_t first_uid, uint32_t last_uid,
-				uint32_t *first_seq_r, uint32_t *last_seq_r)
+static int _view_lookup_uid_range(struct mail_index_view *view,
+				  uint32_t first_uid, uint32_t last_uid,
+				  uint32_t *first_seq_r, uint32_t *last_seq_r)
 {
 	uint32_t left_idx;
 
@@ -347,8 +318,9 @@
 	return 0;
 }
 
-int mail_index_lookup_first(struct mail_index_view *view, enum mail_flags flags,
-			    uint8_t flags_mask, uint32_t *seq_r)
+static int _view_lookup_first(struct mail_index_view *view,
+			      enum mail_flags flags, uint8_t flags_mask,
+			      uint32_t *seq_r)
 {
 #define LOW_UPDATE(x) \
 	STMT_START { if ((x) > low_uid) low_uid = x; } STMT_END
@@ -378,7 +350,7 @@
 			return 0;
 	}
 
-	for (; seq <= view->messages_count; seq++, rec++) {
+	for (; seq <= view->messages_count; seq++) {
 		rec = MAIL_INDEX_MAP_IDX(view->index, view->map, seq-1);
 		if ((rec->flags & flags_mask) == (uint8_t)flags) {
 			*seq_r = seq;
@@ -388,3 +360,106 @@
 
 	return 0;
 }
+
+void mail_index_view_close(struct mail_index_view *view)
+{
+	view->methods.close(view);
+}
+
+uint32_t mail_index_view_get_message_count(struct mail_index_view *view)
+{
+	return view->messages_count;
+}
+
+int mail_index_get_header(struct mail_index_view *view,
+			  const struct mail_index_header **hdr_r)
+{
+	return view->methods.get_header(view, hdr_r);
+}
+
+int mail_index_lookup(struct mail_index_view *view, uint32_t seq,
+		      const struct mail_index_record **rec_r)
+{
+	struct mail_index_map *map;
+
+	return mail_index_lookup_full(view, seq, &map, rec_r);
+}
+
+int mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
+			  uint32_t *uid_r)
+{
+	return view->methods.lookup_uid(view, seq, uid_r);
+}
+
+int mail_index_lookup_extra(struct mail_index_view *view, uint32_t seq,
+			    uint32_t data_id, const void **data_r)
+{
+	const struct mail_index_record *rec;
+	struct mail_index_map *map;
+	uint32_t offset;
+	int ret;
+
+	if ((ret = mail_index_lookup_full(view, seq, &map, &rec)) < 0)
+		return -1;
+
+	if (rec == NULL) {
+		*data_r = NULL;
+		return ret;
+	}
+
+	/* FIXME: do data_id mapping conversion */
+
+	offset = view->index->extra_records[data_id].offset;
+	*data_r = CONST_PTR_OFFSET(rec, offset);
+	return ret;
+}
+
+int mail_index_lookup_uid_range(struct mail_index_view *view,
+				uint32_t first_uid, uint32_t last_uid,
+				uint32_t *first_seq_r, uint32_t *last_seq_r)
+{
+	return view->methods.lookup_uid_range(view, first_uid, last_uid,
+					      first_seq_r, last_seq_r);
+}
+
+int mail_index_lookup_first(struct mail_index_view *view, enum mail_flags flags,
+			    uint8_t flags_mask, uint32_t *seq_r)
+{
+	return view->methods.lookup_first(view, flags, flags_mask, seq_r);
+}
+
+int mail_index_lookup_full(struct mail_index_view *view, uint32_t seq,
+			   struct mail_index_map **map_r,
+			   const struct mail_index_record **rec_r)
+{
+	return view->methods.lookup_full(view, seq, map_r, rec_r);
+}
+
+static struct mail_index_view_methods view_methods = {
+	_view_close,
+	_view_get_message_count,
+	_view_get_header,
+	_view_lookup_full,
+	_view_lookup_uid,
+	_view_lookup_uid_range,
+	_view_lookup_first
+};
+
+struct mail_index_view *mail_index_view_open(struct mail_index *index)
+{
+	struct mail_index_view *view;
+
+	view = i_new(struct mail_index_view, 1);
+	view->methods = view_methods;
+	view->index = index;
+	view->log_view = mail_transaction_log_view_open(index->log);
+
+	view->indexid = index->indexid;
+	view->map = index->map;
+	view->map->refcount++;
+	view->messages_count = view->map->records_count;
+
+	view->log_file_seq = view->map->log_file_seq;
+	view->log_file_offset = view->map->log_file_offset;
+	return view;
+}

Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- mail-index.h	21 Jun 2004 14:44:47 -0000	1.118
+++ mail-index.h	22 Jun 2004 07:36:33 -0000	1.119
@@ -178,6 +178,12 @@
 				  uoff_t *log_file_offset_r);
 void mail_index_transaction_rollback(struct mail_index_transaction *t);
 
+/* Returns a view to transaction. Currently this differs from normal view only
+   in that it contains newly appended messages in transaction. The view is
+   destroyed when the transaction is destroyed. */
+struct mail_index_view *
+mail_index_transaction_get_updated_view(struct mail_index_transaction *t);
+
 /* Begin synchronizing mailbox with index file. This call locks the index
    exclusively against other modifications. Returns 1 if ok, -1 if error.
 
@@ -278,11 +284,6 @@
 void mail_index_update_extra_rec(struct mail_index_transaction *t,
 				 uint32_t seq, uint32_t data_id,
 				 const void *data);
-/* Like mail_index_lookup(), but if seq > view's message count, it's referring
-   to message appended with given transaction. */
-int mail_index_transaction_lookup(struct mail_index_transaction *t,
-				  uint32_t seq,
-				  const struct mail_index_record **rec_r);
 
 /* Returns the last error code. */
 enum mail_index_error mail_index_get_last_error(struct mail_index *index);



More information about the dovecot-cvs mailing list