mail-index-transaction-view.c revision 5d27987496b12dbad8c78aba5a9ccc74e6606623
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Copyright (C) 2004-2006 Timo Sirainen */
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainenstatic void _tview_close(struct mail_index_view *view)
e2bdca8201e4aa1cd31332ffbdd4c6eef9151d5eTimo Sirainenstatic uint32_t _tview_get_message_count(struct mail_index_view *view)
8b5c520883aa37bb55646286d375fdbae294d710Timo Sirainen tview->t->last_new_seq - tview->t->first_new_seq);
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainenstatic const struct mail_index_header *
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen_tview_get_header(struct mail_index_view *view)
b63e20ea9bc84f1aa90a551f217d01385e070b73Timo Sirainen /* FIXME: header counters may not be correct */
b68b98e1545bad8af9cb58ef89e8d7f6e16577beAki Tuomistatic int _tview_lookup_full(struct mail_index_view *view, uint32_t seq,
b68b98e1545bad8af9cb58ef89e8d7f6e16577beAki Tuomi /* FIXME: is this right to return index map..?
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen it's not there yet. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen *rec_r = mail_index_transaction_lookup(tview->t, seq);
f7423cbbd9dea363a5df18ebb96da055a977ae79Timo Sirainen ret = tview->parent->lookup_full(view, seq, map_r, rec_r);
72f21884c0bb9bb26edad63623427ac2120901eaStephan Bosch /* if we're expunged within this transaction, return 0 */
009217abb57a24a4076092e8e4e165545747839eStephan Bosch return array_is_created(&tview->t->expunges) &&
72f21884c0bb9bb26edad63623427ac2120901eaStephan Bosch seq_range_exists(&tview->t->expunges, seq) ? 0 : 1;
7487ff578435377bbeefffdbfb78ca09ed1292dfTimo Sirainenstatic int _tview_lookup_uid(struct mail_index_view *view, uint32_t seq,
541f258d86b2db26efd5670883966183b4fb6323Timo Sirainen *uid_r = mail_index_transaction_lookup(tview->t, seq)->uid;
541f258d86b2db26efd5670883966183b4fb6323Timo Sirainen return tview->parent->lookup_uid(view, seq, uid_r);
541f258d86b2db26efd5670883966183b4fb6323Timo Sirainenstatic int _tview_lookup_uid_range(struct mail_index_view *view,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen if (tview->parent->lookup_uid_range(view, first_uid, last_uid,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* FIXME: we don't need this function yet.. new UIDs might be 0 as
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen /* nothing found, either doesn't exist or it's completely
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen newly appended. */
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen } else if (*last_seq_r + 1 == tview->t->first_new_seq) {
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen /* last_seq_r may be growed from transactions */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic int _tview_lookup_first(struct mail_index_view *view,
8a0a8c982a6ffc75a4b1c8717b6180a811655794Timo Sirainen if (tview->parent->lookup_first(view, flags, flags_mask, seq_r) < 0)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen rec = array_get(&tview->t->appends, &append_count);
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen i_assert(append_count == message_count - seq + 1);
f6f23086d0259d50cde3bd5d4180d67d820d293dTimo Sirainen if ((rec->flags & flags_mask) == (uint8_t)flags) {
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen_tview_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen uint32_t ext_id, struct mail_index_map **map_r,
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen const void **data_r)
ccf50662cc02b5e703039a4ff7f91a4470e25b71Timo Sirainen unsigned int idx;
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen i_assert(ext_id < array_count(&view->index->extensions));
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen if (array_is_created(&tview->t->ext_rec_updates) &&
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen ext_id < array_count(&tview->t->ext_rec_updates)) {
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* there are some ext updates in transaction.
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen see if there's any for this sequence. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen ext_buf = array_idx(&tview->t->ext_rec_updates, ext_id);
1ffb2afe6d7e8860a2231a4827078cf2ef9c22cdTimo Sirainen mail_index_seq_array_lookup(ext_buf, seq, &idx)) {
1ffb2afe6d7e8860a2231a4827078cf2ef9c22cdTimo Sirainen *data_r = CONST_PTR_OFFSET(data, sizeof(uint32_t));
0161376aac025266d8654577c4b9ce371ffc87eaTimo Sirainen /* not updated, return the existing value */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen return tview->parent->lookup_ext_full(view, seq, ext_id,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenstatic int _tview_get_header_ext(struct mail_index_view *view,
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* FIXME: check updates */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen return tview->parent->get_header_ext(view, map, ext_id,
b2d562f9c7fd13f9a16e9b3bcee904630b80b1feTimo Sirainenstatic struct mail_index_view_methods view_methods = {
57397188558fcd1a9e24dbbbd2952eac9c45c20dTimo Sirainenmail_index_transaction_open_updated_view(struct mail_index_transaction *t)
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen /* transaction view is being synced. while it's done, it's not
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen possible to add new messages, but the view itself might
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen change. so we can't make a copy of the view. */