Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/index-search.c @ 7671:882888286bf5 HEAD
Saved search results: Remember what messages' static checks never match, so
we don't waste time checking them over and over again.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 09 Jun 2008 03:23:34 +0300 |
parents | 879208fdc7e3 |
children | 8e206e25a142 |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
6966
diff
changeset
|
1 /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */ |
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" |
7279
ef13dd179331
More fixes to SEARCH BEFORE/ON/SINCE timezone handling.
Timo Sirainen <tss@iki.fi>
parents:
7269
diff
changeset
|
7 #include "utc-offset.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
8 #include "str.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
9 #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
|
10 #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
|
11 #include "message-search.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
12 #include "message-parser.h" |
7620 | 13 #include "mail-index-modseq.h" |
0 | 14 #include "index-storage.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
15 #include "index-mail.h" |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
16 #include "index-sort.h" |
0 | 17 #include "mail-search.h" |
7647
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
18 #include "mailbox-search-result-private.h" |
0 | 19 |
20 #include <stdlib.h> | |
21 #include <ctype.h> | |
22 | |
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
|
23 #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
|
24 #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
|
25 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
26 #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
|
27 #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
|
28 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
29 struct index_search_context { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
30 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
|
31 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
|
32 struct index_mailbox *ibox; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
33 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
34 uint32_t seq1, seq2; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
35 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
|
36 struct index_mail *imail; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
37 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
38 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
|
39 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
|
40 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
41 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
|
42 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
43 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
|
44 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
|
45 unsigned int have_seqsets:1; |
7620 | 46 unsigned int have_index_args: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
|
47 }; |
0 | 48 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
49 struct search_header_context { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
50 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
|
51 struct mail_search_arg *args; |
0 | 52 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
53 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
|
54 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 }; |
0 | 59 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
60 struct search_body_context { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
61 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
|
62 struct istream *input; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
63 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
|
64 }; |
0 | 65 |
5522
5dee807e53cf
Header parser has now flags parameter to tell it how to handle linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
5516
diff
changeset
|
66 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
|
67 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
|
68 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
69 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
|
70 struct mail_search_arg *args, |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
71 uint32_t *seq1_r, uint32_t *seq2_r); |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
72 |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
73 static void search_init_arg(struct mail_search_arg *arg, |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
74 struct index_search_context *ctx) |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
75 { |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
76 switch (arg->type) { |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
77 case SEARCH_SEQSET: |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
78 ctx->have_seqsets = TRUE; |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
79 break; |
7618
6dbd70663adf
Added support for SEARCH_UIDSET.
Timo Sirainen <tss@iki.fi>
parents:
7414
diff
changeset
|
80 case SEARCH_UIDSET: |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
81 case SEARCH_FLAGS: |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
82 case SEARCH_KEYWORDS: |
7620 | 83 case SEARCH_MODSEQ: |
84 if (arg->type == SEARCH_MODSEQ) | |
85 mail_index_modseq_enable(ctx->ibox->index); | |
86 ctx->have_index_args = TRUE; | |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
87 break; |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
88 case SEARCH_ALL: |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
89 if (!arg->not) |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
90 arg->match_always = TRUE; |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
91 break; |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
92 default: |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
93 break; |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
94 } |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
95 } |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
96 |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
97 static void search_seqset_arg(struct mail_search_arg *arg, |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
98 struct index_search_context *ctx) |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
99 { |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
100 if (arg->type == SEARCH_SEQSET) { |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
101 if (seq_range_exists(&arg->value.seqset, ctx->mail_ctx.seq)) |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
102 ARG_SET_RESULT(arg, 1); |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
103 else |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
104 ARG_SET_RESULT(arg, 0); |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
105 } |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
106 } |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
107 |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
108 static int search_arg_match_keywords(struct index_search_context *ctx, |
6965
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
109 struct mail_search_arg *arg) |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
110 { |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
111 ARRAY_TYPE(keyword_indexes) keyword_indexes_arr; |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
112 const struct mail_keywords *search_kws = arg->value.keywords; |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
113 const unsigned int *keyword_indexes; |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
114 unsigned int i, j, count; |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
115 |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
116 t_array_init(&keyword_indexes_arr, 128); |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
117 mail_index_lookup_keywords(ctx->view, ctx->mail_ctx.seq, |
6965
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
118 &keyword_indexes_arr); |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
119 keyword_indexes = array_get(&keyword_indexes_arr, &count); |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
120 |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
121 /* there probably aren't many keywords, so O(n*m) for now */ |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
122 for (i = 0; i < search_kws->count; i++) { |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
123 for (j = 0; j < count; j++) { |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
124 if (search_kws->idx[i] == keyword_indexes[j]) |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
125 break; |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
126 } |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
127 if (j == count) |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
128 return 0; |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
129 } |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
130 return 1; |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
131 } |
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
132 |
0 | 133 /* Returns >0 = matched, 0 = not matched, -1 = unknown */ |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
134 static int search_arg_match_index(struct index_search_context *ctx, |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
135 struct mail_search_arg *arg, |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
136 const struct mail_index_record *rec) |
0 | 137 { |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
138 enum mail_flags flags; |
7620 | 139 uint64_t modseq; |
6965
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
140 int ret; |
1947 | 141 |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
142 switch (arg->type) { |
7618
6dbd70663adf
Added support for SEARCH_UIDSET.
Timo Sirainen <tss@iki.fi>
parents:
7414
diff
changeset
|
143 case SEARCH_UIDSET: |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
144 return seq_range_exists(&arg->value.seqset, rec->uid); |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
145 case SEARCH_FLAGS: |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
146 flags = rec->flags; |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
147 if ((arg->value.flags & MAIL_RECENT) != 0 && |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
148 index_mailbox_is_recent(ctx->ibox, rec->uid)) |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
149 flags |= MAIL_RECENT; |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
150 return (flags & arg->value.flags) == arg->value.flags; |
6965
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
151 case SEARCH_KEYWORDS: |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
152 T_BEGIN { |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
153 ret = search_arg_match_keywords(ctx, arg); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
154 } T_END; |
6965
ae369569e7de
SEARCH_KEYWORDS now uses struct mail_keywords instead of a string array.
Timo Sirainen <tss@iki.fi>
parents:
6962
diff
changeset
|
155 return ret; |
7620 | 156 case SEARCH_MODSEQ: { |
157 if (arg->value.flags != 0) { | |
158 modseq = mail_index_modseq_lookup_flags(ctx->view, | |
159 arg->value.flags, ctx->mail_ctx.seq); | |
160 } else if (arg->value.keywords != NULL) { | |
161 modseq = mail_index_modseq_lookup_keywords(ctx->view, | |
162 arg->value.keywords, ctx->mail_ctx.seq); | |
163 } else { | |
7625 | 164 modseq = mail_index_modseq_lookup(ctx->view, |
7620 | 165 ctx->mail_ctx.seq); |
166 } | |
167 return modseq >= arg->value.modseq->modseq; | |
168 } | |
0 | 169 default: |
170 return -1; | |
171 } | |
172 } | |
173 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
174 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
|
175 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
|
176 { |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
177 const struct mail_index_record *rec; |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
178 |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
179 rec = mail_index_lookup(ctx->view, ctx->mail_ctx.seq); |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
180 switch (search_arg_match_index(ctx, arg, rec)) { |
0 | 181 case -1: |
182 /* unknown */ | |
183 break; | |
184 case 0: | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
185 ARG_SET_RESULT(arg, 0); |
0 | 186 break; |
187 default: | |
188 ARG_SET_RESULT(arg, 1); | |
189 break; | |
190 } | |
191 } | |
192 | |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
193 /* 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
|
194 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
|
195 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
|
196 { |
7279
ef13dd179331
More fixes to SEARCH BEFORE/ON/SINCE timezone handling.
Timo Sirainen <tss@iki.fi>
parents:
7269
diff
changeset
|
197 struct tm *tm; |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
198 uoff_t virtual_size; |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
199 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
|
200 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
|
201 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
202 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
|
203 /* 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 return -1; |
7279
ef13dd179331
More fixes to SEARCH BEFORE/ON/SINCE timezone handling.
Timo Sirainen <tss@iki.fi>
parents:
7269
diff
changeset
|
209 |
7640 | 210 if ((arg->value.search_flags & |
211 MAIL_SEARCH_ARG_FLAG_USE_TZ) == 0) { | |
212 tm = localtime(&date); | |
213 date += utc_offset(tm, date)*60; | |
214 } | |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
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) { |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
217 case SEARCH_BEFORE: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
218 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
|
219 case SEARCH_ON: |
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; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
222 case SEARCH_SINCE: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
223 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
|
224 default: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
225 /* unreachable */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
226 break; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
227 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
228 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
229 /* 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
|
230 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
|
231 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
|
232 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
|
233 /* 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
|
234 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
|
235 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
|
236 return -1; |
7640 | 237 if ((arg->value.search_flags & |
238 MAIL_SEARCH_ARG_FLAG_USE_TZ) == 0) | |
239 date += timezone_offset * 60; | |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
240 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
241 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
|
242 case SEARCH_SENTBEFORE: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
243 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
|
244 case SEARCH_SENTON: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
245 return date >= arg->value.time && |
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
246 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
|
247 case SEARCH_SENTSINCE: |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
248 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
|
249 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
250 /* unreachable */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
251 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
252 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
253 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
254 /* sizes */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
260 if (arg->type == SEARCH_SMALLER) |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
261 return virtual_size < arg->value.size; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
262 else |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
263 return virtual_size > arg->value.size; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
264 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
265 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
266 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
|
267 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
268 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
269 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
270 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
|
271 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
|
272 { |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
273 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
|
274 case -1: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
275 /* unknown */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
276 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
277 case 0: |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
278 ARG_SET_RESULT(arg, 0); |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
279 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
280 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
281 ARG_SET_RESULT(arg, 1); |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
282 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
283 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
284 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
285 |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
286 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
|
287 const unsigned char *sent_value, size_t sent_value_len) |
0 | 288 { |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
289 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
|
290 int timezone_offset; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
291 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
292 if (sent_value == NULL) |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
293 return 0; |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
294 |
1340
087a9f4304ca
s/latest IMAP4rev1 draft/RFC-3501/
Timo Sirainen <tss@iki.fi>
parents:
1322
diff
changeset
|
295 /* 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
|
296 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
|
297 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
|
298 &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
|
299 return 0; |
1604 | 300 sent_time += timezone_offset * 60; |
0 | 301 |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
302 switch (type) { |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
303 case SEARCH_SENTBEFORE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
304 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
|
305 case SEARCH_SENTON: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
306 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
|
307 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
|
308 case SEARCH_SENTSINCE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
309 return sent_time >= search_time; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
310 default: |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
534
diff
changeset
|
311 i_unreached(); |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
312 } |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
313 } |
0 | 314 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 { |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
323 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
|
324 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
|
325 |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
326 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
|
327 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
|
328 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
329 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
|
330 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
|
331 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
332 ret = message_search_init(ctx->search_pool, arg->value.str, |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
333 ctx->mail_ctx.args->charset, flags, |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
334 &arg_ctx); |
5527 | 335 if (ret > 0) { |
336 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
|
337 return arg_ctx; |
5527 | 338 } |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
339 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
|
340 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
|
341 else |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
342 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
|
343 return NULL; |
0 | 344 } |
345 | |
7284
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
346 static void compress_lwsp(string_t *dest, const unsigned char *src, |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
347 unsigned int src_len) |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
348 { |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
349 unsigned int i; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
350 bool prev_lwsp = TRUE; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
351 |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
352 for (i = 0; i < src_len; i++) { |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
353 if (IS_LWSP(src[i])) { |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
354 if (!prev_lwsp) { |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
355 prev_lwsp = TRUE; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
356 str_append_c(dest, ' '); |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
357 } |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
358 } else { |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
359 prev_lwsp = FALSE; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
360 str_append_c(dest, src[i]); |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
361 } |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
362 } |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
363 } |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
364 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
365 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
|
366 struct search_header_context *ctx) |
0 | 367 { |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
368 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
|
369 struct message_block block; |
6574
ab3a1a8ade55
Header searches didn't decode MIME encoded words.
Timo Sirainen <tss@iki.fi>
parents:
6492
diff
changeset
|
370 struct message_header_line hdr; |
0 | 371 int ret; |
372 | |
373 /* first check that the field name matches to argument. */ | |
374 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
|
375 case SEARCH_SENTBEFORE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
376 case SEARCH_SENTON: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
377 case SEARCH_SENTSINCE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
378 /* 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
|
379 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
|
380 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
|
381 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
|
382 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
383 } |
5599
6789ba80419b
Parse search dates already in IMAP code.
Timo Sirainen <tss@iki.fi>
parents:
5527
diff
changeset
|
384 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
|
385 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
|
386 ctx->hdr->full_value_len); |
1070 | 387 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
|
388 } |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
389 return; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
390 |
0 | 391 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
|
392 case SEARCH_HEADER_ADDRESS: |
7284
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
393 case SEARCH_HEADER_COMPRESS_LWSP: |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
394 ctx->custom_header = TRUE; |
0 | 395 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
396 if (strcasecmp(ctx->hdr->name, arg->hdr_field_name) != 0) |
0 | 397 return; |
5513 | 398 break; |
0 | 399 default: |
400 return; | |
401 } | |
402 | |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
403 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
|
404 /* 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
|
405 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
|
406 return; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
407 } |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
408 |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
409 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
|
410 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
|
411 return; |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
412 } |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
413 |
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
414 memset(&block, 0, sizeof(block)); |
7281
e5b840b3c5c2
Header searches shouldn't include the header name or ":" in matching.
Timo Sirainen <tss@iki.fi>
parents:
7279
diff
changeset
|
415 |
e5b840b3c5c2
Header searches shouldn't include the header name or ":" in matching.
Timo Sirainen <tss@iki.fi>
parents:
7279
diff
changeset
|
416 /* We're searching only for values, so drop header name and middle |
e5b840b3c5c2
Header searches shouldn't include the header name or ":" in matching.
Timo Sirainen <tss@iki.fi>
parents:
7279
diff
changeset
|
417 parts. We use header searching so that MIME words will be decoded. */ |
e5b840b3c5c2
Header searches shouldn't include the header name or ":" in matching.
Timo Sirainen <tss@iki.fi>
parents:
7279
diff
changeset
|
418 hdr = *ctx->hdr; |
e5b840b3c5c2
Header searches shouldn't include the header name or ":" in matching.
Timo Sirainen <tss@iki.fi>
parents:
7279
diff
changeset
|
419 hdr.name = ""; hdr.name_len = 0; |
e5b840b3c5c2
Header searches shouldn't include the header name or ":" in matching.
Timo Sirainen <tss@iki.fi>
parents:
7279
diff
changeset
|
420 hdr.middle_len = 0; |
e5b840b3c5c2
Header searches shouldn't include the header name or ":" in matching.
Timo Sirainen <tss@iki.fi>
parents:
7279
diff
changeset
|
421 block.hdr = &hdr; |
e5b840b3c5c2
Header searches shouldn't include the header name or ":" in matching.
Timo Sirainen <tss@iki.fi>
parents:
7279
diff
changeset
|
422 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
423 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
|
424 if (msg_search_ctx == NULL) |
7284
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
425 return; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
426 |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
427 T_BEGIN { |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
428 struct message_address *addr; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
429 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
|
430 |
7284
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
431 switch (arg->type) { |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
432 case SEARCH_HEADER: |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
433 /* simple match */ |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
434 break; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
435 case SEARCH_HEADER_ADDRESS: |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
436 /* we have to match against normalized address */ |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
437 addr = message_address_parse(pool_datastack_create(), |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
438 ctx->hdr->full_value, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
439 ctx->hdr->full_value_len, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
440 (unsigned int)-1, TRUE); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
441 str = t_str_new(ctx->hdr->value_len); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
442 message_address_write(str, addr); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
443 hdr.value = hdr.full_value = str_data(str); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
444 hdr.value_len = hdr.full_value_len = str_len(str); |
7284
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
445 break; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
446 case SEARCH_HEADER_COMPRESS_LWSP: |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
447 /* convert LWSP to single spaces */ |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
448 str = t_str_new(hdr.full_value_len); |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
449 compress_lwsp(str, hdr.full_value, hdr.full_value_len); |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
450 hdr.value = hdr.full_value = str_data(str); |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
451 hdr.value_len = hdr.full_value_len = str_len(str); |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
452 break; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
453 default: |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
454 i_unreached(); |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
455 } |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
456 ret = message_search_more(msg_search_ctx, &block) ? 1 : 0; |
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
457 } T_END; |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
458 |
7284
346d4a44c2f4
SEARCH SUBJECT now changes LWSP to spaces to match ENVELOPE's subject field.
Timo Sirainen <tss@iki.fi>
parents:
7281
diff
changeset
|
459 ARG_SET_RESULT(arg, ret); |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
460 } |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
461 |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
462 static void search_header_unmatch(struct mail_search_arg *arg, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
463 void *context ATTR_UNUSED) |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
464 { |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
465 switch (arg->type) { |
1070 | 466 case SEARCH_SENTBEFORE: |
467 case SEARCH_SENTON: | |
468 case SEARCH_SENTSINCE: | |
469 if (arg->not) { | |
470 /* date header not found, so we match only for | |
471 NOT searches */ | |
472 ARG_SET_RESULT(arg, 0); | |
473 } | |
474 break; | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
475 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
|
476 case SEARCH_HEADER_ADDRESS: |
7328
e0e212e7deeb
SEARCH NOT SUBJECT didn't work correctly.
Timo Sirainen <tss@iki.fi>
parents:
7284
diff
changeset
|
477 case SEARCH_HEADER_COMPRESS_LWSP: |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
478 ARG_SET_RESULT(arg, 0); |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
479 break; |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
480 default: |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
481 break; |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
482 } |
0 | 483 } |
484 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
485 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
|
486 struct search_header_context *ctx) |
0 | 487 { |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
488 if (hdr == NULL) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
489 /* 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
|
490 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
|
491 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
492 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
493 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
494 if (hdr->eoh) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
495 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
496 |
3325
38eaa792c405
Don't call index_mail_parse_header() twice when searching headers. Caused
Timo Sirainen <tss@iki.fi>
parents:
3301
diff
changeset
|
497 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
|
498 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
|
499 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
500 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
|
501 ctx->hdr = hdr; |
0 | 502 |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
503 ctx->custom_header = FALSE; |
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
504 mail_search_args_foreach(ctx->args, search_header_arg, ctx); |
0 | 505 } |
506 } | |
507 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4635
diff
changeset
|
508 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
|
509 struct search_body_context *ctx) |
0 | 510 { |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
511 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
|
512 int ret; |
0 | 513 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
514 if (ctx->index_ctx->error != NULL) |
0 | 515 return; |
516 | |
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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 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
|
524 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
|
525 } |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
526 |
5525
94bc3fbdecd5
Removed message body/header searchers. They're now combined into one
Timo Sirainen <tss@iki.fi>
parents:
5522
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 return; |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
531 } |
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
532 |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
533 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
|
534 ret = message_search_msg(msg_search_ctx, ctx->input, ctx->part); |
7241
a6c066f50877
Added mail_set_cache_corrupted() to rebuild the cache file and force
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
535 if (ret < 0 && ctx->input->stream_errno == 0) { |
a6c066f50877
Added mail_set_cache_corrupted() to rebuild the cache file and force
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
536 /* try again without cached parts */ |
a6c066f50877
Added mail_set_cache_corrupted() to rebuild the cache file and force
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
537 mail_set_cache_corrupted(ctx->index_ctx->mail, |
a6c066f50877
Added mail_set_cache_corrupted() to rebuild the cache file and force
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
538 MAIL_FETCH_MESSAGE_PARTS); |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
539 |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
540 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
|
541 ret = message_search_msg(msg_search_ctx, ctx->input, NULL); |
7241
a6c066f50877
Added mail_set_cache_corrupted() to rebuild the cache file and force
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
542 i_assert(ret >= 0 || ctx->input->stream_errno != 0); |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
543 } |
290
3dcc2275b4ca
IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
544 |
3795
e6c42de08336
Allow message_body_search() to return "message_part is broken" error. If it
Timo Sirainen <tss@iki.fi>
parents:
3467
diff
changeset
|
545 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
|
546 } |
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
547 |
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
|
548 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
|
549 struct index_search_context *ctx) |
0 | 550 { |
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 istream *input; |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
552 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
|
553 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
|
554 bool have_headers, have_body; |
0 | 555 |
556 /* 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
|
557 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
|
558 if (!have_headers && !have_body) |
0 | 559 return TRUE; |
560 | |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
561 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
|
562 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
|
563 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
564 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
|
565 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
|
566 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
567 if (headers == NULL) { |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
568 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
|
569 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
|
570 return FALSE; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
571 } else { |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
572 /* 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
|
573 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
|
574 headers_ctx = |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
575 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
|
576 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
|
577 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
|
578 &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
|
579 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
|
580 return FALSE; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
581 } |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2298
diff
changeset
|
582 } |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
583 |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 |
5516
96f0b56489a2
Don't feed index_mail_parser headers while searching message bodies, unless
Timo Sirainen <tss@iki.fi>
parents:
5513
diff
changeset
|
591 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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 } else { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
598 struct message_size hdr_size; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
599 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
600 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
|
601 return FALSE; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
602 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
603 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
|
604 } |
0 | 605 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
606 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
|
607 struct search_body_context body_ctx; |
0 | 608 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
609 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
|
610 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
|
611 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
|
612 (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
|
613 |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
614 mail_search_args_foreach(args, search_body, &body_ctx); |
0 | 615 } |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
616 return TRUE; |
0 | 617 } |
618 | |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
619 static bool search_msgset_fix_limits(const struct mail_index_header *hdr, |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
620 ARRAY_TYPE(seq_range) *seqset, bool not) |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
621 { |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
622 struct seq_range *range; |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
623 unsigned int count; |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
624 |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
625 i_assert(hdr->messages_count > 0); |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
626 |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
627 range = array_get_modifiable(seqset, &count); |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
628 if (count > 0) { |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
629 i_assert(range[0].seq1 != 0); |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
630 if (range[count-1].seq2 == (uint32_t)-1) { |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
631 /* "*" used, make sure the last message is in the range |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
632 (e.g. with count+1:* we still want to include it) */ |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
633 seq_range_array_add(seqset, 0, hdr->messages_count); |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
634 } |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
635 /* remove all non-existing messages */ |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
636 seq_range_array_remove_range(seqset, hdr->messages_count + 1, |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
637 (uint32_t)-1); |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
638 } |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
639 if (!not) |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
640 return array_count(seqset) > 0; |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
641 else { |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
642 /* if all messages are in the range, it can't match */ |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
643 range = array_get_modifiable(seqset, &count); |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
644 return range[0].seq1 == 1 && |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
645 range[count-1].seq2 == hdr->messages_count; |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
646 } |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
647 } |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
648 |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
649 static void search_msgset_fix(const struct mail_index_header *hdr, |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
650 ARRAY_TYPE(seq_range) *seqset, |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
651 uint32_t *seq1_r, uint32_t *seq2_r, bool not) |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
652 { |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
653 const struct seq_range *range; |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
654 unsigned int count; |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
655 uint32_t min_seq, max_seq; |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
656 |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
657 if (!search_msgset_fix_limits(hdr, seqset, not)) { |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
658 *seq1_r = (uint32_t)-1; |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
659 *seq2_r = 0; |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
660 return; |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
661 } |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
662 |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
663 range = array_get(seqset, &count); |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
664 if (!not) { |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
665 min_seq = range[0].seq1; |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
666 max_seq = range[count-1].seq2; |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
667 } else { |
7619
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
668 min_seq = range[0].seq1 > 1 ? 1 : range[0].seq2 + 1; |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
669 max_seq = range[count-1].seq2 < hdr->messages_count ? |
56f55bd35aa5
Moved IMAP messageset handling to lib-imap/ and searching to lib-storage/.
Timo Sirainen <tss@iki.fi>
parents:
7618
diff
changeset
|
670 hdr->messages_count : range[count-1].seq1 - 1; |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
671 if (min_seq > max_seq) { |
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
|
672 *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
|
673 *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
|
674 return; |
0 | 675 } |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
676 } |
4439
12b5fbb3a05c
Searching (storing, fetching) with sequence sets containing commas was
Timo Sirainen <tss@iki.fi>
parents:
4438
diff
changeset
|
677 |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
678 if (*seq1_r < min_seq || *seq1_r == 0) |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
679 *seq1_r = min_seq; |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
680 if (*seq2_r > max_seq) |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
681 *seq2_r = max_seq; |
0 | 682 } |
683 | |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
684 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
|
685 struct mail_search_arg *args, |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
686 uint32_t *seq1_r, uint32_t *seq2_r) |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
687 { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
688 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
|
689 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
690 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
|
691 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
|
692 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
693 if (args->type == SEARCH_SUB) { |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
694 i_assert(!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
|
695 search_parse_msgset_args(hdr, args->value.subargs, |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
696 &seq1, &seq2); |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
697 } else if (args->type == SEARCH_OR) { |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
698 i_assert(!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
|
699 search_or_parse_msgset_args(hdr, args->value.subargs, |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
700 &seq1, &seq2); |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
701 } else if (args->type == SEARCH_SEQSET) { |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
702 search_msgset_fix(hdr, &args->value.seqset, |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
703 &seq1, &seq2, args->not); |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
704 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
705 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
706 if (min_seq1 == 0) { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
707 min_seq1 = seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
708 max_seq2 = seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
709 } else { |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
710 if (seq1 < min_seq1) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
711 min_seq1 = seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
712 if (seq2 > max_seq2) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
713 max_seq2 = seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
714 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
715 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
716 i_assert(min_seq1 != 0); |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
717 |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
718 if (min_seq1 > *seq1_r) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
719 *seq1_r = min_seq1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
720 if (max_seq2 < *seq2_r) |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
721 *seq2_r = max_seq2; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
722 } |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
723 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
724 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
|
725 struct mail_search_arg *args, |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
726 uint32_t *seq1_r, uint32_t *seq2_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
727 { |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
728 for (; args != NULL; args = args->next) { |
1376 | 729 if (args->type == SEARCH_SUB) { |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
730 i_assert(!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
|
731 search_parse_msgset_args(hdr, args->value.subargs, |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
732 seq1_r, seq2_r); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
733 } 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
|
734 /* 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
|
735 range */ |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
736 i_assert(!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 search_or_parse_msgset_args(hdr, args->value.subargs, |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
738 seq1_r, seq2_r); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
739 } else if (args->type == SEARCH_SEQSET) { |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
740 search_msgset_fix(hdr, &args->value.seqset, |
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
741 seq1_r, seq2_r, args->not); |
0 | 742 } |
743 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
744 } |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
745 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
746 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
|
747 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
|
748 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
749 uint32_t seq1, seq2; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
750 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
751 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
|
752 return; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
753 |
6677
90bcf480312d
Renamed mail_index_lookup_uid_range() to mail_index_lookup_seq_range(), made
Timo Sirainen <tss@iki.fi>
parents:
6574
diff
changeset
|
754 mail_index_lookup_seq_range(ctx->view, uid_lowwater, (uint32_t)-1, |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
755 &seq1, &seq2); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
756 if (*first_seq < seq1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
757 *first_seq = seq1; |
0 | 758 } |
759 | |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
760 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
|
761 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
|
762 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
|
763 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
|
764 { |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
765 for (; args != NULL; args = args->next) { |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
766 if (args->type != SEARCH_FLAGS) { |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
767 if (args->type == SEARCH_ALL) { |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
768 if (args->not) |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
769 return FALSE; |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
770 } |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
771 continue; |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
772 } |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
773 if ((args->value.flags & MAIL_SEEN) != 0) { |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
774 /* SEEN with 0 seen? */ |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
775 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
|
776 return FALSE; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
777 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
778 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
|
779 /* UNSEEN with all seen? */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
780 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
|
781 return FALSE; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
782 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
783 /* SEEN with all seen */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
784 args->match_always = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
785 } else if (args->not) { |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
786 /* 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
|
787 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
|
788 hdr->first_unseen_uid_lowwater, seq1); |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
789 } |
6962
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
790 } |
659e4a606aae
Replaced SEARCH_<flag> with a generic SEARCH_FLAGS. Use value.size for
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
791 if ((args->value.flags & MAIL_DELETED) != 0) { |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
792 /* DELETED with 0 deleted? */ |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
793 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
|
794 return FALSE; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
795 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
796 if (hdr->deleted_messages_count == |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
797 hdr->messages_count) { |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
798 /* UNDELETED with all deleted? */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
799 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
|
800 return FALSE; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
801 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
802 /* DELETED with all deleted */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
803 args->match_always = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
804 } else if (!args->not) { |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
805 /* 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
|
806 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
|
807 hdr->first_deleted_uid_lowwater, seq1); |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
808 } |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
809 } |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
810 } |
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
811 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
812 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
|
813 } |
0 | 814 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
815 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
|
816 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
|
817 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
818 const struct mail_index_header *hdr; |
0 | 819 |
2892
62d53b49110d
Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents:
2883
diff
changeset
|
820 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
|
821 if (hdr->messages_count == 0) { |
2899
1a05764af1e0
UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents:
2892
diff
changeset
|
822 /* 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
|
823 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
|
824 UID FETCH. */ |
1985
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
825 ctx->seq1 = 1; |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
826 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
|
827 return; |
1985
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
828 } |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
829 |
4431
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
830 ctx->seq1 = 1; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
831 ctx->seq2 = hdr->messages_count; |
2461061327ed
NOT condition wasn't handled correctly in SEARCH.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4303
diff
changeset
|
832 |
6485
2eff72b212fe
Simplify search tree by canonicalizing message sets, converting NOT away
Timo Sirainen <tss@iki.fi>
parents:
6457
diff
changeset
|
833 search_parse_msgset_args(hdr, args, &ctx->seq1, &ctx->seq2); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
834 if (ctx->seq1 == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
835 ctx->seq1 = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
836 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
|
837 } |
4438
00db36e1b734
Don't crash when different search conditions reduce the search range so that
Timo Sirainen <tss@iki.fi>
parents:
4432
diff
changeset
|
838 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
|
839 /* 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
|
840 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
|
841 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
842 |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
843 /* 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
|
844 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
|
845 /* 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
|
846 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
|
847 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
|
848 } |
0 | 849 } |
850 | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
851 struct mail_search_context * |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
852 index_storage_search_init(struct mailbox_transaction_context *_t, |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
853 struct mail_search_args *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
|
854 const enum mail_sort_type *sort_program) |
0 | 855 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
856 struct index_transaction_context *t = |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
857 (struct index_transaction_context *)_t; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
858 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
|
859 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
860 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
|
861 ctx->mail_ctx.transaction = _t; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
862 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
|
863 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
|
864 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
|
865 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
|
866 |
7647
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
867 i_array_init(&ctx->mail_ctx.results, 5); |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
868 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
|
869 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
|
870 |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
871 mail_search_args_reset(ctx->mail_ctx.args->args, TRUE); |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
872 |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
873 search_get_seqset(ctx, args->args); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
874 (void)mail_search_args_foreach(args->args, search_init_arg, ctx); |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
875 |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
876 /* Need to reset results for match_always cases */ |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
877 mail_search_args_reset(ctx->mail_ctx.args->args, FALSE); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
878 return &ctx->mail_ctx; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
879 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
880 |
5527 | 881 static void search_arg_deinit(struct mail_search_arg *arg, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
882 void *context ATTR_UNUSED) |
5527 | 883 { |
884 struct message_search_context *search_ctx = arg->context; | |
885 | |
886 if (search_ctx != NULL) { | |
887 message_search_deinit(&search_ctx); | |
888 arg->context = NULL; | |
889 } | |
890 } | |
891 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
892 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
|
893 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
894 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
|
895 int ret; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
896 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
897 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
|
898 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
899 if (ctx->error != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
900 mail_storage_set_error(ctx->ibox->box.storage, |
5613 | 901 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
|
902 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
903 |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
904 mail_search_args_reset(ctx->mail_ctx.args->args, FALSE); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
905 (void)mail_search_args_foreach(ctx->mail_ctx.args->args, |
5527 | 906 search_arg_deinit, NULL); |
907 | |
5504
9414946e1eb0
Message body search API changed to init/search/deinit. Searching now builds
Timo Sirainen <tss@iki.fi>
parents:
4949
diff
changeset
|
908 if (ctx->search_pool != NULL) |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
909 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
|
910 |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
911 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
|
912 index_sort_program_deinit(&ctx->mail_ctx.sort_program); |
7647
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
913 array_free(&ctx->mail_ctx.results); |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
914 array_free(&ctx->mail_ctx.module_contexts); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
915 i_free(ctx); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
916 return ret; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
917 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
918 |
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
|
919 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
|
920 { |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
921 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
|
922 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
|
923 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
924 /* next search only from cached arguments */ |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
925 ret = mail_search_args_foreach(ctx->mail_ctx.args->args, |
4607
71b3570946f8
Moved some search parameters to public struct mail_search_context and added
Timo Sirainen <tss@iki.fi>
parents:
4439
diff
changeset
|
926 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
|
927 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
|
928 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
|
929 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
930 /* open the mail file and check the rest */ |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
931 if (!search_arg_match_text(ctx->mail_ctx.args->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
|
932 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
|
933 |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
934 for (arg = ctx->mail_ctx.args->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
|
935 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
|
936 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
|
937 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
938 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
939 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
|
940 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
941 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
942 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
|
943 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
|
944 { |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
945 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
|
946 float percentage; |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
947 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
|
948 |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
949 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
|
950 /* 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
|
951 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
|
952 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
|
953 } 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
|
954 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
|
955 |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
956 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
|
957 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
|
958 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
|
959 (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
|
960 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
|
961 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
|
962 |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
963 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
964 const char *text; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
965 |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
966 text = t_strdup_printf("Searched %d%% of the mailbox, " |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
967 "ETA %d:%02d", (int)percentage, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
968 secs/60, secs%60); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
969 box->storage->callbacks-> |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
970 notify_ok(box, text, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
971 box->storage->callback_context); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
972 } T_END; |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
973 } |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
974 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
|
975 } |
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
976 |
7647
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
977 static bool search_arg_is_static(struct mail_search_arg *arg) |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
978 { |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
979 struct mail_search_arg *subarg; |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
980 |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
981 switch (arg->type) { |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
982 case SEARCH_OR: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
983 case SEARCH_SUB: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
984 /* they're static only if all subargs are static */ |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
985 subarg = arg->value.subargs; |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
986 for (; subarg != NULL; subarg = subarg->next) { |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
987 if (!search_arg_is_static(subarg)) |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
988 return FALSE; |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
989 } |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
990 return TRUE; |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
991 case SEARCH_SEQSET: /* changes between syncs */ |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
992 case SEARCH_FLAGS: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
993 case SEARCH_KEYWORDS: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
994 case SEARCH_MODSEQ: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
995 break; |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
996 case SEARCH_ALL: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
997 case SEARCH_UIDSET: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
998 case SEARCH_BEFORE: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
999 case SEARCH_ON: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1000 case SEARCH_SINCE: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1001 case SEARCH_SENTBEFORE: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1002 case SEARCH_SENTON: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1003 case SEARCH_SENTSINCE: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1004 case SEARCH_SMALLER: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1005 case SEARCH_LARGER: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1006 case SEARCH_HEADER: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1007 case SEARCH_HEADER_ADDRESS: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1008 case SEARCH_HEADER_COMPRESS_LWSP: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1009 case SEARCH_BODY: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1010 case SEARCH_TEXT: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1011 case SEARCH_BODY_FAST: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1012 case SEARCH_TEXT_FAST: |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1013 return TRUE; |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1014 } |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1015 return FALSE; |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1016 } |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1017 |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1018 static void search_set_static_matches(struct mail_search_arg *arg) |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1019 { |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1020 for (; arg != NULL; arg = arg->next) { |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1021 if (search_arg_is_static(arg)) |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1022 arg->result = 1; |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1023 } |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1024 } |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1025 |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1026 static bool search_has_static_nonmatches(struct mail_search_arg *arg) |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1027 { |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1028 for (; arg != NULL; arg = arg->next) { |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1029 if (arg->result == 0 && search_arg_is_static(arg)) |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1030 return TRUE; |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1031 } |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1032 return FALSE; |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1033 } |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1034 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1035 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
|
1036 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
|
1037 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
1038 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
|
1039 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
|
1040 unsigned int count = 0; |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1041 bool never; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1042 int ret; |
0 | 1043 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1044 *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
|
1045 |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1046 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
|
1047 /* 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
|
1048 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
|
1049 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
|
1050 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
|
1051 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
|
1052 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1053 |
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
|
1054 ctx->mail = mail; |
7414
45624f5ba358
struct mail can't necessarily be casted to struct index_mail. Added a new
Timo Sirainen <tss@iki.fi>
parents:
7328
diff
changeset
|
1055 ctx->imail = ((struct mail_private *)mail)->v.get_index_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
|
1056 |
4949
a959d4208b54
Moved storage callbacks to struct mail_storage. If searching takes over 10
Timo Sirainen <tss@iki.fi>
parents:
4942
diff
changeset
|
1057 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
|
1058 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
|
1059 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
|
1060 |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1061 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
|
1062 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
|
1063 |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1064 if (_ctx->update_result == NULL) |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1065 never = FALSE; |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1066 else { |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1067 /* see if this message never matches */ |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1068 never = seq_range_exists(&_ctx->update_result->never_uids, |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1069 mail->uid); |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1070 if (!never && |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1071 seq_range_exists(&_ctx->update_result->uids, |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1072 mail->uid)) { |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1073 /* we already know that the static data |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1074 matches. mark it as such. */ |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1075 search_set_static_matches(_ctx->args->args); |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1076 } |
7647
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1077 } |
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1078 |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1079 if (never) { |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1080 ret = 0; |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1081 } else T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
1082 ret = search_match_next(ctx) ? 1 : 0; |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1083 |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1084 if (ret == 0 && |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1085 search_has_static_nonmatches(_ctx->args->args)) { |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1086 /* if there are saved search results remember |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1087 that this message never matches */ |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1088 mailbox_search_results_never(_ctx, mail->uid); |
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1089 } |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
1090 } T_END; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1091 |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1092 mail_search_args_reset(_ctx->args->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
|
1093 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
1094 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
|
1095 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
|
1096 if (ret != 0) { |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1097 if (_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
|
1098 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1099 |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1100 index_sort_list_add(_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
|
1101 } |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1102 |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1103 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
|
1104 *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
|
1105 return 0; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1106 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
1107 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1108 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
|
1109 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
|
1110 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
|
1111 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
|
1112 |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1113 if (_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
|
1114 /* 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
|
1115 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
|
1116 ctx->sorted = TRUE; |
7671
882888286bf5
Saved search results: Remember what messages' static checks never match, so
Timo Sirainen <tss@iki.fi>
parents:
7647
diff
changeset
|
1117 index_sort_list_finish(_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
|
1118 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
|
1119 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
|
1120 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4259
diff
changeset
|
1121 |
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
|
1122 return ret; |
0 | 1123 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1124 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1125 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
|
1126 { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1127 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
|
1128 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
|
1129 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1130 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
|
1131 /* 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
|
1132 _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
|
1133 } else { |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1134 _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
|
1135 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1136 |
7620 | 1137 if (!ctx->have_seqsets && !ctx->have_index_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
|
1138 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
|
1139 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1140 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
|
1141 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
|
1142 /* check if the sequence matches */ |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
1143 ret = mail_search_args_foreach(ctx->mail_ctx.args->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
|
1144 search_seqset_arg, ctx); |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
1145 if (ret != 0) { |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
1146 /* check if flags/keywords match before anything else |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
1147 is done. mail_set_seq() can be a bit slow. */ |
7620 | 1148 if (!ctx->have_index_args) |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
1149 break; |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
1150 ret = mail_search_args_foreach(ctx->mail_ctx.args->args, |
6966
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
1151 search_index_arg, ctx); |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
1152 if (ret != 0) |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
1153 break; |
7bb6ef75715c
Optimize searching flags and keywords.
Timo Sirainen <tss@iki.fi>
parents:
6965
diff
changeset
|
1154 } |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1155 |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1156 /* 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
|
1157 _ctx->seq++; |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7640
diff
changeset
|
1158 mail_search_args_reset(ctx->mail_ctx.args->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
|
1159 } |
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4062
diff
changeset
|
1160 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
|
1161 } |