Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/mail-search.h @ 7908:1e69c84a1e5a HEAD
Search code cleanups and minor optimizations.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 20 Jun 2008 05:35:05 +0300 |
parents | ec49260ed4ee |
children | bf9c51edbc66 |
rev | line source |
---|---|
6410
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
1 #ifndef MAIL_SEARCH_H |
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
2 #define MAIL_SEARCH_H |
0 | 3 |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
4 #include "seq-range-array.h" |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
5 #include "mail-types.h" |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
6 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
7 enum mail_search_arg_type { |
0 | 8 SEARCH_OR, |
9 SEARCH_SUB, | |
10 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1844
diff
changeset
|
11 /* sequence sets */ |
0 | 12 SEARCH_ALL, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1844
diff
changeset
|
13 SEARCH_SEQSET, |
7618
6dbd70663adf
Added support for SEARCH_UIDSET.
Timo Sirainen <tss@iki.fi>
parents:
7284
diff
changeset
|
14 SEARCH_UIDSET, |
0 | 15 |
16 /* flags */ | |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
17 SEARCH_FLAGS, |
6965
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
18 SEARCH_KEYWORDS, |
0 | 19 |
20 /* dates */ | |
21 SEARCH_BEFORE, | |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
22 SEARCH_ON, /* time must point to beginning of the day */ |
0 | 23 SEARCH_SINCE, |
24 SEARCH_SENTBEFORE, | |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
25 SEARCH_SENTON, /* time must point to beginning of the day */ |
0 | 26 SEARCH_SENTSINCE, |
27 | |
28 /* sizes */ | |
29 SEARCH_SMALLER, | |
30 SEARCH_LARGER, | |
31 | |
32 /* headers */ | |
33 SEARCH_HEADER, | |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1069
diff
changeset
|
34 SEARCH_HEADER_ADDRESS, |
7284
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
35 SEARCH_HEADER_COMPRESS_LWSP, |
0 | 36 |
37 /* body */ | |
38 SEARCH_BODY, | |
4942
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
39 SEARCH_TEXT, |
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
40 SEARCH_BODY_FAST, |
7620 | 41 SEARCH_TEXT_FAST, |
42 | |
43 /* extensions */ | |
44 SEARCH_MODSEQ | |
45 }; | |
46 | |
7640 | 47 enum mail_search_arg_flag { |
48 /* For (SENT)BEFORE/SINCE/ON searches: Don't drop timezone from | |
49 comparisons */ | |
50 MAIL_SEARCH_ARG_FLAG_USE_TZ = 0x01, | |
51 }; | |
52 | |
7620 | 53 enum mail_search_modseq_type { |
54 MAIL_SEARCH_MODSEQ_TYPE_ANY = 0, | |
55 MAIL_SEARCH_MODSEQ_TYPE_PRIVATE, | |
56 MAIL_SEARCH_MODSEQ_TYPE_SHARED | |
57 }; | |
58 | |
59 struct mail_search_modseq { | |
60 uint64_t modseq; | |
61 enum mail_search_modseq_type type; | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
62 }; |
0 | 63 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
64 struct mail_search_arg { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
65 struct mail_search_arg *next; |
0 | 66 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
67 enum mail_search_arg_type type; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1844
diff
changeset
|
68 struct { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
69 struct mail_search_arg *subargs; |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
70 ARRAY_TYPE(seq_range) seqset; |
0 | 71 const char *str; |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
72 time_t time; |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
73 uoff_t size; |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
74 enum mail_flags flags; |
6965
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
75 struct mail_keywords *keywords; |
7620 | 76 struct mail_search_modseq *modseq; |
7640 | 77 enum mail_search_arg_flag search_flags; |
0 | 78 } value; |
79 | |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
80 void *context; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1069
diff
changeset
|
81 const char *hdr_field_name; /* for SEARCH_HEADER* */ |
0 | 82 unsigned int not:1; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
83 unsigned int match_always:1; /* result = 1 always */ |
0 | 84 |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
85 int result; /* -1 = unknown, 0 = unmatched, 1 = matched */ |
0 | 86 }; |
87 | |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
88 struct mail_search_args { |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
89 int refcount; |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
90 pool_t pool; |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
91 struct mailbox *box; |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
92 struct mail_search_arg *args; |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
93 const char *charset; |
7908
1e69c84a1e5a
Search code cleanups and minor optimizations.
Timo Sirainen <tss@iki.fi>
parents:
7655
diff
changeset
|
94 |
1e69c84a1e5a
Search code cleanups and minor optimizations.
Timo Sirainen <tss@iki.fi>
parents:
7655
diff
changeset
|
95 unsigned int initialized:1; |
1e69c84a1e5a
Search code cleanups and minor optimizations.
Timo Sirainen <tss@iki.fi>
parents:
7655
diff
changeset
|
96 unsigned int simplified:1; |
1e69c84a1e5a
Search code cleanups and minor optimizations.
Timo Sirainen <tss@iki.fi>
parents:
7655
diff
changeset
|
97 unsigned int have_inthreads:1; |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
98 }; |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
99 |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
100 #define ARG_SET_RESULT(arg, res) \ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
101 STMT_START { \ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
102 (arg)->result = !(arg)->not ? (res) : \ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
103 (res) == -1 ? -1 : !(res); \ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
104 } STMT_END |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
105 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
106 typedef void mail_search_foreach_callback_t(struct mail_search_arg *arg, |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
107 void *context); |
0 | 108 |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
109 /* Allocate keywords for search arguments. If change_uidsets is TRUE, |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
110 change uidsets to seqsets. */ |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
111 void mail_search_args_init(struct mail_search_args *args, |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
112 struct mailbox *box, bool change_uidsets, |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
113 const ARRAY_TYPE(seq_range) *search_saved_uidset); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
114 /* Free keywords. The args can initialized afterwards again if needed. */ |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
115 void mail_search_args_deinit(struct mail_search_args *args); |
7655
ec49260ed4ee
SEARCH UPDATE: Convert seqsets in saved results to uidsets so that they can
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
116 /* Convert sequence sets in args to UIDs. */ |
ec49260ed4ee
SEARCH UPDATE: Convert seqsets in saved results to uidsets so that they can
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
117 void mail_search_args_seq2uid(struct mail_search_args *args); |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
118 |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
119 void mail_search_args_ref(struct mail_search_args *args); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
120 void mail_search_args_unref(struct mail_search_args **args); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
121 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
122 /* Reset the results in search arguments. match_always is reset only if |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
123 full_reset is TRUE. */ |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
124 void mail_search_args_reset(struct mail_search_arg *args, bool full_reset); |
0 | 125 |
126 /* goes through arguments in list that don't have a result yet. | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
127 Returns 1 = search matched, 0 = search unmatched, -1 = don't know yet */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
128 int mail_search_args_foreach(struct mail_search_arg *args, |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
129 mail_search_foreach_callback_t *callback, |
953
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
130 void *context); |
4906
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
131 #ifdef CONTEXT_TYPE_SAFETY |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
132 # define mail_search_args_foreach(args, callback, context) \ |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
133 ({(void)(1 ? 0 : callback((struct mail_search_arg *)NULL, context)); \ |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
134 mail_search_args_foreach(args, \ |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
135 (mail_search_foreach_callback_t *)callback, context); }) |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
136 #else |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
137 # define mail_search_args_foreach(args, callback, context) \ |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
138 mail_search_args_foreach(args, \ |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
139 (mail_search_foreach_callback_t *)callback, context) |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
140 #endif |
0 | 141 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1069
diff
changeset
|
142 /* Fills have_headers and have_body based on if such search argument exists |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1069
diff
changeset
|
143 that needs to be checked. Returns the headers that we're searching for, or |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1069
diff
changeset
|
144 NULL if we're searching for TEXT. */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1069
diff
changeset
|
145 const char *const * |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1069
diff
changeset
|
146 mail_search_args_analyze(struct mail_search_arg *args, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
147 bool *have_headers, bool *have_body); |
0 | 148 |
7908
1e69c84a1e5a
Search code cleanups and minor optimizations.
Timo Sirainen <tss@iki.fi>
parents:
7655
diff
changeset
|
149 /* Simplify/optimize search arguments */ |
1e69c84a1e5a
Search code cleanups and minor optimizations.
Timo Sirainen <tss@iki.fi>
parents:
7655
diff
changeset
|
150 void mail_search_args_simplify(struct mail_search_args *args); |
6899
69babcc2fb80
Simplify search arguments immediately when calling mailbox_search_init().
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
151 |
0 | 152 #endif |