Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/index-search.c @ 5513:fec5b65282a2 HEAD
fix
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 03 Apr 2007 21:18:08 +0300 |
parents | 65250cfebd74 |
children | 96f0b56489a2 |
rev | line source |
---|---|
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1 /* Copyright (C) 2002-2006 Timo Sirainen */ |
0 | 2 |
3 #include "lib.h" | |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
4 #include "ioloop.h" |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
5 #include "array.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
761
diff
changeset
|
6 #include "istream.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
7 #include "str.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
8 #include "message-address.h" |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
9 #include "message-date.h" |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
10 #include "message-body-search.h" |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
11 #include "message-header-search.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
12 #include "message-parser.h" |
119
2f67de235489
Whops, we were using RFC822 dates everywhere instead of IMAP dates.
Timo Sirainen <tss@iki.fi>
parents:
109
diff
changeset
|
13 #include "imap-date.h" |
0 | 14 #include "index-storage.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
15 #include "index-mail.h" |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
16 #include "index-sort.h" |
0 | 17 #include "mail-search.h" |
18 | |
19 #include <stdlib.h> | |
20 #include <ctype.h> | |
21 | |
883
39e0b536e708
Storage can now specify if errors should be sent to user as BAD or NO.
Timo Sirainen <tss@iki.fi>
parents:
881
diff
changeset
|
22 #define TXT_UNKNOWN_CHARSET "[BADCHARSET] Unknown charset" |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
23 #define TXT_INVALID_SEARCH_KEY "Invalid search key" |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
24 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
25 #define SEARCH_NONBLOCK_COUNT 20 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
26 #define SEARCH_NOTIFY_INTERVAL_SECS 10 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
27 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
28 struct index_search_context { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
29 struct mail_search_context mail_ctx; |
2224
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
30 struct mail_index_view *view; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
31 struct index_mailbox *ibox; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
32 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
33 uint32_t seq1, seq2; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
34 struct mail *mail; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
35 struct index_mail *imail; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
36 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
37 pool_t search_pool; |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
38 const char *error; |
924
4f697dde0fca
THREAD=REFERENCES implementation. Doesn't crash, but I'm not sure how
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
39 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
40 struct timeval search_start_time, last_notify; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
41 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
42 unsigned int failed:1; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
43 unsigned int sorted:1; |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
44 unsigned int have_seqsets:1; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
45 }; |
0 | 46 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
47 struct search_header_context { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
48 struct index_search_context *index_context; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
49 struct mail_search_arg *args; |
0 | 50 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
51 struct message_header_line *hdr; |
924
4f697dde0fca
THREAD=REFERENCES implementation. Doesn't crash, but I'm not sure how
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
52 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
53 unsigned int parse_headers:1; |
924
4f697dde0fca
THREAD=REFERENCES implementation. Doesn't crash, but I'm not sure how
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
54 unsigned int custom_header:1; |
4f697dde0fca
THREAD=REFERENCES implementation. Doesn't crash, but I'm not sure how
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
55 unsigned int threading:1; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
56 }; |
0 | 57 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
58 struct search_body_context { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
59 struct index_search_context *index_ctx; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
60 struct istream *input; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
61 const struct message_part *part; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
62 }; |
0 | 63 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
64 struct search_arg_context { |
5505 | 65 struct message_header_search_context *hdr_search_ctx; |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
66 struct message_body_search_context *body_search_ctx; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
67 }; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
68 |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
69 static int search_parse_msgset_args(struct index_mailbox *ibox, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
70 const struct mail_index_header *hdr, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
71 struct mail_search_arg *args, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
72 uint32_t *seq1_r, uint32_t *seq2_r, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
73 bool not); |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
74 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
75 static int seqset_contains(struct mail_search_seqset *set, uint32_t seq) |
0 | 76 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
77 while (set != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
78 if (seq >= set->seq1 && seq <= set->seq2) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
79 return TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
80 set = set->next; |
0 | 81 } |
82 | |
83 return FALSE; | |
84 } | |
85 | |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
46
diff
changeset
|
86 static uoff_t str_to_uoff_t(const char *str) |
46 | 87 { |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
46
diff
changeset
|
88 uoff_t num; |
46 | 89 |
90 num = 0; | |
91 while (*str != '\0') { | |
92 if (*str < '0' || *str > '9') | |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
46
diff
changeset
|
93 return 0; |
46 | 94 |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
46
diff
changeset
|
95 num = num*10 + (*str - '0'); |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
96 str++; |
46 | 97 } |
98 | |
99 return num; | |
100 } | |
101 | |
0 | 102 /* Returns >0 = matched, 0 = not matched, -1 = unknown */ |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
103 static int search_arg_match_index(struct index_mail *imail, |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
104 enum mail_search_arg_type type, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
105 const char *value) |
0 | 106 { |
1947 | 107 const struct mail_index_record *rec = imail->data.rec; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
108 const char *const *keywords; |
1947 | 109 |
0 | 110 switch (type) { |
111 /* flags */ | |
112 case SEARCH_ANSWERED: | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
113 return rec->flags & MAIL_ANSWERED; |
0 | 114 case SEARCH_DELETED: |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
115 return rec->flags & MAIL_DELETED; |
0 | 116 case SEARCH_DRAFT: |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
117 return rec->flags & MAIL_DRAFT; |
0 | 118 case SEARCH_FLAGGED: |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
119 return rec->flags & MAIL_FLAGGED; |
0 | 120 case SEARCH_SEEN: |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
121 return rec->flags & MAIL_SEEN; |
0 | 122 case SEARCH_RECENT: |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
123 return mail_get_flags(&imail->mail.mail) & MAIL_RECENT; |
0 | 124 case SEARCH_KEYWORD: |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
125 keywords = mail_get_keywords(&imail->mail.mail); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
126 if (keywords != NULL) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
127 while (*keywords != NULL) { |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
128 if (strcasecmp(*keywords, value) == 0) |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
129 return 1; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
130 keywords++; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
131 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
132 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
133 return 0; |
0 | 134 |
135 default: | |
136 return -1; | |
137 } | |
138 } | |
139 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
140 static void search_init_seqset_arg(struct mail_search_arg *arg, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
141 struct index_search_context *ctx) |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
142 { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
143 switch (arg->type) { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
144 case SEARCH_SEQSET: |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
145 ctx->have_seqsets = TRUE; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
146 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
147 case SEARCH_ALL: |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
148 if (!arg->not) |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
149 arg->match_always = TRUE; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
150 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
151 default: |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
152 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
153 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
154 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
155 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
156 static void search_seqset_arg(struct mail_search_arg *arg, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
157 struct index_search_context *ctx) |
0 | 158 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
159 if (arg->type == SEARCH_SEQSET) { |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
160 if (seqset_contains(arg->value.seqset, ctx->mail_ctx.seq)) |
3873
31d8f49b1a34
Compiler warning fixes and one real fix for int -> bool changes.
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
161 ARG_SET_RESULT(arg, 1); |
31d8f49b1a34
Compiler warning fixes and one real fix for int -> bool changes.
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
162 else |
31d8f49b1a34
Compiler warning fixes and one real fix for int -> bool changes.
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
163 ARG_SET_RESULT(arg, 0); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
164 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
165 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
166 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
167 static void search_index_arg(struct mail_search_arg *arg, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
168 struct index_search_context *ctx) |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
169 { |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
170 if (ctx->imail->data.rec == NULL) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
171 /* expunged message */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
172 ARG_SET_RESULT(arg, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
173 return; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
174 } |
0 | 175 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
176 switch (search_arg_match_index(ctx->imail, arg->type, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
177 arg->value.str)) { |
0 | 178 case -1: |
179 /* unknown */ | |
180 break; | |
181 case 0: | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
182 ARG_SET_RESULT(arg, 0); |
0 | 183 break; |
184 default: | |
185 ARG_SET_RESULT(arg, 1); | |
186 break; | |
187 } | |
188 } | |
189 | |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
190 /* Returns >0 = matched, 0 = not matched, -1 = unknown */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
191 static int search_arg_match_cached(struct index_search_context *ctx, |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
192 enum mail_search_arg_type type, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
193 const char *value) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
194 { |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
195 time_t date, search_time; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
196 uoff_t virtual_size, search_size; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
197 int timezone_offset; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
198 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
199 switch (type) { |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
200 /* internal dates */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
201 case SEARCH_BEFORE: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
202 case SEARCH_ON: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
203 case SEARCH_SINCE: |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
204 date = mail_get_received_date(ctx->mail); |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
205 if (date == (time_t)-1) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
206 return -1; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
207 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
208 if (!imap_parse_date(value, &search_time)) |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
209 return 0; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
210 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
211 switch (type) { |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
212 case SEARCH_BEFORE: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
213 return date < search_time; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
214 case SEARCH_ON: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
215 return date >= search_time && |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
216 date < search_time + 3600*24; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
217 case SEARCH_SINCE: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
218 return date >= search_time; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
219 default: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
220 /* unreachable */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
221 break; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
222 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
223 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
224 /* sent dates */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
225 case SEARCH_SENTBEFORE: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
226 case SEARCH_SENTON: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
227 case SEARCH_SENTSINCE: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
228 /* NOTE: RFC-3501 specifies that timezone is ignored |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
229 in searches. date is returned as UTC, so change it. */ |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
230 date = mail_get_date(ctx->mail, &timezone_offset); |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
231 if (date == (time_t)-1) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
232 return -1; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
233 date += timezone_offset * 60; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
234 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
235 if (!imap_parse_date(value, &search_time)) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
236 return 0; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
237 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
238 switch (type) { |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
239 case SEARCH_SENTBEFORE: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
240 return date < search_time; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
241 case SEARCH_SENTON: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
242 return date >= search_time && |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
243 date < search_time + 3600*24; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
244 case SEARCH_SENTSINCE: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
245 return date >= search_time; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
246 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
247 /* unreachable */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
248 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
249 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
250 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
251 /* sizes */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
252 case SEARCH_SMALLER: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
253 case SEARCH_LARGER: |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
254 virtual_size = mail_get_virtual_size(ctx->mail); |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
255 if (virtual_size == (uoff_t)-1) |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
256 return -1; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
257 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
258 search_size = str_to_uoff_t(value); |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
259 if (type == SEARCH_SMALLER) |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
260 return virtual_size < search_size; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
261 else |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
262 return virtual_size > search_size; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
263 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
264 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
265 return -1; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
266 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
267 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
268 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
269 static void search_cached_arg(struct mail_search_arg *arg, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
270 struct index_search_context *ctx) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
271 { |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
272 switch (search_arg_match_cached(ctx, arg->type, |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
273 arg->value.str)) { |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
274 case -1: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
275 /* unknown */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
276 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
277 case 0: |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
278 ARG_SET_RESULT(arg, 0); |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
279 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
280 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
281 ARG_SET_RESULT(arg, 1); |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
282 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
283 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
284 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
285 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
286 static int search_sent(enum mail_search_arg_type type, const char *search_value, |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
287 const unsigned char *sent_value, size_t sent_value_len) |
0 | 288 { |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
289 time_t search_time, sent_time; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
290 int timezone_offset; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
291 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
292 if (sent_value == NULL) |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
293 return 0; |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
294 |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
295 if (!imap_parse_date(search_value, &search_time)) |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
296 return 0; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
297 |
1340
087a9f4304ca
s/latest IMAP4rev1 draft/RFC-3501/
Timo Sirainen <tss@iki.fi>
parents:
1322
diff
changeset
|
298 /* NOTE: RFC-3501 specifies that timezone is ignored |
935
bd2d99a3d601
Even more rfc822 date timezone fixes
Timo Sirainen <tss@iki.fi>
parents:
934
diff
changeset
|
299 in searches. sent_time is returned as UTC, so change it. */ |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
300 if (!message_date_parse(sent_value, sent_value_len, |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
301 &sent_time, &timezone_offset)) |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
302 return 0; |
1604 | 303 sent_time += timezone_offset * 60; |
0 | 304 |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
305 switch (type) { |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
306 case SEARCH_SENTBEFORE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
307 return sent_time < search_time; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
308 case SEARCH_SENTON: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
309 return sent_time >= search_time && |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
310 sent_time < search_time + 3600*24; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
311 case SEARCH_SENTSINCE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
312 return sent_time >= search_time; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
313 default: |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
534
diff
changeset
|
314 i_unreached(); |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
315 } |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
316 } |
0 | 317 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
318 static struct search_arg_context * |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
319 search_arg_context(struct index_search_context *ctx, |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
320 struct mail_search_arg *arg) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
321 { |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
322 struct search_arg_context *arg_ctx = arg->context; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
323 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
324 if (arg_ctx != NULL) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
325 return arg_ctx; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
326 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
327 if (ctx->search_pool == NULL) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
328 ctx->search_pool = pool_alloconly_create("search pool", 8192); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
329 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
330 arg_ctx = p_new(ctx->search_pool, struct search_arg_context, 1); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
331 arg->context = arg_ctx; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
332 return arg_ctx; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
333 } |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
334 |
5505 | 335 static struct message_header_search_context * |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
336 search_header_context(struct index_search_context *ctx, |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
337 struct mail_search_arg *arg) |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
338 { |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
339 struct search_arg_context *arg_ctx; |
5505 | 340 int ret; |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
341 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
342 arg_ctx = search_arg_context(ctx, arg); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
343 if (arg_ctx->hdr_search_ctx != NULL) { |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
344 message_header_search_reset(arg_ctx->hdr_search_ctx); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
345 return arg_ctx->hdr_search_ctx; |
0 | 346 } |
347 | |
5505 | 348 ret = message_header_search_init(ctx->search_pool, arg->value.str, |
349 ctx->mail_ctx.charset, | |
350 &arg_ctx->hdr_search_ctx); | |
351 if (ret > 0) | |
352 return arg_ctx->hdr_search_ctx; | |
353 if (ret == 0) | |
354 ctx->error = TXT_UNKNOWN_CHARSET; | |
355 else | |
356 ctx->error = TXT_INVALID_SEARCH_KEY; | |
357 return NULL; | |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
358 } |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
359 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
360 static struct message_body_search_context * |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
361 search_body_context(struct index_search_context *ctx, |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
362 struct mail_search_arg *arg) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
363 { |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
364 struct search_arg_context *arg_ctx; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
365 int ret; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
366 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
367 arg_ctx = search_arg_context(ctx, arg); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
368 if (arg_ctx->body_search_ctx != NULL) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
369 return arg_ctx->body_search_ctx; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
370 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
371 ret = message_body_search_init(ctx->search_pool, arg->value.str, |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
372 ctx->mail_ctx.charset, |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
373 arg->type == SEARCH_TEXT || |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
374 arg->type == SEARCH_TEXT_FAST, |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
375 &arg_ctx->body_search_ctx); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
376 if (ret > 0) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
377 return arg_ctx->body_search_ctx; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
378 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
379 if (ret == 0) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
380 ctx->error = TXT_UNKNOWN_CHARSET; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
381 else |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
382 ctx->error = TXT_INVALID_SEARCH_KEY; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
383 return NULL; |
0 | 384 } |
385 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
386 static void search_header_arg(struct mail_search_arg *arg, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
387 struct search_header_context *ctx) |
0 | 388 { |
5505 | 389 struct message_header_search_context *hdr_search_ctx; |
0 | 390 int ret; |
391 | |
392 /* first check that the field name matches to argument. */ | |
393 switch (arg->type) { | |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
394 case SEARCH_SENTBEFORE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
395 case SEARCH_SENTON: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
396 case SEARCH_SENTSINCE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
397 /* date is handled differently than others */ |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
398 if (strcasecmp(ctx->hdr->name, "Date") == 0) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
399 if (ctx->hdr->continues) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
400 ctx->hdr->use_full_value = TRUE; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
401 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
402 } |
1070 | 403 ret = search_sent(arg->type, arg->value.str, |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
404 ctx->hdr->full_value, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
405 ctx->hdr->full_value_len); |
1070 | 406 ARG_SET_RESULT(arg, ret); |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
407 } |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
408 return; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
409 |
0 | 410 case SEARCH_HEADER: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
411 case SEARCH_HEADER_ADDRESS: |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
412 ctx->custom_header = TRUE; |
0 | 413 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
414 if (strcasecmp(ctx->hdr->name, arg->hdr_field_name) != 0) |
0 | 415 return; |
5513 | 416 break; |
0 | 417 default: |
418 return; | |
419 } | |
420 | |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
421 if (arg->value.str[0] == '\0') { |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
422 /* we're just testing existence of the field. always matches. */ |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
423 ret = 1; |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
424 } else { |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
425 if (ctx->hdr->continues) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
426 ctx->hdr->use_full_value = TRUE; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
427 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
428 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
429 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
430 t_push(); |
765
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
764
diff
changeset
|
431 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
432 hdr_search_ctx = search_header_context(ctx->index_context, arg); |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
433 if (hdr_search_ctx == NULL) |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
434 ret = 0; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
435 else if (arg->type == SEARCH_HEADER_ADDRESS) { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
436 /* we have to match against normalized address */ |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
437 struct message_address *addr; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
438 string_t *str; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
439 |
1782
2f3d906d99d8
data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents:
1765
diff
changeset
|
440 addr = message_address_parse(pool_datastack_create(), |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
441 ctx->hdr->full_value, |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
442 ctx->hdr->full_value_len, |
4635
210bb1ff0e6e
Added fill_missing parameter to message_address_parse() which specifies if
Timo Sirainen <tss@iki.fi>
parents:
4607
diff
changeset
|
443 (unsigned int)-1, TRUE); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
444 str = t_str_new(ctx->hdr->value_len); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
445 message_address_write(str, addr); |
5505 | 446 ret = message_header_search(hdr_search_ctx, |
447 str_data(str), | |
448 str_len(str)) ? 1 : 0; | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
449 } else { |
5505 | 450 if (message_header_search(hdr_search_ctx, |
451 ctx->hdr->full_value, | |
452 ctx->hdr->full_value_len)) | |
453 ret = 1; | |
454 else | |
455 ret = 0; | |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
456 } |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
457 t_pop(); |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
458 } |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
459 |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
460 if (ret == 1 || |
5507
65250cfebd74
Don't handle TEXT searches in header searches. It's done later anyway.
Timo Sirainen <tss@iki.fi>
parents:
5505
diff
changeset
|
461 (arg->type != SEARCH_HEADER && |
65250cfebd74
Don't handle TEXT searches in header searches. It's done later anyway.
Timo Sirainen <tss@iki.fi>
parents:
5505
diff
changeset
|
462 arg->type != SEARCH_HEADER_ADDRESS)) { |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
463 /* set only when we definitely know if it's a match */ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
464 ARG_SET_RESULT(arg, ret); |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
465 } |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
466 } |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
467 |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
468 static void search_header_unmatch(struct mail_search_arg *arg, |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
469 void *context __attr_unused__) |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
470 { |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
471 switch (arg->type) { |
1070 | 472 case SEARCH_SENTBEFORE: |
473 case SEARCH_SENTON: | |
474 case SEARCH_SENTSINCE: | |
475 if (arg->not) { | |
476 /* date header not found, so we match only for | |
477 NOT searches */ | |
478 ARG_SET_RESULT(arg, 0); | |
479 } | |
480 break; | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
481 case SEARCH_HEADER: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
482 case SEARCH_HEADER_ADDRESS: |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
483 ARG_SET_RESULT(arg, 0); |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
484 break; |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
485 default: |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
486 break; |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
487 } |
0 | 488 } |
489 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
490 static void search_header(struct message_header_line *hdr, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
491 struct search_header_context *ctx) |
0 | 492 { |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
493 if (hdr == NULL) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
494 /* end of headers, mark all unknown SEARCH_HEADERs unmatched */ |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
495 mail_search_args_foreach(ctx->args, search_header_unmatch, ctx); |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
496 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
497 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
498 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
499 if (hdr->eoh) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
500 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
501 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
502 if (ctx->parse_headers) |
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
503 index_mail_parse_header(NULL, hdr, ctx->index_context->imail); |
924
4f697dde0fca
THREAD=REFERENCES implementation. Doesn't crash, but I'm not sure how
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
504 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
505 if (ctx->custom_header || strcasecmp(hdr->name, "Date") == 0) { |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
506 ctx->hdr = hdr; |
0 | 507 |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
508 ctx->custom_header = FALSE; |
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
509 mail_search_args_foreach(ctx->args, search_header_arg, ctx); |
0 | 510 } |
511 } | |
512 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
513 static void search_body(struct mail_search_arg *arg, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
514 struct search_body_context *ctx) |
0 | 515 { |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
516 struct message_body_search_context *body_search_ctx; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3795
diff
changeset
|
517 int ret; |
0 | 518 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
519 if (ctx->index_ctx->error != NULL) |
0 | 520 return; |
521 | |
4942
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
522 switch (arg->type) { |
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
523 case SEARCH_BODY: |
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
524 case SEARCH_BODY_FAST: |
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
525 case SEARCH_TEXT: |
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
526 case SEARCH_TEXT_FAST: |
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
527 break; |
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
528 default: |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
529 return; |
4942
b382b21409b5
Added support for X-BODY-FAST and X-TEXT-FAST SEARCH arguments. FTS plugin
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
530 } |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
531 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
532 body_search_ctx = search_body_context(ctx->index_ctx, arg); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
533 if (body_search_ctx == NULL) { |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
534 ARG_SET_RESULT(arg, 0); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
535 return; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
536 } |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
537 |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
538 i_stream_seek(ctx->input, 0); |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
539 ret = message_body_search(body_search_ctx, ctx->input, ctx->part); |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
540 if (ret < 0) { |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
541 mail_cache_set_corrupted(ctx->index_ctx->ibox->cache, |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
542 "Broken message structure for mail UID %u", |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
543 ctx->index_ctx->mail->uid); |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
544 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
545 /* get the body parts, and try again */ |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
546 ctx->index_ctx->imail->data.parts = NULL; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
547 ctx->part = mail_get_parts(ctx->index_ctx->mail); |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
548 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
549 i_stream_seek(ctx->input, 0); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
550 ret = message_body_search(body_search_ctx, |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
551 ctx->input, ctx->part); |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
552 if (ret < 0) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
553 i_panic("Couldn't fix broken body structure"); |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
554 } |
290
3dcc2275b4ca
IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
555 |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
556 ARG_SET_RESULT(arg, ret > 0); |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
557 } |
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
558 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3795
diff
changeset
|
559 static bool search_arg_match_text(struct mail_search_arg *args, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3795
diff
changeset
|
560 struct index_search_context *ctx) |
0 | 561 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
562 struct istream *input; |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
563 struct mailbox_header_lookup_ctx *headers_ctx; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
564 const char *const *headers; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3795
diff
changeset
|
565 bool have_headers, have_body; |
0 | 566 |
567 /* first check what we need to use */ | |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
568 headers = mail_search_args_analyze(args, &have_headers, &have_body); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
569 if (!have_headers && !have_body) |
0 | 570 return TRUE; |
571 | |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
572 if (have_headers) { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
573 struct search_header_context hdr_ctx; |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
574 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
575 if (have_body) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
576 headers = NULL; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
577 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
578 if (headers == NULL) { |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
579 headers_ctx = NULL; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
580 input = mail_get_stream(ctx->mail, NULL, NULL); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
581 if (input == NULL) |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
582 return FALSE; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
583 } else { |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
584 /* FIXME: do this once in init */ |
3301
dd19f2e8575f
Don't even try to allow searching zero number of headers.
Timo Sirainen <tss@iki.fi>
parents:
3248
diff
changeset
|
585 i_assert(*headers != NULL); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
586 headers_ctx = |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
587 mailbox_header_lookup_init(&ctx->ibox->box, |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
588 headers); |
3248
ff47e78ad717
Renamed mail_get_header() to mail_get_first_header() and mail_gets_headers()
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
589 input = mail_get_header_stream(ctx->mail, headers_ctx); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
590 if (input == NULL) { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3873
diff
changeset
|
591 mailbox_header_lookup_deinit(&headers_ctx); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
592 return FALSE; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
593 } |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
594 } |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
595 |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
596 memset(&hdr_ctx, 0, sizeof(hdr_ctx)); |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
597 hdr_ctx.index_context = ctx; |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
598 hdr_ctx.custom_header = TRUE; |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
599 hdr_ctx.args = args; |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
600 hdr_ctx.parse_headers = headers == NULL; |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
601 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
602 index_mail_parse_header_init(ctx->imail, headers_ctx); |
4259
fd315deac28f
Rewrote the message bodystructure parser to allow parsing from non-blocking streams. Also did a couple of API changes and cleanups.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4222
diff
changeset
|
603 message_parse_header(input, NULL, search_header, &hdr_ctx); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
604 if (headers_ctx != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3873
diff
changeset
|
605 mailbox_header_lookup_deinit(&headers_ctx); |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
606 } else { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
607 struct message_size hdr_size; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
608 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
609 input = mail_get_stream(ctx->mail, &hdr_size, NULL); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
610 if (input == NULL) |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
611 return FALSE; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
612 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
613 i_stream_seek(input, hdr_size.physical_size); |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
614 } |
0 | 615 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
616 if (have_body) { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
617 struct search_body_context body_ctx; |
0 | 618 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
619 memset(&body_ctx, 0, sizeof(body_ctx)); |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
620 body_ctx.index_ctx = ctx; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
761
diff
changeset
|
621 body_ctx.input = input; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
622 body_ctx.part = mail_get_parts(ctx->mail); |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
623 |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
624 mail_search_args_foreach(args, search_body, &body_ctx); |
0 | 625 } |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
626 return TRUE; |
0 | 627 } |
628 | |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
629 static void update_seqs(const struct mail_search_seqset *set, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
630 const struct mail_index_header *hdr, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
631 uint32_t *seq1_r, uint32_t *seq2_r, bool not) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
632 { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
633 if (!not) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
634 /* seq1..seq2 */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
635 if (*seq1_r < set->seq1 || *seq1_r == 0) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
636 *seq1_r = set->seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
637 if (*seq2_r > set->seq2) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
638 *seq2_r = set->seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
639 } else { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
640 if (set->seq1 == 1) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
641 /* seq2+1..count */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
642 if (set->seq2 == hdr->messages_count) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
643 /* completely outside our range */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
644 *seq1_r = (uint32_t)-1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
645 *seq2_r = 0; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
646 } else { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
647 if (*seq1_r < set->seq2 + 1) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
648 *seq1_r = set->seq2 + 1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
649 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
650 } else if (set->seq2 == hdr->messages_count) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
651 /* 1..seq1-1 */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
652 if (*seq2_r > set->seq1 - 1) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
653 *seq2_r = set->seq1 - 1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
654 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
655 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
656 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
657 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
658 static int search_msgset_fix(struct index_mailbox *ibox, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
659 const struct mail_index_header *hdr, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
660 struct mail_search_seqset *set, |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
661 uint32_t *seq1_r, uint32_t *seq2_r, bool not) |
0 | 662 { |
4439
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
663 struct mail_search_seqset full_set; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
664 uint32_t min_seq = (uint32_t)-1, max_seq = 0; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
665 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
666 for (; set != NULL; set = set->next) { |
3467
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
667 if (set->seq1 > hdr->messages_count) { |
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
668 if (set->seq1 != (uint32_t)-1 && |
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
669 set->seq2 != (uint32_t)-1) { |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
670 set->seq1 = set->seq2 = 0; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
671 if (not) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
672 continue; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
673 |
3467
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
674 /* completely outside our range */ |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
675 *seq1_r = (uint32_t)-1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
676 *seq2_r = 0; |
3467
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
677 return 0; |
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
678 } |
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
679 /* either seq1 or seq2 is '*', so the last message is |
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
680 in range. */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
681 set->seq1 = hdr->messages_count; |
3467
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
682 } |
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
683 if (set->seq2 > hdr->messages_count) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
684 set->seq2 = hdr->messages_count; |
0 | 685 |
3467
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
686 if (set->seq1 == 0 || set->seq2 == 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
687 mail_storage_set_syntax_error(ibox->box.storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
688 "Invalid messageset"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
689 return -1; |
0 | 690 } |
691 | |
4439
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
692 if (set->seq1 < min_seq) |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
693 min_seq = set->seq1; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
694 if (set->seq2 > max_seq) |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
695 max_seq = set->seq2; |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
696 } |
4439
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
697 |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
698 full_set.seq1 = min_seq; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
699 full_set.seq2 = max_seq; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
700 full_set.next = NULL; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
701 update_seqs(&full_set, hdr, seq1_r, seq2_r, not); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
702 return 0; |
0 | 703 } |
704 | |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
705 static int search_or_parse_msgset_args(struct index_mailbox *ibox, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
706 const struct mail_index_header *hdr, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
707 struct mail_search_arg *args, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
708 uint32_t *seq1_r, uint32_t *seq2_r, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
709 bool not) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
710 { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
711 uint32_t seq1, seq2, min_seq1 = 0, max_seq2 = 0; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
712 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
713 for (; args != NULL; args = args->next) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
714 bool cur_not = args->not; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
715 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
716 if (not) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
717 cur_not = !cur_not; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
718 seq1 = 1; seq2 = hdr->messages_count; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
719 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
720 if (args->type == SEARCH_SUB) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
721 if (search_parse_msgset_args(ibox, hdr, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
722 args->value.subargs, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
723 &seq1, &seq2, cur_not) < 0) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
724 return -1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
725 } else if (args->type == SEARCH_OR) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
726 if (search_or_parse_msgset_args(ibox, hdr, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
727 args->value.subargs, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
728 &seq1, &seq2, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
729 cur_not) < 0) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
730 return -1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
731 } else if (args->type == SEARCH_SEQSET) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
732 if (search_msgset_fix(ibox, hdr, args->value.seqset, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
733 &seq1, &seq2, cur_not) < 0) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
734 return -1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
735 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
736 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
737 if (min_seq1 == 0) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
738 min_seq1 = seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
739 max_seq2 = seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
740 } else { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
741 if (seq1 < min_seq1) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
742 min_seq1 = seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
743 if (seq2 > max_seq2) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
744 max_seq2 = seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
745 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
746 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
747 i_assert(min_seq1 != 0); |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
748 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
749 if (min_seq1 > *seq1_r) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
750 *seq1_r = min_seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
751 if (max_seq2 < *seq2_r) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
752 *seq2_r = max_seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
753 return 0; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
754 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
755 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
756 static int search_parse_msgset_args(struct index_mailbox *ibox, |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
757 const struct mail_index_header *hdr, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
758 struct mail_search_arg *args, |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
759 uint32_t *seq1_r, uint32_t *seq2_r, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
760 bool not) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
761 { |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
762 for (; args != NULL; args = args->next) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
763 bool cur_not = args->not; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
764 |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
765 if (not) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
766 cur_not = !cur_not; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
767 |
1376 | 768 if (args->type == SEARCH_SUB) { |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
769 if (search_parse_msgset_args(ibox, hdr, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
770 args->value.subargs, |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
771 seq1_r, seq2_r, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
772 cur_not) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
773 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
774 } else if (args->type == SEARCH_OR) { |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
775 /* go through our children and use the widest seqset |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
776 range */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
777 if (search_or_parse_msgset_args(ibox, hdr, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
778 args->value.subargs, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
779 seq1_r, seq2_r, |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
780 cur_not) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
781 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
782 } else if (args->type == SEARCH_SEQSET) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
783 if (search_msgset_fix(ibox, hdr, args->value.seqset, |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
784 seq1_r, seq2_r, cur_not) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
785 return -1; |
0 | 786 } |
787 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
788 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
789 } |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
790 |
2224
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
791 static int search_limit_lowwater(struct index_search_context *ctx, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
792 uint32_t uid_lowwater, uint32_t *first_seq) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
793 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
794 uint32_t seq1, seq2; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
795 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
796 if (uid_lowwater == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
797 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
798 |
2224
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
799 if (mail_index_lookup_uid_range(ctx->view, uid_lowwater, |
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
800 (uint32_t)-1, &seq1, &seq2) < 0) { |
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
801 mail_storage_set_index_error(ctx->ibox); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
802 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
803 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
804 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
805 if (*first_seq < seq1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
806 *first_seq = seq1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
807 return 0; |
0 | 808 } |
809 | |
2224
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
810 static int search_limit_by_flags(struct index_search_context *ctx, |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
811 const struct mail_index_header *hdr, |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
812 struct mail_search_arg *args, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
813 uint32_t *seq1, uint32_t *seq2) |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
814 { |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
815 for (; args != NULL; args = args->next) { |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
816 switch (args->type) { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
817 case SEARCH_SEEN: |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
818 /* SEEN with 0 seen? */ |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
819 if (!args->not && hdr->seen_messages_count == 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
820 return 0; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
821 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
822 if (hdr->seen_messages_count == hdr->messages_count) { |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
823 /* UNSEEN with all seen? */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
824 if (args->not) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
825 return 0; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
826 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
827 /* SEEN with all seen */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
828 args->match_always = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
829 } else if (args->not) { |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
830 /* UNSEEN with lowwater limiting */ |
2224
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
831 if (search_limit_lowwater(ctx, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
832 hdr->first_unseen_uid_lowwater, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
833 seq1) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
834 return -1; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
835 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
836 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
837 case SEARCH_DELETED: |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
838 /* DELETED with 0 deleted? */ |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
839 if (!args->not && hdr->deleted_messages_count == 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
840 return 0; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
841 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
842 if (hdr->deleted_messages_count == |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
843 hdr->messages_count) { |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
844 /* UNDELETED with all deleted? */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
845 if (args->not) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
846 return 0; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
847 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
848 /* DELETED with all deleted */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
849 args->match_always = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
850 } else if (!args->not) { |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
851 /* DELETED with lowwater limiting */ |
2224
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
852 if (search_limit_lowwater(ctx, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
853 hdr->first_deleted_uid_lowwater, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
854 seq1) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
855 return -1; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
856 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
857 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
858 case SEARCH_ALL: |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
859 if (args->not) |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
860 return 0; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
861 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
862 default: |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
863 break; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
864 } |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
865 } |
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
866 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
867 return *seq1 <= *seq2; |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
868 } |
0 | 869 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
870 static int search_get_seqset(struct index_search_context *ctx, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
871 struct mail_search_arg *args) |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
872 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
873 const struct mail_index_header *hdr; |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
874 int ret; |
0 | 875 |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2883
diff
changeset
|
876 hdr = mail_index_get_header(ctx->view); |
1985
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
877 if (hdr->messages_count == 0) { |
2899
1a05764af1e0
UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
878 /* no messages, don't check sequence ranges. although we could |
1a05764af1e0
UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
879 give error message then for FETCH, we shouldn't do it for |
1a05764af1e0
UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
880 UID FETCH. */ |
1985
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
881 ctx->seq1 = 1; |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
882 ctx->seq2 = 0; |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
883 return 0; |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
884 } |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
885 |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
886 ctx->seq1 = 1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
887 ctx->seq2 = hdr->messages_count; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
888 |
2899
1a05764af1e0
UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
889 if (search_parse_msgset_args(ctx->ibox, hdr, args, |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
890 &ctx->seq1, &ctx->seq2, FALSE) < 0) |
2899
1a05764af1e0
UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
891 return -1; |
1a05764af1e0
UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
892 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
893 if (ctx->seq1 == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
894 ctx->seq1 = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
895 ctx->seq2 = hdr->messages_count; |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
896 } |
4438
00db36e1b734
Don't crash when different search conditions reduce the search range so that
Timo Sirainen <tss@iki.fi>
parents:
4432
diff
changeset
|
897 if (ctx->seq1 > ctx->seq2) { |
4432
c13d8fe698f8
Don't crash if seqset restrictions caused no messages to be searched.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4431
diff
changeset
|
898 /* no matches */ |
c13d8fe698f8
Don't crash if seqset restrictions caused no messages to be searched.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4431
diff
changeset
|
899 return 0; |
c13d8fe698f8
Don't crash if seqset restrictions caused no messages to be searched.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4431
diff
changeset
|
900 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
901 |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
902 /* UNSEEN and DELETED in root search level may limit the range */ |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
903 ret = search_limit_by_flags(ctx, hdr, args, &ctx->seq1, &ctx->seq2); |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
904 if (ret < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
905 return -1; |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
906 if (ret == 0) { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
907 /* no matches */ |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
908 ctx->seq1 = 1; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
909 ctx->seq2 = 0; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
910 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
911 return 0; |
0 | 912 } |
913 | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
914 struct mail_search_context * |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
915 index_storage_search_init(struct mailbox_transaction_context *_t, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
916 const char *charset, struct mail_search_arg *args, |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
917 const enum mail_sort_type *sort_program) |
0 | 918 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
919 struct index_transaction_context *t = |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
920 (struct index_transaction_context *)_t; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
921 struct index_search_context *ctx; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
922 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
923 ctx = i_new(struct index_search_context, 1); |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
924 ctx->mail_ctx.transaction = _t; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
925 ctx->ibox = t->ibox; |
2224
a816e2d88406
Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
926 ctx->view = t->trans_view; |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
927 ctx->mail_ctx.charset = i_strdup(charset); |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
928 ctx->mail_ctx.args = args; |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
929 ctx->mail_ctx.sort_program = index_sort_program_init(_t, sort_program); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
930 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
931 array_create(&ctx->mail_ctx.module_contexts, default_pool, |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
932 sizeof(void *), 5); |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
933 |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
934 mail_search_args_reset(ctx->mail_ctx.args, TRUE); |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
935 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
936 if (search_get_seqset(ctx, args) < 0) { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
937 ctx->failed = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
938 ctx->seq1 = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
939 ctx->seq2 = 0; |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
940 } else { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
941 (void)mail_search_args_foreach(args, search_init_seqset_arg, |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
942 ctx); |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
943 /* Need to reset results for match_always cases */ |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
944 mail_search_args_reset(ctx->mail_ctx.args, FALSE); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
945 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
946 return &ctx->mail_ctx; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
947 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
948 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
949 int index_storage_search_deinit(struct mail_search_context *_ctx) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
950 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
951 struct index_search_context *ctx = (struct index_search_context *)_ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
952 int ret; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
953 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
954 ret = ctx->failed || ctx->error != NULL ? -1 : 0; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
955 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
956 if (ctx->error != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
957 mail_storage_set_error(ctx->ibox->box.storage, |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
958 "%s", ctx->error); |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
959 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
960 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
961 if (ctx->search_pool != NULL) |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
962 pool_unref(ctx->search_pool); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
963 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
964 if (ctx->mail_ctx.sort_program != NULL) |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
965 index_sort_program_deinit(&ctx->mail_ctx.sort_program); |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
966 array_free(&ctx->mail_ctx.module_contexts); |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
967 i_free(ctx->mail_ctx.charset); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
968 i_free(ctx); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
969 return ret; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
970 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
971 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3795
diff
changeset
|
972 static bool search_match_next(struct index_search_context *ctx) |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
973 { |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
974 struct mail_search_arg *arg; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
975 int ret; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
976 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
977 /* check the index matches first */ |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
978 ret = mail_search_args_foreach(ctx->mail_ctx.args, |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
979 search_index_arg, ctx); |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
980 if (ret >= 0) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
981 return ret > 0; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
982 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
983 if (ctx->imail->data.rec == NULL) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
984 /* expunged message, no way to check if the rest would have |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
985 matched */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
986 return FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
987 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
988 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
989 /* next search only from cached arguments */ |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
990 ret = mail_search_args_foreach(ctx->mail_ctx.args, |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
991 search_cached_arg, ctx); |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
992 if (ret >= 0) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
993 return ret > 0; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
994 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
995 /* open the mail file and check the rest */ |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
996 if (!search_arg_match_text(ctx->mail_ctx.args, ctx)) |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
997 return FALSE; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
998 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
999 for (arg = ctx->mail_ctx.args; arg != NULL; arg = arg->next) { |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1000 if (arg->result != 1) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1001 return FALSE; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1002 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1003 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1004 return TRUE; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1005 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1006 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1007 static void index_storage_search_notify(struct mailbox *box, |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1008 struct index_search_context *ctx) |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1009 { |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1010 const struct mail_index_header *hdr; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1011 const char *text; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1012 float percentage; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1013 unsigned int msecs, secs; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1014 |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1015 if (ctx->last_notify.tv_sec == 0) { |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1016 /* set the search time in here, in case a plugin |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1017 already spent some time indexing the mailbox */ |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1018 ctx->search_start_time = ioloop_timeval; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1019 } else if (box->storage->callbacks->notify_ok != NULL) { |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1020 hdr = mail_index_get_header(ctx->ibox->view); |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1021 |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1022 percentage = ctx->mail->seq * 100.0 / hdr->messages_count; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1023 msecs = (ioloop_timeval.tv_sec - |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1024 ctx->search_start_time.tv_sec) * 1000 + |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1025 (ioloop_timeval.tv_usec - |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1026 ctx->search_start_time.tv_usec) / 1000; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1027 secs = (msecs / (percentage / 100.0) - msecs) / 1000; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1028 |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1029 t_push(); |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1030 text = t_strdup_printf("Searched %d%% of the mailbox, " |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1031 "ETA %d:%02d", (int)percentage, |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1032 secs/60, secs%60); |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1033 box->storage->callbacks-> |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1034 notify_ok(box, text, box->storage->callback_context); |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1035 t_pop(); |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1036 } |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1037 ctx->last_notify = ioloop_timeval; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1038 } |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1039 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1040 int index_storage_search_next_nonblock(struct mail_search_context *_ctx, |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1041 struct mail *mail, bool *tryagain_r) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
1042 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
1043 struct index_search_context *ctx = (struct index_search_context *)_ctx; |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1044 struct mailbox *box = _ctx->transaction->box; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1045 unsigned int count = 0; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1046 int ret; |
0 | 1047 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1048 *tryagain_r = FALSE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1049 |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1050 if (ctx->sorted) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1051 /* everything searched at this point already. just returning |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1052 matches from sort list */ |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1053 return index_sort_list_next(ctx->mail_ctx.sort_program, mail); |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1054 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1055 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
1056 ctx->mail = mail; |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
1057 ctx->imail = (struct index_mail *)mail; |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
1058 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1059 if (ioloop_time - ctx->last_notify.tv_sec >= |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1060 SEARCH_NOTIFY_INTERVAL_SECS) |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1061 index_storage_search_notify(box, ctx); |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1062 |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1063 while ((ret = box->v.search_next_update_seq(_ctx)) > 0) { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1064 if (mail_set_seq(mail, _ctx->seq) < 0) { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1065 ret = -1; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
1066 break; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1067 } |
453
0f6fd6802265
Modify log now stores the changes in ranges, so store 1:100 doesn't
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
1068 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1069 t_push(); |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1070 ret = search_match_next(ctx) ? 1 : 0; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1071 t_pop(); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1072 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1073 mail_search_args_reset(ctx->mail_ctx.args, FALSE); |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1074 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1075 if (ctx->error != NULL) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1076 ret = -1; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1077 if (ret != 0) { |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1078 if (ctx->mail_ctx.sort_program == NULL) |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1079 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1080 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1081 if (index_sort_list_add(ctx->mail_ctx.sort_program, |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1082 mail) < 0) { |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1083 ret = -1; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1084 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1085 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1086 } |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1087 |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1088 if (++count == SEARCH_NONBLOCK_COUNT) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1089 *tryagain_r = TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1090 return 0; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1091 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
1092 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1093 if (ret < 0) |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1094 ctx->failed = TRUE; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
1095 ctx->mail = NULL; |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
1096 ctx->imail = NULL; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1097 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1098 if (ctx->mail_ctx.sort_program != NULL && ret == 0) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1099 /* finished searching the messages. now sort them and start |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1100 returning the messages. */ |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1101 ctx->sorted = TRUE; |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1102 if (index_sort_list_finish(ctx->mail_ctx.sort_program) < 0) |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1103 return -1; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1104 return index_storage_search_next_nonblock(_ctx, mail, |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1105 tryagain_r); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1106 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1107 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
1108 return ret; |
0 | 1109 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1110 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1111 int index_storage_search_next_update_seq(struct mail_search_context *_ctx) |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1112 { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1113 struct index_search_context *ctx = (struct index_search_context *)_ctx; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1114 int ret; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1115 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1116 if (_ctx->seq == 0) { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1117 /* first time */ |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1118 _ctx->seq = ctx->seq1; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1119 } else { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1120 _ctx->seq++; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1121 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1122 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1123 if (!ctx->have_seqsets) |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1124 return _ctx->seq <= ctx->seq2 ? 1 : 0; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1125 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1126 ret = 0; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1127 while (_ctx->seq <= ctx->seq2) { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1128 /* check if the sequence matches */ |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1129 ret = mail_search_args_foreach(ctx->mail_ctx.args, |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1130 search_seqset_arg, ctx); |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1131 if (ret != 0) |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1132 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1133 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1134 /* doesn't, try next one */ |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1135 _ctx->seq++; |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
1136 mail_search_args_reset(ctx->mail_ctx.args, FALSE); |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1137 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1138 return ret == 0 ? 0 : 1; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1139 } |