struct mail_cache_record *cache_rec, *next;
const struct mail_index_record *rec;
struct mail_index_map *map;
- uint32_t write_offset, update_offset;
+ uint32_t messages_count, write_offset, update_offset;
const void *buf;
size_t size, buf_size;
int ret;
size = sizeof(*cache_rec) + buf_size;
ctx->cache_rec.size = uint32_to_nbo(size);
- // FIXME: check cache_offset in transaction
- ret = mail_index_lookup_full(ctx->view->view, ctx->prev_seq,
- &map, &rec);
+ 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;
+ }
if (ret < 0)
return -1;
mail_index_transaction_free(t);
}
+static struct mail_index_record *
+mail_index_lookup_append(struct mail_index_transaction *t, uint32_t seq)
+{
+ size_t pos;
+
+ i_assert(seq >= t->first_new_seq && seq <= t->last_new_seq);
+
+ pos = (seq - t->first_new_seq) * t->view->index->record_size;
+ return buffer_get_space_unsafe(t->appends, pos,
+ 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)
{
rec->uid = uid;
}
-static struct mail_index_record *
-mail_index_lookup_append_rec(struct mail_index_transaction *t, uint32_t seq)
-{
- size_t pos;
-
- i_assert(seq >= t->first_new_seq && seq <= t->last_new_seq);
-
- pos = (seq - t->first_new_seq) * t->view->index->record_size;
- return buffer_get_space_unsafe(t->appends, pos,
- t->view->index->record_size);
-}
-
void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq)
{
struct mail_transaction_expunge exp, *data;
if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
/* just appended message, modify it directly */
- rec = mail_index_lookup_append_rec(t, seq);
+ rec = mail_index_lookup_append(t, seq);
mail_index_record_modify_flags(rec, modify_type,
flags, keywords);
return;
if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
/* just appended message, modify it directly */
- rec = mail_index_lookup_append_rec(t, seq);
+ rec = mail_index_lookup_append(t, seq);
rec->cache_offset = offset;
} else {
mail_index_update_seq_buffer(&t->cache_updates, seq,
if (t->first_new_seq != 0 && seq >= t->first_new_seq) {
/* just appended message, modify it directly */
/* FIXME: do data_id mapping conversion */
- rec = mail_index_lookup_append_rec(t, seq);
+ rec = mail_index_lookup_append(t, seq);
memcpy(PTR_OFFSET(rec, index->extra_records[data_id].offset),
data, index->extra_records[data_id].size);
} else {
for (; size > 0; size--)
t->hdr_mask[offset++] = 1;
}
-
-const struct mail_index_record *
-mail_index_lookup_append(struct mail_index_transaction *t, uint32_t seq)
-{
- return mail_index_lookup_append_rec(t, seq);
-}
void mail_index_update_extra_rec(struct mail_index_transaction *t,
uint32_t seq, uint32_t data_id,
const void *data);
-/* Returns given appended message, with all updates that have been done
- to it since the append. */
-const struct mail_index_record *
-mail_index_lookup_append(struct mail_index_transaction *t, uint32_t seq);
+/* 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);