Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-index/mail-index-sync-keywords.c @ 9458:adee8cb3ff5d HEAD
Minor memory allocation tweaks.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 28 Oct 2009 14:10:04 -0400 |
parents | b9faf4db2a9f |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8547
diff
changeset
|
1 /* Copyright (c) 2004-2009 Dovecot authors, see the included COPYING file */ |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
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:
3254
diff
changeset
|
4 #include "array.h" |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "buffer.h" |
7620 | 6 #include "mail-index-modseq.h" |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "mail-index-view-private.h" |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "mail-index-sync-private.h" |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "mail-transaction-log.h" |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
11 static bool |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
12 keyword_lookup(struct mail_index_sync_map_ctx *ctx, |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
13 const char *keyword_name, unsigned int *idx_r) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 { |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
15 struct mail_index_map *map = ctx->view->map; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
16 const unsigned int *idx_map; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
17 unsigned int i, count, keyword_idx; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 |
4501
a7178fbf4697
In some conditions a keyword could have been added to the index twice. Also
Timo Sirainen <tss@iki.fi>
parents:
4279
diff
changeset
|
19 if (array_is_created(&map->keyword_idx_map) && |
a7178fbf4697
In some conditions a keyword could have been added to the index twice. Also
Timo Sirainen <tss@iki.fi>
parents:
4279
diff
changeset
|
20 mail_index_keyword_lookup(ctx->view->index, keyword_name, |
6335
a1c587d3d633
Removed autocreate parameter from mail_index_keyword_lookup(). Added a new
Timo Sirainen <tss@iki.fi>
parents:
6325
diff
changeset
|
21 &keyword_idx)) { |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
22 /* FIXME: slow. maybe create index -> file mapping as well */ |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
23 idx_map = array_get(&map->keyword_idx_map, &count); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
24 for (i = 0; i < count; i++) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
25 if (idx_map[i] == keyword_idx) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
26 *idx_r = i; |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
27 return TRUE; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
28 } |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 } |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
31 return FALSE; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 static buffer_t * |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 keywords_get_header_buf(struct mail_index_map *map, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 const struct mail_index_ext *ext, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 unsigned int new_count, unsigned int *keywords_count_r, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 size_t *rec_offset_r, size_t *name_offset_root_r, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 size_t *name_offset_r) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 buffer_t *buf; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 const struct mail_index_keyword_header *kw_hdr; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 const struct mail_index_keyword_header_rec *kw_rec; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 const char *name; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 struct mail_index_keyword_header new_kw_hdr; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 uint32_t offset; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 kw_hdr = CONST_PTR_OFFSET(map->hdr_base, ext->hdr_offset); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 kw_rec = (const void *)(kw_hdr + 1); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 name = (const char *)(kw_rec + kw_hdr->keywords_count); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 if (kw_hdr->keywords_count == 0) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 return NULL; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 |
6325 | 55 i_assert((size_t)(name - (const char *)kw_hdr) < ext->hdr_size); |
56 | |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 new_kw_hdr = *kw_hdr; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 new_kw_hdr.keywords_count += new_count; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 *keywords_count_r = new_kw_hdr.keywords_count; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 offset = kw_rec[kw_hdr->keywords_count-1].name_offset; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 offset += strlen(name + offset) + 1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 buf = buffer_create_dynamic(pool_datastack_create(), 512); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 buffer_append(buf, &new_kw_hdr, sizeof(new_kw_hdr)); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 buffer_append(buf, kw_rec, sizeof(*kw_rec) * kw_hdr->keywords_count); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 *rec_offset_r = buf->used; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 buffer_write(buf, buf->used + sizeof(*kw_rec) * new_count, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 name, offset); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 *name_offset_root_r = buf->used; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 *name_offset_r = offset; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 return buf; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
75 static void keywords_ext_register(struct mail_index_sync_map_ctx *ctx, |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
76 uint32_t ext_map_idx, uint32_t reset_id, |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
77 uint32_t hdr_size, uint32_t keywords_count) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 buffer_t *ext_intro_buf; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 struct mail_transaction_ext_intro *u; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
82 i_assert(keywords_count > 0); |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
83 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 ext_intro_buf = |
8547
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
85 buffer_create_static_hard(pool_datastack_create(), sizeof(*u) + |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
86 sizeof(MAIL_INDEX_EXT_KEYWORDS)-1); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 u = buffer_append_space_unsafe(ext_intro_buf, sizeof(*u)); |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
89 u->ext_id = ext_map_idx; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 u->reset_id = reset_id; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 u->hdr_size = hdr_size; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 u->record_size = (keywords_count + CHAR_BIT - 1) / CHAR_BIT; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 if ((u->record_size % 4) != 0) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 /* since we aren't properly aligned anyway, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 reserve one extra byte for future */ |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 u->record_size++; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 u->record_align = 1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
100 if (ext_map_idx == (uint32_t)-1) { |
8547
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
101 u->name_size = strlen(MAIL_INDEX_EXT_KEYWORDS); |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
102 buffer_append(ext_intro_buf, MAIL_INDEX_EXT_KEYWORDS, |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
103 u->name_size); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 |
6373
06818dd6a952
Make sure extensions updates don't modify keywords.
Timo Sirainen <tss@iki.fi>
parents:
6349
diff
changeset
|
106 ctx->internal_update = TRUE; |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
107 if (mail_index_sync_ext_intro(ctx, u) < 0) |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
108 i_panic("Keyword extension growing failed"); |
6373
06818dd6a952
Make sure extensions updates don't modify keywords.
Timo Sirainen <tss@iki.fi>
parents:
6349
diff
changeset
|
109 ctx->internal_update = FALSE; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
112 static void |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
113 keywords_header_add(struct mail_index_sync_map_ctx *ctx, |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
114 const char *keyword_name, unsigned int *keyword_idx_r) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 { |
6373
06818dd6a952
Make sure extensions updates don't modify keywords.
Timo Sirainen <tss@iki.fi>
parents:
6349
diff
changeset
|
116 struct mail_index_map *map; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 const struct mail_index_ext *ext = NULL; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 struct mail_index_keyword_header *kw_hdr; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 struct mail_index_keyword_header_rec kw_rec; |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
120 uint32_t ext_map_idx; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 buffer_t *buf = NULL; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
122 size_t keyword_len, rec_offset, name_offset, name_offset_root; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 unsigned int keywords_count; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5399
diff
changeset
|
125 /* if we crash in the middle of writing the header, the |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5399
diff
changeset
|
126 keywords are more or less corrupted. avoid that by |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5399
diff
changeset
|
127 making sure the header is updated atomically. */ |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5399
diff
changeset
|
128 map = mail_index_sync_get_atomic_map(ctx); |
5399
9be95726e29f
When adding new keywords, update the index file atomically so the keywords
Timo Sirainen <tss@iki.fi>
parents:
5051
diff
changeset
|
129 |
8547
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
130 if (!mail_index_map_lookup_ext(map, MAIL_INDEX_EXT_KEYWORDS, |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
131 &ext_map_idx)) |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
132 ext_map_idx = (uint32_t)-1; |
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
133 else { |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
134 /* update existing header */ |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
135 ext = array_idx(&map->extensions, ext_map_idx); |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
136 buf = keywords_get_header_buf(map, ext, 1, &keywords_count, |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
137 &rec_offset, &name_offset_root, |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
138 &name_offset); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 if (buf == NULL) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 /* create new / replace broken header */ |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 buf = buffer_create_dynamic(pool_datastack_create(), 512); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 kw_hdr = buffer_append_space_unsafe(buf, sizeof(*kw_hdr)); |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
145 kw_hdr->keywords_count = 1; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 keywords_count = kw_hdr->keywords_count; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 rec_offset = buf->used; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 name_offset_root = rec_offset + |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 kw_hdr->keywords_count * sizeof(kw_rec); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 name_offset = 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
154 /* add the keyword */ |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 memset(&kw_rec, 0, sizeof(kw_rec)); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 kw_rec.name_offset = name_offset; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 |
3549
3c5eb0649d5a
We didn't add the ending NUL character in keyword name, which caused more or
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
158 keyword_len = strlen(keyword_name) + 1; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
159 buffer_write(buf, rec_offset, &kw_rec, sizeof(kw_rec)); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
160 buffer_write(buf, name_offset_root, keyword_name, keyword_len); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
162 rec_offset += sizeof(kw_rec); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
163 kw_rec.name_offset += keyword_len; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
164 name_offset_root += keyword_len; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 if ((buf->used % 4) != 0) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 buffer_append_zero(buf, 4 - (buf->used % 4)); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 if (ext == NULL || buf->used > ext->hdr_size || |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 (uint32_t)ext->record_size * CHAR_BIT < keywords_count) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 /* if we need to grow the buffer, add some padding */ |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 buffer_append_zero(buf, 128); |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
173 keywords_ext_register(ctx, ext_map_idx, |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
174 ext == NULL ? 0 : ext->reset_id, |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
175 buf->used, keywords_count); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 /* map may have changed */ |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 map = ctx->view->map; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 |
8547
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
180 if (!mail_index_map_lookup_ext(map, MAIL_INDEX_EXT_KEYWORDS, |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
181 &ext_map_idx)) |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
182 i_unreached(); |
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
183 ext = array_idx(&map->extensions, ext_map_idx); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 i_assert(ext->hdr_size == buf->used); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
188 buffer_copy(map->hdr_copy_buf, ext->hdr_offset, buf, 0, buf->used); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 map->hdr_base = map->hdr_copy_buf->data; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
191 if (mail_index_map_parse_keywords(map) < 0) |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
192 i_panic("Keyword update corrupted keywords header"); |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
193 |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
194 *keyword_idx_r = keywords_count - 1; |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
195 i_assert(*keyword_idx_r / CHAR_BIT < ext->record_size); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
198 static int |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5399
diff
changeset
|
199 keywords_update_records(struct mail_index_sync_map_ctx *ctx, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 const struct mail_index_ext *ext, |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5399
diff
changeset
|
201 unsigned int keyword_idx, enum modify_type type, |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
202 uint32_t uid1, uint32_t uid2) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5399
diff
changeset
|
204 struct mail_index_view *view = ctx->view; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 struct mail_index_record *rec; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
206 unsigned char *data, data_mask; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
207 unsigned int data_offset; |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
208 uint32_t seq1, seq2; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
209 |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
210 i_assert(keyword_idx != (unsigned int)-1); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
212 if (!mail_index_lookup_seq_range(view, uid1, uid2, &seq1, &seq2)) |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
213 return 1; |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
214 |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5399
diff
changeset
|
215 mail_index_sync_write_seq_update(ctx, seq1, seq2); |
7620 | 216 mail_index_modseq_update_keyword(ctx->modseq_ctx, keyword_idx, |
217 seq1, seq2); | |
3805
5d090d03f2b5
Don't rewrite index file every time with mmap_disable=yes.
Timo Sirainen <tss@iki.fi>
parents:
3549
diff
changeset
|
218 |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
219 data_offset = keyword_idx / CHAR_BIT; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
220 data_mask = 1 << (keyword_idx % CHAR_BIT); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
221 |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
222 i_assert(data_offset < ext->record_size); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
223 data_offset += ext->record_offset; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 |
4501
a7178fbf4697
In some conditions a keyword could have been added to the index twice. Also
Timo Sirainen <tss@iki.fi>
parents:
4279
diff
changeset
|
225 i_assert(data_offset >= sizeof(struct mail_index_record)); |
a7178fbf4697
In some conditions a keyword could have been added to the index twice. Also
Timo Sirainen <tss@iki.fi>
parents:
4279
diff
changeset
|
226 |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
227 switch (type) { |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
228 case MODIFY_ADD: |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
229 for (seq1--; seq1 < seq2; seq1++) { |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
230 rec = MAIL_INDEX_MAP_IDX(view->map, seq1); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
231 data = PTR_OFFSET(rec, data_offset); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
232 *data |= data_mask; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
233 } |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 break; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
235 case MODIFY_REMOVE: |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
236 data_mask = ~data_mask; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
237 for (seq1--; seq1 < seq2; seq1++) { |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
238 rec = MAIL_INDEX_MAP_IDX(view->map, seq1); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
239 data = PTR_OFFSET(rec, data_offset); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
240 *data &= data_mask; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 } |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
242 break; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
243 default: |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
244 i_unreached(); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 } |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
246 return 1; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 int mail_index_sync_keywords(struct mail_index_sync_map_ctx *ctx, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 const struct mail_transaction_header *hdr, |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 const struct mail_transaction_keyword_update *rec) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 { |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
253 struct mail_index_view *view = ctx->view; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
254 const char *keyword_name; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 const struct mail_index_ext *ext; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
256 const uint32_t *uid, *end; |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
257 uint32_t seqset_offset, ext_map_idx; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
258 unsigned int keyword_idx; |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
259 int ret; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
261 seqset_offset = sizeof(*rec) + rec->name_size; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
262 if ((seqset_offset % 4) != 0) |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
263 seqset_offset += 4 - (seqset_offset % 4); |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
264 i_assert(seqset_offset < hdr->size); |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
265 |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
266 uid = CONST_PTR_OFFSET(rec, seqset_offset); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 end = CONST_PTR_OFFSET(rec, hdr->size); |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
269 keyword_name = t_strndup(rec + 1, rec->name_size); |
6323
4a6dd4e894b4
Log an error if empty keyword name is tried to be used.
Timo Sirainen <tss@iki.fi>
parents:
6320
diff
changeset
|
270 if (*keyword_name == '\0') { |
4a6dd4e894b4
Log an error if empty keyword name is tried to be used.
Timo Sirainen <tss@iki.fi>
parents:
6320
diff
changeset
|
271 mail_index_sync_set_corrupted(ctx, |
4a6dd4e894b4
Log an error if empty keyword name is tried to be used.
Timo Sirainen <tss@iki.fi>
parents:
6320
diff
changeset
|
272 "Trying to use empty keyword"); |
4a6dd4e894b4
Log an error if empty keyword name is tried to be used.
Timo Sirainen <tss@iki.fi>
parents:
6320
diff
changeset
|
273 return -1; |
4a6dd4e894b4
Log an error if empty keyword name is tried to be used.
Timo Sirainen <tss@iki.fi>
parents:
6320
diff
changeset
|
274 } |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
275 if (!keyword_lookup(ctx, keyword_name, &keyword_idx)) |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
276 keywords_header_add(ctx, keyword_name, &keyword_idx); |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
277 |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
278 /* if the keyword wasn't found, the "keywords" extension was created. |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
279 if it was found, the record size should already be correct, but |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
280 in case it isn't just fix it ourself. */ |
8547
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
281 if (!mail_index_map_lookup_ext(view->map, MAIL_INDEX_EXT_KEYWORDS, |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
282 &ext_map_idx)) |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
283 i_unreached(); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
285 ext = array_idx(&view->map->extensions, ext_map_idx); |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
286 if (keyword_idx / CHAR_BIT >= ext->record_size) { |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
287 if (rec->modify_type == MODIFY_REMOVE) { |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
288 /* nothing to do */ |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
289 return 1; |
6320
58b6fb965e62
If keyword ext record is missing, log an error instead of assert-crashing.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
290 } |
3086 | 291 |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
292 /* grow the record size */ |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
293 keywords_ext_register(ctx, ext_map_idx, ext->reset_id, |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
294 ext->hdr_size, |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
295 array_count(&view->map->keyword_idx_map)); |
8547
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
296 if (!mail_index_map_lookup_ext(view->map, |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
297 MAIL_INDEX_EXT_KEYWORDS, |
6349
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
298 &ext_map_idx)) |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
299 i_unreached(); |
75c814287334
Cleaned up keyword handling code.
Timo Sirainen <tss@iki.fi>
parents:
6348
diff
changeset
|
300 ext = array_idx(&view->map->extensions, ext_map_idx); |
3086 | 301 } |
302 | |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 while (uid+2 <= end) { |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
304 ret = keywords_update_records(ctx, ext, keyword_idx, |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
305 rec->modify_type, |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
306 uid[0], uid[1]); |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
307 if (ret <= 0) |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
308 return ret; |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
309 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 uid += 2; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 return 1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 } |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
315 |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
316 int |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
317 mail_index_sync_keywords_reset(struct mail_index_sync_map_ctx *ctx, |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
318 const struct mail_transaction_header *hdr, |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
319 const struct mail_transaction_keyword_reset *r) |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
320 { |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
321 struct mail_index_map *map = ctx->view->map; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
322 struct mail_index_record *rec; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
323 const struct mail_index_ext *ext; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
324 const struct mail_transaction_keyword_reset *end; |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
325 uint32_t ext_map_idx, seq1, seq2; |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
326 |
8547
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
327 if (!mail_index_map_lookup_ext(map, MAIL_INDEX_EXT_KEYWORDS, |
545cb188f7ab
Replaced literal "keywords" strings with a macro.
Timo Sirainen <tss@iki.fi>
parents:
7620
diff
changeset
|
328 &ext_map_idx)) { |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
329 /* nothing to do */ |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
330 return 1; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
331 } |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
332 |
6348
ef1c7b2acc10
Only index extension indexes are now called "ext_id". For map extension
Timo Sirainen <tss@iki.fi>
parents:
6335
diff
changeset
|
333 ext = array_idx(&map->extensions, ext_map_idx); |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
334 end = CONST_PTR_OFFSET(r, hdr->size); |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
335 for (; r != end; r++) { |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
336 if (!mail_index_lookup_seq_range(ctx->view, r->uid1, r->uid2, |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
337 &seq1, &seq2)) |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
338 continue; |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
339 |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
340 mail_index_sync_write_seq_update(ctx, seq1, seq2); |
7620 | 341 mail_index_modseq_reset_keywords(ctx->modseq_ctx, seq1, seq2); |
7132
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
342 for (seq1--; seq1 < seq2; seq1++) { |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
343 rec = MAIL_INDEX_MAP_IDX(map, seq1); |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
344 memset(PTR_OFFSET(rec, ext->record_offset), |
a1d1f7c9671e
Reverted fix for dropping expunged messages from flag updates. It's more
Timo Sirainen <tss@iki.fi>
parents:
7130
diff
changeset
|
345 0, ext->record_size); |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
346 } |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
347 } |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
348 return 1; |
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3086
diff
changeset
|
349 } |