Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/mail-search.h @ 7619:56f55bd35aa5 HEAD
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Rewrote messageset handling to use struct seq_range instead.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 14 Mar 2008 11:59:36 +0200 |
parents | 6dbd70663adf |
children | 4b8c1c164d8f |
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, |
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
41 SEARCH_TEXT_FAST |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
42 }; |
0 | 43 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
44 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
|
45 struct mail_search_arg *next; |
0 | 46 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
47 enum mail_search_arg_type type; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1844
diff
changeset
|
48 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
|
49 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
|
50 ARRAY_TYPE(seq_range) seqset; |
0 | 51 const char *str; |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 struct mail_keywords *keywords; |
0 | 56 } value; |
57 | |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
58 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
|
59 const char *hdr_field_name; /* for SEARCH_HEADER* */ |
0 | 60 unsigned int not:1; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
61 unsigned int match_always:1; /* result = 1 always */ |
0 | 62 |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
63 int result; /* -1 = unknown, 0 = unmatched, 1 = matched */ |
0 | 64 }; |
65 | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
66 #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
|
67 STMT_START { \ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
68 (arg)->result = !(arg)->not ? (res) : \ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
69 (res) == -1 ? -1 : !(res); \ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
70 } STMT_END |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
71 |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
72 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
|
73 void *context); |
0 | 74 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
75 /* 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
|
76 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
|
77 void mail_search_args_reset(struct mail_search_arg *args, bool full_reset); |
0 | 78 |
79 /* 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
|
80 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
|
81 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
|
82 mail_search_foreach_callback_t *callback, |
953
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
83 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
|
84 #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
|
85 # 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
|
86 ({(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
|
87 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
|
88 (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
|
89 #else |
0c3c948412c5
Type safe callbacks weren't as easy as I thought. Only callback(void
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
90 # 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
|
91 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
|
92 (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
|
93 #endif |
0 | 94 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1069
diff
changeset
|
95 /* 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 bool *have_headers, bool *have_body); |
0 | 101 |
6899
69babcc2fb80
Simplify search arguments immediately when calling mailbox_search_init().
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
102 /* 1) Change args so that SEARCH_SUB and SEARCH_OR will never have "not" set |
69babcc2fb80
Simplify search arguments immediately when calling mailbox_search_init().
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
103 2) Drop unnecessary nested SEARCH_SUB and SEARCH_ORs */ |
69babcc2fb80
Simplify search arguments immediately when calling mailbox_search_init().
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
104 void mail_search_args_simplify(struct mail_search_arg *args); |
69babcc2fb80
Simplify search arguments immediately when calling mailbox_search_init().
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
105 |
0 | 106 #endif |