Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/index-search.c @ 6280:eb7c9d8ece54 HEAD
mail_*() APIs changed to return int and return the actual data as pointer.
Changed some code to do error handling a bit better.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 12 Aug 2007 19:40:54 +0300 |
parents | 5f66277bbe40 |
children | 6a64e64fa3a3 |
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" |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
10 #include "message-search.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
11 #include "message-parser.h" |
0 | 12 #include "index-storage.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
13 #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
|
14 #include "index-sort.h" |
0 | 15 #include "mail-search.h" |
16 | |
17 #include <stdlib.h> | |
18 #include <ctype.h> | |
19 | |
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
|
20 #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
|
21 #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
|
22 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
23 #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
|
24 #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
|
25 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
26 struct index_search_context { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
27 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
|
28 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
|
29 struct index_mailbox *ibox; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
30 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
31 uint32_t seq1, seq2; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
32 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
|
33 struct index_mail *imail; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
34 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
35 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
|
36 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
|
37 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
38 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
|
39 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 }; |
0 | 44 |
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 struct search_header_context { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
46 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
|
47 struct mail_search_arg *args; |
0 | 48 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
49 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
|
50 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 }; |
0 | 55 |
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 struct search_body_context { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
57 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
|
58 struct istream *input; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
59 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
|
60 }; |
0 | 61 |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5516
diff
changeset
|
62 static const enum message_header_parser_flags hdr_parser_flags = |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5516
diff
changeset
|
63 MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE; |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5516
diff
changeset
|
64 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
65 static void search_parse_msgset_args(const struct mail_index_header *hdr, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
66 struct mail_search_arg *args, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
67 uint32_t *seq1_r, uint32_t *seq2_r, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
68 bool not); |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
69 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
70 static int seqset_contains(struct mail_search_seqset *set, uint32_t seq) |
0 | 71 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
72 while (set != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
73 if (seq >= set->seq1 && seq <= set->seq2) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
74 return TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
75 set = set->next; |
0 | 76 } |
77 | |
78 return FALSE; | |
79 } | |
80 | |
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
|
81 static uoff_t str_to_uoff_t(const char *str) |
46 | 82 { |
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
|
83 uoff_t num; |
46 | 84 |
85 num = 0; | |
86 while (*str != '\0') { | |
87 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
|
88 return 0; |
46 | 89 |
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
|
90 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
|
91 str++; |
46 | 92 } |
93 | |
94 return num; | |
95 } | |
96 | |
0 | 97 /* 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
|
98 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
|
99 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
|
100 const char *value) |
0 | 101 { |
6276
b5a23c868935
Don't store data->rec. It may not stay usable.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
102 enum mail_flags flags = imail->data.flags; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
103 const char *const *keywords; |
1947 | 104 |
0 | 105 switch (type) { |
106 /* flags */ | |
107 case SEARCH_ANSWERED: | |
6276
b5a23c868935
Don't store data->rec. It may not stay usable.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
108 return flags & MAIL_ANSWERED; |
0 | 109 case SEARCH_DELETED: |
6276
b5a23c868935
Don't store data->rec. It may not stay usable.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
110 return flags & MAIL_DELETED; |
0 | 111 case SEARCH_DRAFT: |
6276
b5a23c868935
Don't store data->rec. It may not stay usable.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
112 return flags & MAIL_DRAFT; |
0 | 113 case SEARCH_FLAGGED: |
6276
b5a23c868935
Don't store data->rec. It may not stay usable.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
114 return flags & MAIL_FLAGGED; |
0 | 115 case SEARCH_SEEN: |
6276
b5a23c868935
Don't store data->rec. It may not stay usable.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
116 return flags & MAIL_SEEN; |
0 | 117 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
|
118 return mail_get_flags(&imail->mail.mail) & MAIL_RECENT; |
0 | 119 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
|
120 keywords = mail_get_keywords(&imail->mail.mail); |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
121 while (*keywords != NULL) { |
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
122 if (strcasecmp(*keywords, value) == 0) |
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
123 return 1; |
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
124 keywords++; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
125 } |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2899
diff
changeset
|
126 return 0; |
0 | 127 |
128 default: | |
129 return -1; | |
130 } | |
131 } | |
132 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
133 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
|
134 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
|
135 { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
144 default: |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
145 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
146 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
147 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
148 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
149 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
|
150 struct index_search_context *ctx) |
0 | 151 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 else |
31d8f49b1a34
Compiler warning fixes and one real fix for int -> bool changes.
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
156 ARG_SET_RESULT(arg, 0); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
157 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
158 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
159 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
160 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
|
161 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
|
162 { |
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
|
163 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
|
164 arg->value.str)) { |
0 | 165 case -1: |
166 /* unknown */ | |
167 break; | |
168 case 0: | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
169 ARG_SET_RESULT(arg, 0); |
0 | 170 break; |
171 default: | |
172 ARG_SET_RESULT(arg, 1); | |
173 break; | |
174 } | |
175 } | |
176 | |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
177 /* 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
|
178 static int search_arg_match_cached(struct index_search_context *ctx, |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
179 struct mail_search_arg *arg) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
180 { |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
181 uoff_t virtual_size, search_size; |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
182 time_t date; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
183 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
|
184 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
185 switch (arg->type) { |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
186 /* 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
|
187 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
|
188 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
|
189 case SEARCH_SINCE: |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
190 if (mail_get_received_date(ctx->mail, &date) < 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
|
191 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
|
192 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
193 switch (arg->type) { |
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 case SEARCH_BEFORE: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
195 return date < arg->value.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 case SEARCH_ON: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
197 return date >= arg->value.time && |
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
198 date < arg->value.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
|
199 case SEARCH_SINCE: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
200 return date >= arg->value.time; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
201 default: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
202 /* unreachable */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
203 break; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
204 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
205 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
206 /* 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
|
207 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
|
208 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
|
209 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
|
210 /* 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
|
211 in searches. date is returned as UTC, so change it. */ |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
212 if (mail_get_date(ctx->mail, &date, &timezone_offset) < 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
|
213 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
|
214 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
|
215 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
216 switch (arg->type) { |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
217 case SEARCH_SENTBEFORE: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
218 return date < arg->value.time; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
219 case SEARCH_SENTON: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
220 return date >= arg->value.time && |
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
221 date < arg->value.time + 3600*24; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
222 case SEARCH_SENTSINCE: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
223 return date >= arg->value.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
|
224 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
225 /* unreachable */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
226 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
227 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
228 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
229 /* sizes */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
230 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
|
231 case SEARCH_LARGER: |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
232 if (mail_get_virtual_size(ctx->mail, &virtual_size) < 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
|
233 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
|
234 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
235 search_size = str_to_uoff_t(arg->value.str); |
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
236 if (arg->type == SEARCH_SMALLER) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
237 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
|
238 else |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
239 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
|
240 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
241 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
242 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
|
243 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
244 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
245 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
246 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
|
247 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
|
248 { |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
249 switch (search_arg_match_cached(ctx, arg)) { |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
250 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
|
251 /* unknown */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
252 break; |
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 0: |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
254 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
|
255 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
256 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
257 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
|
258 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
259 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
260 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
261 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
262 static int search_sent(enum mail_search_arg_type type, time_t search_time, |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
263 const unsigned char *sent_value, size_t sent_value_len) |
0 | 264 { |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
265 time_t sent_time; |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
266 int timezone_offset; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
267 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
268 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
|
269 return 0; |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
270 |
1340
087a9f4304ca
s/latest IMAP4rev1 draft/RFC-3501/
Timo Sirainen <tss@iki.fi>
parents:
1322
diff
changeset
|
271 /* 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
|
272 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
|
273 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
|
274 &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
|
275 return 0; |
1604 | 276 sent_time += timezone_offset * 60; |
0 | 277 |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
278 switch (type) { |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
279 case SEARCH_SENTBEFORE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
280 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
|
281 case SEARCH_SENTON: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
282 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
|
283 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
|
284 case SEARCH_SENTSINCE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
285 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
|
286 default: |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
534
diff
changeset
|
287 i_unreached(); |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
288 } |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
289 } |
0 | 290 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
291 static struct message_search_context * |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
292 msg_search_arg_context(struct index_search_context *ctx, |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
293 struct mail_search_arg *arg) |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
294 { |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
295 struct message_search_context *arg_ctx = arg->context; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
296 enum message_search_flags flags; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
297 int ret; |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
298 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
299 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
|
300 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
|
301 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
302 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
|
303 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
|
304 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
305 flags = (arg->type == SEARCH_BODY || arg->type == SEARCH_BODY_FAST) ? |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
306 MESSAGE_SEARCH_FLAG_SKIP_HEADERS : 0; |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
307 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
308 ret = message_search_init(ctx->search_pool, arg->value.str, |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
309 ctx->mail_ctx.charset, flags, |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
310 &arg_ctx); |
5527 | 311 if (ret > 0) { |
312 arg->context = arg_ctx; | |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
313 return arg_ctx; |
5527 | 314 } |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
315 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
|
316 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
|
317 else |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
318 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
|
319 return NULL; |
0 | 320 } |
321 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
322 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
|
323 struct search_header_context *ctx) |
0 | 324 { |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
325 struct message_search_context *msg_search_ctx; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
326 struct message_block block; |
0 | 327 int ret; |
328 | |
329 /* first check that the field name matches to argument. */ | |
330 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
|
331 case SEARCH_SENTBEFORE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
332 case SEARCH_SENTON: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
333 case SEARCH_SENTSINCE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
334 /* 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
|
335 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
|
336 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
|
337 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
|
338 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
339 } |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
340 ret = search_sent(arg->type, arg->value.time, |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
341 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
|
342 ctx->hdr->full_value_len); |
1070 | 343 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
|
344 } |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
345 return; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
346 |
0 | 347 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
|
348 case SEARCH_HEADER_ADDRESS: |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
349 ctx->custom_header = TRUE; |
0 | 350 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
351 if (strcasecmp(ctx->hdr->name, arg->hdr_field_name) != 0) |
0 | 352 return; |
5513 | 353 break; |
0 | 354 default: |
355 return; | |
356 } | |
357 | |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
358 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
|
359 /* we're just testing existence of the field. always matches. */ |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
360 ARG_SET_RESULT(arg, 1); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
361 return; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
362 } |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
363 |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
364 if (ctx->hdr->continues) { |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
365 ctx->hdr->use_full_value = TRUE; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
366 return; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
367 } |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
368 |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
369 memset(&block, 0, sizeof(block)); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
370 msg_search_ctx = msg_search_arg_context(ctx->index_context, arg); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
371 if (msg_search_ctx == NULL) |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
372 ret = 0; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
373 else if (arg->type == SEARCH_HEADER_ADDRESS) { |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
374 /* we have to match against normalized address */ |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
375 struct message_address *addr; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
376 string_t *str; |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
377 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
378 t_push(); |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
379 addr = message_address_parse(pool_datastack_create(), |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
380 ctx->hdr->full_value, |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
381 ctx->hdr->full_value_len, |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
382 (unsigned int)-1, TRUE); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
383 str = t_str_new(ctx->hdr->value_len); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
384 message_address_write(str, addr); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
385 block.data = str_data(str); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
386 block.size = str_len(str); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
387 ret = message_search_more_decoded(msg_search_ctx, &block); |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
388 t_pop(); |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
389 } else { |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
390 block.data = ctx->hdr->full_value; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
391 block.size = ctx->hdr->full_value_len; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
392 ret = message_search_more_decoded(msg_search_ctx, &block); |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
393 } |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
394 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
395 if (ret > 0 || |
5507
65250cfebd74
Don't handle TEXT searches in header searches. It's done later anyway.
Timo Sirainen <tss@iki.fi>
parents:
5505
diff
changeset
|
396 (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
|
397 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
|
398 /* 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
|
399 ARG_SET_RESULT(arg, ret); |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
400 } |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
401 } |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
402 |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
403 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
|
404 void *context __attr_unused__) |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
405 { |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
406 switch (arg->type) { |
1070 | 407 case SEARCH_SENTBEFORE: |
408 case SEARCH_SENTON: | |
409 case SEARCH_SENTSINCE: | |
410 if (arg->not) { | |
411 /* date header not found, so we match only for | |
412 NOT searches */ | |
413 ARG_SET_RESULT(arg, 0); | |
414 } | |
415 break; | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
416 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
|
417 case SEARCH_HEADER_ADDRESS: |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
418 ARG_SET_RESULT(arg, 0); |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
419 break; |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
420 default: |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
421 break; |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
422 } |
0 | 423 } |
424 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
425 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
|
426 struct search_header_context *ctx) |
0 | 427 { |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
428 if (hdr == NULL) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
429 /* 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
|
430 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
|
431 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
432 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
433 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
434 if (hdr->eoh) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
435 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
436 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
437 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
|
438 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
|
439 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
440 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
|
441 ctx->hdr = hdr; |
0 | 442 |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
443 ctx->custom_header = FALSE; |
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
444 mail_search_args_foreach(ctx->args, search_header_arg, ctx); |
0 | 445 } |
446 } | |
447 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
448 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
|
449 struct search_body_context *ctx) |
0 | 450 { |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
451 struct message_search_context *msg_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
|
452 int ret; |
0 | 453 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
454 if (ctx->index_ctx->error != NULL) |
0 | 455 return; |
456 | |
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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 } |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
466 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
467 msg_search_ctx = msg_search_arg_context(ctx->index_ctx, arg); |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
468 if (msg_search_ctx == NULL) { |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
469 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
|
470 return; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
471 } |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
472 |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
473 i_stream_seek(ctx->input, 0); |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
474 ret = message_search_msg(msg_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
|
475 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
|
476 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
|
477 "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
|
478 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
|
479 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
480 /* 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
|
481 ctx->index_ctx->imail->data.parts = NULL; |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
482 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
483 i_stream_seek(ctx->input, 0); |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
484 ret = message_search_msg(msg_search_ctx, ctx->input, NULL); |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
485 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
|
486 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
|
487 } |
290
3dcc2275b4ca
IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
488 |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
489 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
|
490 } |
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
491 |
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
|
492 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
|
493 struct index_search_context *ctx) |
0 | 494 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
495 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
|
496 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
|
497 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
|
498 bool have_headers, have_body; |
0 | 499 |
500 /* 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
|
501 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
|
502 if (!have_headers && !have_body) |
0 | 503 return TRUE; |
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 (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
|
506 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
|
507 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
508 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
|
509 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
|
510 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
511 if (headers == NULL) { |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
512 headers_ctx = NULL; |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
513 if (mail_get_stream(ctx->mail, NULL, NULL, &input) < 0) |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
514 return FALSE; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
515 } else { |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
516 /* 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
|
517 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
|
518 headers_ctx = |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
519 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
|
520 headers); |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
521 if (mail_get_header_stream(ctx->mail, headers_ctx, |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
522 &input) < 0) { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3873
diff
changeset
|
523 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
|
524 return FALSE; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
525 } |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
526 } |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
527 |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
528 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
|
529 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
|
530 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
|
531 hdr_ctx.args = args; |
5516
96f0b56489a2
Don't feed index_mail_parser headers while searching message bodies, unless
Timo Sirainen <tss@iki.fi>
parents:
5513
diff
changeset
|
532 hdr_ctx.parse_headers = headers == NULL && |
96f0b56489a2
Don't feed index_mail_parser headers while searching message bodies, unless
Timo Sirainen <tss@iki.fi>
parents:
5513
diff
changeset
|
533 index_mail_want_parse_headers(ctx->imail); |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
534 |
5516
96f0b56489a2
Don't feed index_mail_parser headers while searching message bodies, unless
Timo Sirainen <tss@iki.fi>
parents:
5513
diff
changeset
|
535 if (hdr_ctx.parse_headers) |
96f0b56489a2
Don't feed index_mail_parser headers while searching message bodies, unless
Timo Sirainen <tss@iki.fi>
parents:
5513
diff
changeset
|
536 index_mail_parse_header_init(ctx->imail, headers_ctx); |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5516
diff
changeset
|
537 message_parse_header(input, NULL, hdr_parser_flags, |
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5516
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 } else { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
542 struct message_size hdr_size; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
543 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
544 if (mail_get_stream(ctx->mail, &hdr_size, NULL, &input) < 0) |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
545 return FALSE; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
546 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
547 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
|
548 } |
0 | 549 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
550 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
|
551 struct search_body_context body_ctx; |
0 | 552 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
553 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
|
554 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
|
555 body_ctx.input = input; |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
556 (void)mail_get_parts(ctx->mail, &body_ctx.part); |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
557 |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
558 mail_search_args_foreach(args, search_body, &body_ctx); |
0 | 559 } |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
560 return TRUE; |
0 | 561 } |
562 | |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
567 if (!not) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
568 /* seq1..seq2 */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
569 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
|
570 *seq1_r = set->seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
571 if (*seq2_r > set->seq2) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
572 *seq2_r = set->seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
573 } else { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
574 if (set->seq1 == 1) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
575 /* seq2+1..count */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
576 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
|
577 /* completely outside our range */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
578 *seq1_r = (uint32_t)-1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
579 *seq2_r = 0; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
580 } else { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
581 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
|
582 *seq1_r = set->seq2 + 1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
583 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
584 } 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
|
585 /* 1..seq1-1 */ |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
586 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
|
587 *seq2_r = set->seq1 - 1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
588 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
589 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
590 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
591 |
5605
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
592 static void search_msgset_fix(const struct mail_index_header *hdr, |
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
593 struct mail_search_seqset *set, |
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
594 uint32_t *seq1_r, uint32_t *seq2_r, bool not) |
0 | 595 { |
4439
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
596 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
|
597 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
|
598 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
599 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
|
600 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
|
601 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
|
602 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
|
603 set->seq1 = set->seq2 = 0; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
604 if (not) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
605 continue; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
606 |
3467
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
607 /* completely outside our range */ |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
608 *seq1_r = (uint32_t)-1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
609 *seq2_r = 0; |
5605
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
610 return; |
3467
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
611 } |
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
612 /* 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
|
613 in range. */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
614 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
|
615 } |
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
616 if (set->seq2 > hdr->messages_count) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
617 set->seq2 = hdr->messages_count; |
0 | 618 |
3467
b75125eced7f
Moved sequence set range checks to imap-specific code, so that SEARCH can
Timo Sirainen <tss@iki.fi>
parents:
3325
diff
changeset
|
619 if (set->seq1 == 0 || set->seq2 == 0) { |
5605
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
620 /* this shouldn't happen. treat as nonexisting. */ |
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
621 *seq1_r = (uint32_t)-1; |
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
622 *seq2_r = 0; |
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
623 return; |
0 | 624 } |
625 | |
4439
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
626 if (set->seq1 < min_seq) |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
627 min_seq = set->seq1; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
628 if (set->seq2 > max_seq) |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
629 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
|
630 } |
4439
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
631 |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
632 full_set.seq1 = min_seq; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
633 full_set.seq2 = max_seq; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
634 full_set.next = NULL; |
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
635 update_seqs(&full_set, hdr, seq1_r, seq2_r, not); |
5605
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
636 return; |
0 | 637 } |
638 | |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
639 static void search_or_parse_msgset_args(const struct mail_index_header *hdr, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
640 struct mail_search_arg *args, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
641 uint32_t *seq1_r, uint32_t *seq2_r, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
642 bool not) |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
643 { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
644 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
|
645 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
646 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
|
647 bool cur_not = args->not; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
648 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
649 if (not) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
650 cur_not = !cur_not; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
651 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
|
652 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
653 if (args->type == SEARCH_SUB) { |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
654 search_parse_msgset_args(hdr, args->value.subargs, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
655 &seq1, &seq2, cur_not); |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
656 } else if (args->type == SEARCH_OR) { |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
657 search_or_parse_msgset_args(hdr, args->value.subargs, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
658 &seq1, &seq2, cur_not); |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
659 } else if (args->type == SEARCH_SEQSET) { |
5605
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
660 search_msgset_fix(hdr, args->value.seqset, |
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
661 &seq1, &seq2, cur_not); |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
662 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
663 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
664 if (min_seq1 == 0) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
665 min_seq1 = seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
666 max_seq2 = seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
667 } else { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
668 if (seq1 < min_seq1) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
669 min_seq1 = seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
670 if (seq2 > max_seq2) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
671 max_seq2 = seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
672 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
673 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
674 i_assert(min_seq1 != 0); |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
675 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
676 if (min_seq1 > *seq1_r) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
677 *seq1_r = min_seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
678 if (max_seq2 < *seq2_r) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
679 *seq2_r = max_seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
680 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
681 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
682 static void search_parse_msgset_args(const struct mail_index_header *hdr, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
683 struct mail_search_arg *args, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
684 uint32_t *seq1_r, uint32_t *seq2_r, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
685 bool not) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
686 { |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
687 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
|
688 bool cur_not = args->not; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
689 |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
690 if (not) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
691 cur_not = !cur_not; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
692 |
1376 | 693 if (args->type == SEARCH_SUB) { |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
694 search_parse_msgset_args(hdr, args->value.subargs, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
695 seq1_r, seq2_r, cur_not); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
696 } 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
|
697 /* 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
|
698 range */ |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
699 search_or_parse_msgset_args(hdr, args->value.subargs, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
700 seq1_r, seq2_r, cur_not); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
701 } else if (args->type == SEARCH_SEQSET) { |
5605
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
702 search_msgset_fix(hdr, args->value.seqset, |
8b97d6bbff35
Don't try to handle 0 in messagesets by returning a nice error message.
Timo Sirainen <tss@iki.fi>
parents:
5599
diff
changeset
|
703 seq1_r, seq2_r, cur_not); |
0 | 704 } |
705 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
706 } |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
707 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
708 static void search_limit_lowwater(struct index_search_context *ctx, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
709 uint32_t uid_lowwater, uint32_t *first_seq) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
710 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
711 uint32_t seq1, seq2; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
712 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
713 if (uid_lowwater == 0) |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
714 return; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
715 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
716 mail_index_lookup_uid_range(ctx->view, uid_lowwater, (uint32_t)-1, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
717 &seq1, &seq2); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
718 if (*first_seq < seq1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
719 *first_seq = seq1; |
0 | 720 } |
721 | |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
722 static bool search_limit_by_flags(struct index_search_context *ctx, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
723 const struct mail_index_header *hdr, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
724 struct mail_search_arg *args, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
725 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
|
726 { |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
727 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
|
728 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
|
729 case SEARCH_SEEN: |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
730 /* SEEN with 0 seen? */ |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
731 if (!args->not && hdr->seen_messages_count == 0) |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
732 return FALSE; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
733 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
734 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
|
735 /* UNSEEN with all seen? */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
736 if (args->not) |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
737 return FALSE; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
738 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
739 /* SEEN with all seen */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
740 args->match_always = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
741 } else if (args->not) { |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
742 /* UNSEEN with lowwater limiting */ |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
743 search_limit_lowwater(ctx, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
744 hdr->first_unseen_uid_lowwater, seq1); |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
745 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
746 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
747 case SEARCH_DELETED: |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
748 /* DELETED with 0 deleted? */ |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
749 if (!args->not && hdr->deleted_messages_count == 0) |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
750 return FALSE; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
751 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
752 if (hdr->deleted_messages_count == |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
753 hdr->messages_count) { |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
754 /* UNDELETED with all deleted? */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
755 if (args->not) |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
756 return FALSE; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
757 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
758 /* DELETED with all deleted */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
759 args->match_always = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
760 } else if (!args->not) { |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
761 /* DELETED with lowwater limiting */ |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
762 search_limit_lowwater(ctx, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
763 hdr->first_deleted_uid_lowwater, seq1); |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
764 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
765 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
766 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
|
767 if (args->not) |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
768 return 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
|
769 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
770 default: |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
771 break; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
772 } |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
773 } |
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
774 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
775 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
|
776 } |
0 | 777 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
778 static void search_get_seqset(struct index_search_context *ctx, |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
779 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
|
780 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
781 const struct mail_index_header *hdr; |
0 | 782 |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2883
diff
changeset
|
783 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
|
784 if (hdr->messages_count == 0) { |
2899
1a05764af1e0
UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
785 /* 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
|
786 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
|
787 UID FETCH. */ |
1985
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
788 ctx->seq1 = 1; |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
789 ctx->seq2 = 0; |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
790 return; |
1985
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
791 } |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
792 |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
793 ctx->seq1 = 1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
794 ctx->seq2 = hdr->messages_count; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
795 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
796 search_parse_msgset_args(hdr, args, &ctx->seq1, &ctx->seq2, FALSE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
797 if (ctx->seq1 == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
798 ctx->seq1 = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
799 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
|
800 } |
4438
00db36e1b734
Don't crash when different search conditions reduce the search range so that
Timo Sirainen <tss@iki.fi>
parents:
4432
diff
changeset
|
801 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
|
802 /* no matches */ |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
803 return; |
4432
c13d8fe698f8
Don't crash if seqset restrictions caused no messages to be searched.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4431
diff
changeset
|
804 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
805 |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
806 /* UNSEEN and DELETED in root search level may limit the range */ |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
807 if (!search_limit_by_flags(ctx, hdr, args, &ctx->seq1, &ctx->seq2)) { |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
808 /* 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
|
809 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
|
810 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
|
811 } |
0 | 812 } |
813 | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
814 struct mail_search_context * |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
815 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
|
816 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
|
817 const enum mail_sort_type *sort_program) |
0 | 818 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
819 struct index_transaction_context *t = |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
820 (struct index_transaction_context *)_t; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
821 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
|
822 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
823 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
|
824 ctx->mail_ctx.transaction = _t; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
825 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
|
826 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
|
827 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
|
828 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
|
829 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
|
830 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
831 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
|
832 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
|
833 |
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
834 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
|
835 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
836 search_get_seqset(ctx, args); |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
837 (void)mail_search_args_foreach(args, search_init_seqset_arg, ctx); |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
838 |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
839 /* Need to reset results for match_always cases */ |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
840 mail_search_args_reset(ctx->mail_ctx.args, FALSE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
841 return &ctx->mail_ctx; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
842 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
843 |
5527 | 844 static void search_arg_deinit(struct mail_search_arg *arg, |
845 void *context __attr_unused__) | |
846 { | |
847 struct message_search_context *search_ctx = arg->context; | |
848 | |
849 if (search_ctx != NULL) { | |
850 message_search_deinit(&search_ctx); | |
851 arg->context = NULL; | |
852 } | |
853 } | |
854 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
855 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
|
856 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
857 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
|
858 int ret; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
859 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
860 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
|
861 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
862 if (ctx->error != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
863 mail_storage_set_error(ctx->ibox->box.storage, |
5613 | 864 MAIL_ERROR_PARAMS, ctx->error); |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
865 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
866 |
5527 | 867 mail_search_args_reset(ctx->mail_ctx.args, FALSE); |
868 (void)mail_search_args_foreach(ctx->mail_ctx.args, | |
869 search_arg_deinit, NULL); | |
870 | |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
871 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
|
872 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
|
873 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
874 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
|
875 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
|
876 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
|
877 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
|
878 i_free(ctx); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
879 return ret; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
880 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
881 |
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
|
882 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
|
883 { |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
884 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
|
885 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
|
886 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
887 /* 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
|
888 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
|
889 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
|
890 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
|
891 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
|
892 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
893 /* 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
|
894 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
|
895 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
|
896 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
|
897 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
|
898 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
899 /* 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
|
900 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
|
901 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
|
902 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
903 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
|
904 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
|
905 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
|
906 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
907 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
908 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
|
909 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
910 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
911 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
|
912 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
|
913 { |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
914 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
|
915 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
|
916 float percentage; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
917 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
|
918 |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
919 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
|
920 /* 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
|
921 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
|
922 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
|
923 } 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
|
924 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
|
925 |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
926 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
|
927 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
|
928 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
|
929 (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
|
930 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
|
931 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
|
932 |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
933 t_push(); |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
934 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
|
935 "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
|
936 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
|
937 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
|
938 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
|
939 t_pop(); |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
940 } |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
941 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
|
942 } |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
943 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
944 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
|
945 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
|
946 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
947 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
|
948 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
|
949 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
|
950 int ret; |
0 | 951 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
952 *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
|
953 |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
954 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
|
955 /* 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
|
956 matches from sort list */ |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
957 if (!index_sort_list_next(ctx->mail_ctx.sort_program, mail)) |
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
958 return 0; |
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
959 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
|
960 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
961 |
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
|
962 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
|
963 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
|
964 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
965 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
|
966 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
|
967 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
|
968 |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
969 while ((ret = box->v.search_next_update_seq(_ctx)) > 0) { |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
970 mail_set_seq(mail, _ctx->seq); |
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
|
971 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
972 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
|
973 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
|
974 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
|
975 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
976 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
|
977 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
978 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
|
979 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
|
980 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
|
981 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
|
982 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
983 |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
984 index_sort_list_add(ctx->mail_ctx.sort_program, mail); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
985 } |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
986 |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
987 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
|
988 *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
|
989 return 0; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
990 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
991 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
992 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
|
993 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
|
994 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
|
995 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
|
996 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
997 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
|
998 /* 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
|
999 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
|
1000 ctx->sorted = TRUE; |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6276
diff
changeset
|
1001 index_sort_list_finish(ctx->mail_ctx.sort_program); |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1002 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
|
1003 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
|
1004 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1005 |
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
|
1006 return ret; |
0 | 1007 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1008 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1009 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
|
1010 { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1011 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
|
1012 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
|
1013 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1014 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
|
1015 /* 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
|
1016 _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
|
1017 } else { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1018 _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
|
1019 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1020 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1021 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
|
1022 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
|
1023 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1024 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
|
1025 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
|
1026 /* 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
|
1027 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
|
1028 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
|
1029 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
|
1030 break; |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1031 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1032 /* 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
|
1033 _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
|
1034 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
|
1035 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1036 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
|
1037 } |