annotate src/lib-index/mail-index-transaction-view.c @ 5855:fd6ff4d9cab1 HEAD

Removed view->hdr. Use view->map->hdr directly.
author Timo Sirainen <tss@iki.fi>
date Sun, 01 Jul 2007 22:11:41 +0300
parents 3bccf203fa91
children 5d3a941444f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1 /* Copyright (C) 2004-2006 Timo Sirainen */
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
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
16 struct mail_index_header hdr;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 };
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 static void _tview_close(struct mail_index_view *view)
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 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
22 (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
23 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
24
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
25 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
26 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
27 }
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 static uint32_t _tview_get_message_count(struct mail_index_view *view)
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 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
32 (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
33
5855
fd6ff4d9cab1 Removed view->hdr. Use view->map->hdr directly.
Timo Sirainen <tss@iki.fi>
parents: 5228
diff changeset
34 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
35 (tview->t->last_new_seq == 0 ? 0 :
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 tview->t->last_new_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
37 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
2892
62d53b49110d Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents: 2884
diff changeset
39 static const struct mail_index_header *
62d53b49110d Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents: 2884
diff changeset
40 _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
41 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 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
43 (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
44 const struct mail_index_header *hdr;
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
45 const struct mail_index_record *recs;
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
46 unsigned int count;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47
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
48 /* 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
49 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
50
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
51 if (array_is_created(&tview->t->appends)) {
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
52 /* update next_uid from appends, if UIDs have been given yet */
5228
3bccf203fa91 When adding mails to index in non-sorted UID order and then using
Timo Sirainen <tss@iki.fi>
parents: 4529
diff changeset
53 mail_index_transaction_sort_appends(tview->t);
3bccf203fa91 When adding mails to index in non-sorted UID order and then using
Timo Sirainen <tss@iki.fi>
parents: 4529
diff changeset
54
4528
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
55 recs = array_get(&tview->t->appends, &count);
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
56 if (count > 0 && recs[count-1].uid != 0) {
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
57 i_assert(recs[count-1].uid >= hdr->next_uid);
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
58 tview->hdr = *hdr;
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
59 tview->hdr.next_uid = recs[count-1].uid + 1;
4529
0ffb6fa11744 And fix for previous change..
Timo Sirainen <tss@iki.fi>
parents: 4528
diff changeset
60 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
61 }
74212d11b6b5 Transaction view: mail_index_get_header() returns now updated next_uid field
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
62 }
4529
0ffb6fa11744 And fix for previous change..
Timo Sirainen <tss@iki.fi>
parents: 4528
diff changeset
63 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
64 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 static int _tview_lookup_full(struct mail_index_view *view, uint32_t seq,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 struct mail_index_map **map_r,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 const struct mail_index_record **rec_r)
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 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
71 (struct mail_index_view_transaction *)view;
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
72 int ret;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 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
75 /* 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
76 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
77 *map_r = view->index->map;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 *rec_r = mail_index_transaction_lookup(tview->t, seq);
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 return 1;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 }
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
81
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
82 ret = tview->super->lookup_full(view, seq, map_r, rec_r);
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
83 if (ret <= 0)
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
84 return ret;
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
85
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
86 /* if we're expunged within this transaction, return 0 */
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
87 return array_is_created(&tview->t->expunges) &&
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
88 seq_range_exists(&tview->t->expunges, seq) ? 0 : 1;
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
89
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 static int _tview_lookup_uid(struct mail_index_view *view, uint32_t seq,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 uint32_t *uid_r)
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 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
96 (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
97
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 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
99 *uid_r = mail_index_transaction_lookup(tview->t, seq)->uid;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 return 0;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 } else {
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
102 return 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
103 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 static int _tview_lookup_uid_range(struct mail_index_view *view,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 uint32_t first_uid, uint32_t last_uid,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 uint32_t *first_seq_r, uint32_t *last_seq_r)
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 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
111 (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
112
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
113 if (tview->super->lookup_uid_range(view, first_uid, last_uid,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
114 first_seq_r, last_seq_r) < 0)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 return -1;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 /* FIXME: we don't need this function yet.. new UIDs might be 0 as
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 well.. */
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 if (*first_seq_r == 0) {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 /* nothing found, either doesn't exist or it's completely
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 newly appended. */
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 } else if (*last_seq_r + 1 == 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 /* last_seq_r may be growed from transactions */
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 return 0;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 static int _tview_lookup_first(struct mail_index_view *view,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 enum mail_flags flags, uint8_t flags_mask,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 uint32_t *seq_r)
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 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
135 (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
136 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
137 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
138 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
139
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
140 if (tview->super->lookup_first(view, flags, flags_mask, seq_r) < 0)
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 return -1;
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 if (*seq_r != 0)
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 return 0;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
146 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
147 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
148 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
149 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
150
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
151 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
152 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
153 *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
154 break;
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 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 return 0;
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 }
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
161 static int
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
162 _tview_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
163 uint32_t ext_id, struct mail_index_map **map_r,
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
164 const void **data_r)
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
165 {
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
166 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
167 (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
168 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
169 const void *data;
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
170 unsigned int idx;
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
171
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
172 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
173
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
174 *map_r = view->index->map;
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
175
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
176 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
177 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
178 /* 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
179 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
180 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
181 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
182 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
183 data = array_idx(ext_buf, idx);
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
184 *data_r = CONST_PTR_OFFSET(data, sizeof(uint32_t));
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
185 return 1;
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
186 }
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
187 }
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
188
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
189 /* 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
190 if (seq < tview->t->first_new_seq) {
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
191 return tview->super->lookup_ext_full(view, seq, ext_id,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
192 map_r, data_r);
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
193 }
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
194
3191
0df3f5d71958 Changed many buffers to arrays. Cleans up the code a lot.
Timo Sirainen <tss@iki.fi>
parents: 2918
diff changeset
195 *data_r = NULL;
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
196 return 1;
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
197 }
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
198
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
199 static int _tview_get_header_ext(struct mail_index_view *view,
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
200 struct mail_index_map *map, uint32_t ext_id,
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
201 const void **data_r, size_t *data_size_r)
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
202 {
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
203 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
204 (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
205
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
206 /* FIXME: check updates */
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
207 return tview->super->get_header_ext(view, map, ext_id,
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
208 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
209 }
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
210
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
211 static struct mail_index_view_vfuncs trans_view_vfuncs = {
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212 _tview_close,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 _tview_get_message_count,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214 _tview_get_header,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 _tview_lookup_full,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 _tview_lookup_uid,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 _tview_lookup_uid_range,
2563
5752e5ac88f0 Save extra record/header infos into index file permanently.
Timo Sirainen <tss@iki.fi>
parents: 2271
diff changeset
218 _tview_lookup_first,
2853
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
219 _tview_lookup_ext_full,
512dd7d76cdc Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents: 2671
diff changeset
220 _tview_get_header_ext
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
221 };
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
223 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
224 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
225 {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
226 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
227
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
228 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
229 /* 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
230 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
231 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
232 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
233 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
234 }
173a0296e81d Update view's header only after syncing the view. This and other changes fix
Timo Sirainen <tss@iki.fi>
parents: 2853
diff changeset
235
2271
15d959d262a4 UIDs for appended messages can now be assigned all at once. Maildir now
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
236 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
237 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
238 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
239 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
240 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
241
2271
15d959d262a4 UIDs for appended messages can now be assigned all at once. Maildir now
Timo Sirainen <tss@iki.fi>
parents: 2240
diff changeset
242 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
243 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
244 }