annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 8549
diff changeset
1 /* Copyright (c) 2004-2009 Dovecot authors, see the included COPYING file */
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
3470
346a494c2feb Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents: 3195
diff changeset
4 #include "array.h"
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "buffer.h"
4333
8bfdd3928097 mail_index_lookup() and mail_index_lookup_full() returns now 0 if the mail has been expunged within the transaction.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
6 #include "seq-range-array.h"
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "mail-index-private.h"
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "mail-index-view-private.h"
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "mail-index-transaction-private.h"
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 struct mail_index_view_transaction {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 struct mail_index_view view;
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
13 struct mail_index_view_vfuncs *super;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 struct mail_index_transaction *t;
4528
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
15
6262
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
16 struct mail_index_map *lookup_map;
4528
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
17 struct mail_index_header hdr;
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
18
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
19 buffer_t *lookup_return_data;
8548
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
20 uint32_t lookup_prev_seq;
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
21
9234
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
22 unsigned int record_size;
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
23 unsigned int recs_count;
9234
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
24 void *recs;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 };
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
27 static void tview_close(struct mail_index_view *view)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 struct mail_index_view_transaction *tview =
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 (struct mail_index_view_transaction *)view;
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
31 struct mail_index_transaction *t = tview->t;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32
6262
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
33 if (tview->lookup_map != NULL)
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
34 mail_index_unmap(&tview->lookup_map);
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
35 if (tview->lookup_return_data != NULL)
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
36 buffer_free(&tview->lookup_return_data);
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
37 i_free(tview->recs);
6262
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
38
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
39 tview->super->close(view);
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
40 mail_index_transaction_unref(&t);
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
43 static uint32_t tview_get_message_count(struct mail_index_view *view)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 struct mail_index_view_transaction *tview =
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 (struct mail_index_view_transaction *)view;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47
5855
fd6ff4d9cab1 Removed view->hdr. Use view->map->hdr directly.
Timo Sirainen <tss@iki.fi>
parents: 5228
diff changeset
48 return view->map->hdr.messages_count +
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 (tview->t->last_new_seq == 0 ? 0 :
8213
ffefb9074966 Transaction view: get_message_count() returned one too few when there were new messages.
Timo Sirainen <tss@iki.fi>
parents: 8199
diff changeset
50 tview->t->last_new_seq - tview->t->first_new_seq + 1);
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52
2892
62d53b49110d Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents: 2884
diff changeset
53 static const struct mail_index_header *
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
54 tview_get_header(struct mail_index_view *view)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 struct mail_index_view_transaction *tview =
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 (struct mail_index_view_transaction *)view;
4528
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
58 const struct mail_index_header *hdr;
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6036
diff changeset
59 uint32_t next_uid;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60
2884
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
61 /* FIXME: header counters may not be correct */
4528
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
62 hdr = tview->super->get_header(view);
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
63
6037
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6036
diff changeset
64 next_uid = mail_index_transaction_get_next_uid(tview->t);
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6036
diff changeset
65 if (next_uid != hdr->next_uid) {
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6036
diff changeset
66 tview->hdr = *hdr;
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6036
diff changeset
67 tview->hdr.next_uid = next_uid;
d911d943438e Recent flag handling rewrite. Still not perfect with maildir.
Timo Sirainen <tss@iki.fi>
parents: 6036
diff changeset
68 hdr = &tview->hdr;
4528
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
69 }
4529
0ffb6fa11744 And fix for previous change..
Timo Sirainen <tss@iki.fi>
parents: 4528
diff changeset
70 return hdr;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
73 static const struct mail_index_record *
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
74 tview_apply_flag_updates(struct mail_index_view_transaction *tview,
9234
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
75 struct mail_index_map *map,
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
76 const struct mail_index_record *rec, uint32_t seq)
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
77 {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
78 struct mail_index_transaction *t = tview->t;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
79 const struct mail_transaction_flag_update *updates;
9234
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
80 struct mail_index_record *trec;
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
81 unsigned int idx, count;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
82
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
83 /* see if there are any flag updates */
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
84 if (seq < t->min_flagupdate_seq || seq > t->max_flagupdate_seq ||
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
85 !array_is_created(&t->updates))
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
86 return rec;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
87
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
88 updates = array_get(&t->updates, &count);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
89 idx = mail_index_transaction_get_flag_update_pos(t, 0, count, seq);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
90 if (seq < updates[idx].uid1 || seq > updates[idx].uid2)
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
91 return rec;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
92
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
93 /* yes, we have flag updates. since we can't modify rec directly and
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
94 we want to be able to handle multiple mail_index_lookup() calls
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
95 without the second one overriding the first one's data, we'll
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
96 create a records array and return data from there */
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
97 if (tview->recs == NULL) {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
98 tview->recs_count = t->first_new_seq;
9234
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
99 tview->record_size = I_MAX(map->hdr.record_size,
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
100 tview->view.map->hdr.record_size);
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
101 tview->recs = i_malloc(tview->record_size *
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
102 tview->recs_count);
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
103 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
104 i_assert(tview->recs_count == t->first_new_seq);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
105 i_assert(seq > 0 && seq <= tview->recs_count);
9234
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
106 i_assert(map->hdr.record_size <= tview->record_size);
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
107
9234
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
108 trec = PTR_OFFSET(tview->recs, (seq-1) * tview->record_size);
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
109 memcpy(trec, rec, map->hdr.record_size);
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
110 trec->flags |= updates[idx].add_flags;
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
111 trec->flags &= ~updates[idx].remove_flags;
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
112 return trec;
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
113 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
114
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
115 static const struct mail_index_record *
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
116 tview_lookup_full(struct mail_index_view *view, uint32_t seq,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
117 struct mail_index_map **map_r, bool *expunged_r)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 struct mail_index_view_transaction *tview =
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 (struct mail_index_view_transaction *)view;
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
121 const struct mail_index_record *rec;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 if (seq >= tview->t->first_new_seq) {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 /* FIXME: is this right to return index map..?
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 it's not there yet. */
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 *map_r = view->index->map;
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
127 *expunged_r = FALSE;
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
128 return mail_index_transaction_lookup(tview->t, seq);
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 }
4333
8bfdd3928097 mail_index_lookup() and mail_index_lookup_full() returns now 0 if the mail has been expunged within the transaction.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
130
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
131 rec = tview->super->lookup_full(view, seq, map_r, expunged_r);
9234
ae3e0ff64c94 Transaction view: Fixed getting extension data from messages whose flags had changed.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
132 rec = tview_apply_flag_updates(tview, *map_r, rec, seq);
4333
8bfdd3928097 mail_index_lookup() and mail_index_lookup_full() returns now 0 if the mail has been expunged within the transaction.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3879
diff changeset
133
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
134 if (array_is_created(&tview->t->expunges) &&
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
135 seq_range_exists(&tview->t->expunges, seq))
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
136 *expunged_r = TRUE;
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
137 return rec;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
140 static void
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
141 tview_lookup_uid(struct mail_index_view *view, uint32_t seq, uint32_t *uid_r)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 struct mail_index_view_transaction *tview =
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 (struct mail_index_view_transaction *)view;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145
6275
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6262
diff changeset
146 if (seq >= tview->t->first_new_seq)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 *uid_r = mail_index_transaction_lookup(tview->t, seq)->uid;
6275
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6262
diff changeset
148 else
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6262
diff changeset
149 tview->super->lookup_uid(view, seq, uid_r);
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151
6677
90bcf480312d Renamed mail_index_lookup_uid_range() to mail_index_lookup_seq_range(), made
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
152 static void tview_lookup_seq_range(struct mail_index_view *view,
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
153 uint32_t first_uid, uint32_t last_uid,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
154 uint32_t *first_seq_r, uint32_t *last_seq_r)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 struct mail_index_view_transaction *tview =
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 (struct mail_index_view_transaction *)view;
6036
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
158 const struct mail_index_record *rec;
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
159 uint32_t seq;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160
8214
76425554b4bc Transaction view: If index is reset, don't return old to-be-removed sequences.
Timo Sirainen <tss@iki.fi>
parents: 8213
diff changeset
161 if (!tview->t->reset) {
76425554b4bc Transaction view: If index is reset, don't return old to-be-removed sequences.
Timo Sirainen <tss@iki.fi>
parents: 8213
diff changeset
162 tview->super->lookup_seq_range(view, first_uid, last_uid,
76425554b4bc Transaction view: If index is reset, don't return old to-be-removed sequences.
Timo Sirainen <tss@iki.fi>
parents: 8213
diff changeset
163 first_seq_r, last_seq_r);
76425554b4bc Transaction view: If index is reset, don't return old to-be-removed sequences.
Timo Sirainen <tss@iki.fi>
parents: 8213
diff changeset
164 } else {
76425554b4bc Transaction view: If index is reset, don't return old to-be-removed sequences.
Timo Sirainen <tss@iki.fi>
parents: 8213
diff changeset
165 /* index is being reset. we never want to return old
76425554b4bc Transaction view: If index is reset, don't return old to-be-removed sequences.
Timo Sirainen <tss@iki.fi>
parents: 8213
diff changeset
166 sequences. */
76425554b4bc Transaction view: If index is reset, don't return old to-be-removed sequences.
Timo Sirainen <tss@iki.fi>
parents: 8213
diff changeset
167 *first_seq_r = *last_seq_r = 0;
76425554b4bc Transaction view: If index is reset, don't return old to-be-removed sequences.
Timo Sirainen <tss@iki.fi>
parents: 8213
diff changeset
168 }
6036
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
169 if (tview->t->last_new_seq == 0) {
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
170 /* no new messages, the results are final. */
6275
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6262
diff changeset
171 return;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173
6036
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
174 rec = mail_index_transaction_lookup(tview->t, tview->t->first_new_seq);
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
175 if (rec->uid == 0) {
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
176 /* new messages don't have UIDs */
6275
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6262
diff changeset
177 return;
6036
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
178 }
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
179 if (last_uid < rec->uid) {
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
180 /* all wanted messages were existing */
6275
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6262
diff changeset
181 return;
6036
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
182 }
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
183
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
184 /* at least some of the wanted messages are newly created */
7064
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
185 if (*first_seq_r == 0) {
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
186 seq = tview->t->first_new_seq;
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
187 for (; seq <= tview->t->last_new_seq; seq++) {
8115
8ac8713b1386 mail_index_lookup_seq*() could have returned wrong sequences with transaction views.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
188 rec = mail_index_transaction_lookup(tview->t, seq);
7064
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
189 if (first_uid <= rec->uid)
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
190 break;
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
191 }
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
192 if (seq > tview->t->last_new_seq) {
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
193 /* no messages in range */
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
194 return;
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
195 }
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
196 *first_seq_r = seq;
046d06f52aa6 mail_index_lookup_seq*() were broken for updated transaction view when
Timo Sirainen <tss@iki.fi>
parents: 6677
diff changeset
197 }
6036
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
198
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
199 seq = tview->t->last_new_seq;
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
200 for (; seq >= tview->t->first_new_seq; seq--) {
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
201 rec = mail_index_transaction_lookup(tview->t, seq);
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
202 if (rec->uid <= last_uid) {
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
203 *last_seq_r = seq;
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
204 break;
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
205 }
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
206 }
5d3a941444f1 mail_index_lookup_uid_range() works now correctly when searching for newly
Timo Sirainen <tss@iki.fi>
parents: 5855
diff changeset
207 i_assert(seq >= tview->t->first_new_seq);
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
209
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
210 static void tview_lookup_first(struct mail_index_view *view,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
211 enum mail_flags flags, uint8_t flags_mask,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
212 uint32_t *seq_r)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214 struct mail_index_view_transaction *tview =
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 (struct mail_index_view_transaction *)view;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 const struct mail_index_record *rec;
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
217 unsigned int append_count;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 uint32_t seq, message_count;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219
8215
c0888db40086 Transaction view: If index is reset, lookup_first() shouldn't return old sequences.
Timo Sirainen <tss@iki.fi>
parents: 8214
diff changeset
220 if (!tview->t->reset) {
c0888db40086 Transaction view: If index is reset, lookup_first() shouldn't return old sequences.
Timo Sirainen <tss@iki.fi>
parents: 8214
diff changeset
221 tview->super->lookup_first(view, flags, flags_mask, seq_r);
c0888db40086 Transaction view: If index is reset, lookup_first() shouldn't return old sequences.
Timo Sirainen <tss@iki.fi>
parents: 8214
diff changeset
222 if (*seq_r != 0)
c0888db40086 Transaction view: If index is reset, lookup_first() shouldn't return old sequences.
Timo Sirainen <tss@iki.fi>
parents: 8214
diff changeset
223 return;
c0888db40086 Transaction view: If index is reset, lookup_first() shouldn't return old sequences.
Timo Sirainen <tss@iki.fi>
parents: 8214
diff changeset
224 } else {
c0888db40086 Transaction view: If index is reset, lookup_first() shouldn't return old sequences.
Timo Sirainen <tss@iki.fi>
parents: 8214
diff changeset
225 *seq_r = 0;
c0888db40086 Transaction view: If index is reset, lookup_first() shouldn't return old sequences.
Timo Sirainen <tss@iki.fi>
parents: 8214
diff changeset
226 }
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
228 rec = array_get(&tview->t->appends, &append_count);
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 seq = tview->t->first_new_seq;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 message_count = tview->t->last_new_seq;
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
231 i_assert(append_count == message_count - seq + 1);
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
232
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
233 for (; seq <= message_count; seq++, rec++) {
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 if ((rec->flags & flags_mask) == (uint8_t)flags) {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 *seq_r = seq;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 break;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
241 static void keyword_index_add(ARRAY_TYPE(keyword_indexes) *keywords,
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
242 unsigned int idx)
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
243 {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
244 const unsigned int *indexes;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
245 unsigned int i, count;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
246
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
247 indexes = array_get(keywords, &count);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
248 for (i = 0; i < count; i++) {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
249 if (indexes[i] == idx)
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
250 return;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
251 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
252 array_append(keywords, &idx, 1);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
253 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
254
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
255 static void keyword_index_remove(ARRAY_TYPE(keyword_indexes) *keywords,
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
256 unsigned int idx)
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
257 {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
258 const unsigned int *indexes;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
259 unsigned int i, count;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
260
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
261 indexes = array_get(keywords, &count);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
262 for (i = 0; i < count; i++) {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
263 if (indexes[i] == idx) {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
264 array_delete(keywords, i, 1);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
265 break;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
266 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
267 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
268 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
269
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
270 static void tview_lookup_keywords(struct mail_index_view *view, uint32_t seq,
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
271 ARRAY_TYPE(keyword_indexes) *keyword_idx)
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
272 {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
273 struct mail_index_view_transaction *tview =
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
274 (struct mail_index_view_transaction *)view;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
275 struct mail_index_transaction *t = tview->t;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
276 const struct mail_index_transaction_keyword_update *updates;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
277 unsigned int i, count;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
278
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
279 tview->super->lookup_keywords(view, seq, keyword_idx);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
280
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
281 if (seq < t->min_flagupdate_seq || seq > t->max_flagupdate_seq) {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
282 /* no keyword updates for this sequence */
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
283 return;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
284 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
285
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
286 /* apply any keyword updates in this transaction */
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
287 if (array_is_created(&t->keyword_resets)) {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
288 if (seq_range_exists(&t->keyword_resets, seq))
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
289 array_clear(keyword_idx);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
290 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
291
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
292 if (array_is_created(&t->keyword_updates))
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
293 updates = array_get(&t->keyword_updates, &count);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
294 else {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
295 updates = NULL;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
296 count = 0;
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
297 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
298 for (i = 0; i < count; i++) {
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
299 if (array_is_created(&updates[i].add_seq) &&
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
300 seq_range_exists(&updates[i].add_seq, seq))
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
301 keyword_index_add(keyword_idx, i);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
302 else if (array_is_created(&updates[i].remove_seq) &&
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
303 seq_range_exists(&updates[i].remove_seq, seq))
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
304 keyword_index_remove(keyword_idx, i);
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
305 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
306 }
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
307
6262
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
308 static struct mail_index_map *
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
309 tview_get_lookup_map(struct mail_index_view_transaction *tview)
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
310 {
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
311 if (tview->lookup_map == NULL) {
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
312 tview->lookup_map =
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
313 mail_index_map_clone(tview->view.index->map);
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
314 }
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
315 return tview->lookup_map;
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
316 }
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
317
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
318 static const void *
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
319 tview_return_updated_ext(struct mail_index_view_transaction *tview,
8548
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
320 uint32_t seq, const void *data, uint32_t ext_id)
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
321 {
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
322 const struct mail_index_ext *ext;
8192
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
323 const struct mail_index_registered_ext *rext;
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
324 const struct mail_transaction_ext_intro *intro;
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
325 unsigned int record_align, record_size;
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
326 uint32_t ext_idx;
8548
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
327 size_t pos;
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
328
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
329 /* data begins with a 32bit sequence, followed by the actual
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
330 extension data */
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
331 data = CONST_PTR_OFFSET(data, sizeof(uint32_t));
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
332
8192
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
333 if (!mail_index_map_get_ext_idx(tview->lookup_map, ext_id, &ext_idx)) {
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
334 /* we're adding the extension now. */
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
335 rext = array_idx(&tview->view.index->extensions, ext_id);
8195
413c70b0ae1d Transaction view: Fix for the previous lookup_ext() fix.
Timo Sirainen <tss@iki.fi>
parents: 8192
diff changeset
336 record_align = rext->record_align;
413c70b0ae1d Transaction view: Fix for the previous lookup_ext() fix.
Timo Sirainen <tss@iki.fi>
parents: 8192
diff changeset
337 record_size = rext->record_size;
8192
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
338 } else {
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
339 ext = array_idx(&tview->lookup_map->extensions, ext_idx);
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
340 record_align = ext->record_align;
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
341 record_size = ext->record_size;
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
342 }
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
343
8192
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
344 /* see if the extension has been resized within this transaction */
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
345 if (array_is_created(&tview->t->ext_resizes) &&
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
346 ext_id < array_count(&tview->t->ext_resizes)) {
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
347 intro = array_idx(&tview->t->ext_resizes, ext_id);
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
348 if (intro[ext_id].name_size != 0) {
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
349 record_align = intro->record_align;
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
350 record_size = intro->record_size;
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
351 }
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
352 }
32aa972895cc Transaction view: lookup_ext() crashed if extension was just being added within the transaction.
Timo Sirainen <tss@iki.fi>
parents: 8126
diff changeset
353
8199
94c751fa58e3 Transaction view: One more try at really fixing lookup_ext()..
Timo Sirainen <tss@iki.fi>
parents: 8195
diff changeset
354 if (record_align <= sizeof(uint32_t)) {
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
355 /* data is 32bit aligned already */
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
356 return data;
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
357 } else {
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
358 /* assume we want 64bit alignment - copy the data to
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
359 temporary buffer and return it */
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
360 if (tview->lookup_return_data == NULL) {
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
361 tview->lookup_return_data =
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
362 buffer_create_dynamic(default_pool,
8199
94c751fa58e3 Transaction view: One more try at really fixing lookup_ext()..
Timo Sirainen <tss@iki.fi>
parents: 8195
diff changeset
363 record_size + 64);
8548
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
364 } else if (seq != tview->lookup_prev_seq) {
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
365 /* clear the buffer between lookups for different
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
366 messages */
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
367 buffer_set_used_size(tview->lookup_return_data, 0);
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
368 }
8548
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
369 tview->lookup_prev_seq = seq;
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
370 pos = tview->lookup_return_data->used;
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
371 buffer_append(tview->lookup_return_data, data, record_size);
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
372 return CONST_PTR_OFFSET(tview->lookup_return_data->data, pos);
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
373 }
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
374 }
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
375
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
376 static void
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
377 tview_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
378 uint32_t ext_id, struct mail_index_map **map_r,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
379 const void **data_r, bool *expunged_r)
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
380 {
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
381 struct mail_index_view_transaction *tview =
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
382 (struct mail_index_view_transaction *)view;
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4333
diff changeset
383 const ARRAY_TYPE(seq_array) *ext_buf;
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
384 const void *data;
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
385 unsigned int idx;
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
386
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
387 i_assert(ext_id < array_count(&view->index->extensions));
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
388
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
389 *expunged_r = FALSE;
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
390
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
391 if (array_is_created(&tview->t->ext_rec_updates) &&
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
392 ext_id < array_count(&tview->t->ext_rec_updates)) {
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
393 /* there are some ext updates in transaction.
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
394 see if there's any for this sequence. */
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
395 ext_buf = array_idx(&tview->t->ext_rec_updates, ext_id);
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
396 if (array_is_created(ext_buf) &&
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
397 mail_index_seq_array_lookup(ext_buf, seq, &idx)) {
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
398 data = array_idx(ext_buf, idx);
6262
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
399 *map_r = tview_get_lookup_map(tview);
8548
6a6a3bfea547 transaction view: Allow looking up multiple ext datas for the same message without breaking.
Timo Sirainen <tss@iki.fi>
parents: 8215
diff changeset
400 *data_r = tview_return_updated_ext(tview, seq, data,
8126
cf2c4f3c636f mail_index_lookup_ext*() didn't return properly aligned pointers with updated transaction views.
Timo Sirainen <tss@iki.fi>
parents: 8115
diff changeset
401 ext_id);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
402 return;
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
403 }
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
404 }
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
405
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
406 /* not updated, return the existing value */
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
407 if (seq < tview->t->first_new_seq) {
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
408 tview->super->lookup_ext_full(view, seq, ext_id,
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
409 map_r, data_r, expunged_r);
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
410 } else {
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
411 *map_r = view->index->map;
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6275
diff changeset
412 *data_r = NULL;
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
413 }
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
414 }
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
415
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
416 static void tview_get_header_ext(struct mail_index_view *view,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
417 struct mail_index_map *map, uint32_t ext_id,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
418 const void **data_r, size_t *data_size_r)
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
419 {
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
420 struct mail_index_view_transaction *tview =
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
421 (struct mail_index_view_transaction *)view;
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
422
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
423 /* FIXME: check updates */
6275
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 6262
diff changeset
424 tview->super->get_header_ext(view, map, ext_id, data_r, data_size_r);
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
425 }
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
426
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
427 static bool tview_ext_get_reset_id(struct mail_index_view *view,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
428 struct mail_index_map *map,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
429 uint32_t ext_id, uint32_t *reset_id_r)
6171
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
430 {
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
431 struct mail_index_view_transaction *tview =
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
432 (struct mail_index_view_transaction *)view;
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
433 const uint32_t *reset_id_p;
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
434
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
435 if (array_is_created(&tview->t->ext_reset_ids) &&
6262
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
436 ext_id < array_count(&tview->t->ext_reset_ids) &&
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
437 map == tview->lookup_map) {
6171
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
438 reset_id_p = array_idx(&tview->t->ext_reset_ids, ext_id);
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
439 *reset_id_r = *reset_id_p;
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
440 return TRUE;
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
441 }
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
442
6262
15abc6d262cd mail_index_ext_get_reset_id() takes now map parameters. Fixed it to work
Timo Sirainen <tss@iki.fi>
parents: 6171
diff changeset
443 return tview->super->ext_get_reset_id(view, map, ext_id, reset_id_r);
6171
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
444 }
635b58fe8287 Added mail_index_ext_get_reset_id() which returns the latest reset_id when
Timo Sirainen <tss@iki.fi>
parents: 6037
diff changeset
445
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
446 static struct mail_index_view_vfuncs trans_view_vfuncs = {
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
447 tview_close,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
448 tview_get_message_count,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
449 tview_get_header,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
450 tview_lookup_full,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
451 tview_lookup_uid,
6677
90bcf480312d Renamed mail_index_lookup_uid_range() to mail_index_lookup_seq_range(), made
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
452 tview_lookup_seq_range,
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
453 tview_lookup_first,
8549
7b16388a3bb0 mail_get_flags/keywords() now returns updated values if they've been changed within transaction.
Timo Sirainen <tss@iki.fi>
parents: 8548
diff changeset
454 tview_lookup_keywords,
6420
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
455 tview_lookup_ext_full,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
456 tview_get_header_ext,
a8b515e1a26f Removed _ prefixes from function names.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
457 tview_ext_get_reset_id
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458 };
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
460 struct mail_index_view *
2271
15d959d262a4 UIDs for appended messages can now be assigned all at once. Maildir now
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
461 mail_index_transaction_open_updated_view(struct mail_index_transaction *t)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
463 struct mail_index_view_transaction *tview;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464
2884
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
465 if (t->view->syncing) {
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
466 /* transaction view is being synced. while it's done, it's not
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
467 possible to add new messages, but the view itself might
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
468 change. so we can't make a copy of the view. */
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
469 mail_index_view_ref(t->view);
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
470 return t->view;
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
471 }
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
472
2271
15d959d262a4 UIDs for appended messages can now be assigned all at once. Maildir now
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
473 tview = i_new(struct mail_index_view_transaction, 1);
15d959d262a4 UIDs for appended messages can now be assigned all at once. Maildir now
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
474 mail_index_view_clone(&tview->view, t->view);
4453
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
475 tview->view.v = trans_view_vfuncs;
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
476 tview->super = &t->view->v;
2271
15d959d262a4 UIDs for appended messages can now be assigned all at once. Maildir now
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
477 tview->t = t;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478
2271
15d959d262a4 UIDs for appended messages can now be assigned all at once. Maildir now
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
479 mail_index_transaction_ref(t);
15d959d262a4 UIDs for appended messages can now be assigned all at once. Maildir now
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
480 return &tview->view;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 }