comparison src/lib-index/mail-index-transaction-view.c @ 9234:ae3e0ff64c94 HEAD

Transaction view: Fixed getting extension data from messages whose flags had changed.
author Timo Sirainen <tss@iki.fi>
date Tue, 21 Jul 2009 15:01:05 -0400
parents b9faf4db2a9f
children 22b45d08cd4e
comparison
equal deleted inserted replaced
9233:518963e8a20d 9234:ae3e0ff64c94
17 struct mail_index_header hdr; 17 struct mail_index_header hdr;
18 18
19 buffer_t *lookup_return_data; 19 buffer_t *lookup_return_data;
20 uint32_t lookup_prev_seq; 20 uint32_t lookup_prev_seq;
21 21
22 unsigned int record_size;
22 unsigned int recs_count; 23 unsigned int recs_count;
23 struct mail_index_record *recs; 24 void *recs;
24 }; 25 };
25 26
26 static void tview_close(struct mail_index_view *view) 27 static void tview_close(struct mail_index_view *view)
27 { 28 {
28 struct mail_index_view_transaction *tview = 29 struct mail_index_view_transaction *tview =
69 return hdr; 70 return hdr;
70 } 71 }
71 72
72 static const struct mail_index_record * 73 static const struct mail_index_record *
73 tview_apply_flag_updates(struct mail_index_view_transaction *tview, 74 tview_apply_flag_updates(struct mail_index_view_transaction *tview,
75 struct mail_index_map *map,
74 const struct mail_index_record *rec, uint32_t seq) 76 const struct mail_index_record *rec, uint32_t seq)
75 { 77 {
76 struct mail_index_transaction *t = tview->t; 78 struct mail_index_transaction *t = tview->t;
77 const struct mail_transaction_flag_update *updates; 79 const struct mail_transaction_flag_update *updates;
80 struct mail_index_record *trec;
78 unsigned int idx, count; 81 unsigned int idx, count;
79 82
80 /* see if there are any flag updates */ 83 /* see if there are any flag updates */
81 if (seq < t->min_flagupdate_seq || seq > t->max_flagupdate_seq || 84 if (seq < t->min_flagupdate_seq || seq > t->max_flagupdate_seq ||
82 !array_is_created(&t->updates)) 85 !array_is_created(&t->updates))
91 we want to be able to handle multiple mail_index_lookup() calls 94 we want to be able to handle multiple mail_index_lookup() calls
92 without the second one overriding the first one's data, we'll 95 without the second one overriding the first one's data, we'll
93 create a records array and return data from there */ 96 create a records array and return data from there */
94 if (tview->recs == NULL) { 97 if (tview->recs == NULL) {
95 tview->recs_count = t->first_new_seq; 98 tview->recs_count = t->first_new_seq;
96 tview->recs = i_new(struct mail_index_record, 99 tview->record_size = I_MAX(map->hdr.record_size,
97 tview->recs_count); 100 tview->view.map->hdr.record_size);
101 tview->recs = i_malloc(tview->record_size *
102 tview->recs_count);
98 } 103 }
99 i_assert(tview->recs_count == t->first_new_seq); 104 i_assert(tview->recs_count == t->first_new_seq);
100 i_assert(seq > 0 && seq <= tview->recs_count); 105 i_assert(seq > 0 && seq <= tview->recs_count);
101 106 i_assert(map->hdr.record_size <= tview->record_size);
102 tview->recs[seq-1] = *rec; 107
103 tview->recs[seq-1].flags |= updates[idx].add_flags; 108 trec = PTR_OFFSET(tview->recs, (seq-1) * tview->record_size);
104 tview->recs[seq-1].flags &= ~updates[idx].remove_flags; 109 memcpy(trec, rec, map->hdr.record_size);
105 return &tview->recs[seq-1]; 110 trec->flags |= updates[idx].add_flags;
111 trec->flags &= ~updates[idx].remove_flags;
112 return trec;
106 } 113 }
107 114
108 static const struct mail_index_record * 115 static const struct mail_index_record *
109 tview_lookup_full(struct mail_index_view *view, uint32_t seq, 116 tview_lookup_full(struct mail_index_view *view, uint32_t seq,
110 struct mail_index_map **map_r, bool *expunged_r) 117 struct mail_index_map **map_r, bool *expunged_r)
120 *expunged_r = FALSE; 127 *expunged_r = FALSE;
121 return mail_index_transaction_lookup(tview->t, seq); 128 return mail_index_transaction_lookup(tview->t, seq);
122 } 129 }
123 130
124 rec = tview->super->lookup_full(view, seq, map_r, expunged_r); 131 rec = tview->super->lookup_full(view, seq, map_r, expunged_r);
125 rec = tview_apply_flag_updates(tview, rec, seq); 132 rec = tview_apply_flag_updates(tview, *map_r, rec, seq);
126 133
127 if (array_is_created(&tview->t->expunges) && 134 if (array_is_created(&tview->t->expunges) &&
128 seq_range_exists(&tview->t->expunges, seq)) 135 seq_range_exists(&tview->t->expunges, seq))
129 *expunged_r = TRUE; 136 *expunged_r = TRUE;
130 return rec; 137 return rec;