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