Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/index-search.c @ 1985:3ccd4eb52ee4 HEAD
don't crash when requesting messages from empty mailbox
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 10 May 2004 02:20:04 +0300 |
parents | 4dec6a3d79fd |
children | 418a0de45c38 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "lib.h" | |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
761
diff
changeset
|
4 #include "istream.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
5 #include "str.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
6 #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
|
7 #include "message-date.h" |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
8 #include "message-body-search.h" |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
9 #include "message-header-search.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
10 #include "message-parser.h" |
119
2f67de235489
Whops, we were using RFC822 dates everywhere instead of IMAP dates.
Timo Sirainen <tss@iki.fi>
parents:
109
diff
changeset
|
11 #include "imap-date.h" |
0 | 12 #include "index-storage.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
13 #include "index-mail.h" |
0 | 14 #include "mail-search.h" |
15 | |
16 #include <stdlib.h> | |
17 #include <ctype.h> | |
18 | |
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
|
19 #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
|
20 #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
|
21 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
22 struct index_search_context { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
23 struct mail_search_context mail_ctx; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
24 struct index_transaction_context *trans; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
25 struct index_mailbox *ibox; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
26 char *charset; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
27 struct mail_search_arg *args; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
28 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
29 uint32_t seq1, seq2; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
30 struct index_mail imail; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
31 struct mail *mail; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
32 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
33 pool_t hdr_pool; |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
34 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
|
35 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
36 int failed; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
37 }; |
0 | 38 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
39 struct search_header_context { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
40 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
|
41 struct mail_search_arg *args; |
0 | 42 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
43 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
|
44 |
4f697dde0fca
THREAD=REFERENCES implementation. Doesn't crash, but I'm not sure how
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
45 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
|
46 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
|
47 }; |
0 | 48 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
49 struct search_body_context { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
50 struct index_search_context *index_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
|
51 struct istream *input; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
52 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
|
53 }; |
0 | 54 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
55 static int seqset_contains(struct mail_search_seqset *set, uint32_t seq) |
0 | 56 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
57 while (set != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
58 if (seq >= set->seq1 && seq <= set->seq2) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
59 return TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
60 set = set->next; |
0 | 61 } |
62 | |
63 return FALSE; | |
64 } | |
65 | |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
46
diff
changeset
|
66 static uoff_t str_to_uoff_t(const char *str) |
46 | 67 { |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
46
diff
changeset
|
68 uoff_t num; |
46 | 69 |
70 num = 0; | |
71 while (*str != '\0') { | |
72 if (*str < '0' || *str > '9') | |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
46
diff
changeset
|
73 return 0; |
46 | 74 |
50
d493b9cc265e
Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed
Timo Sirainen <tss@iki.fi>
parents:
46
diff
changeset
|
75 num = num*10 + (*str - '0'); |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
76 str++; |
46 | 77 } |
78 | |
79 return num; | |
80 } | |
81 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
82 static int search_keyword(struct mail_index *index, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
83 const struct mail_index_record *rec, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
84 const char *value) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
85 { |
1958 | 86 const char **keywords; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
87 int i; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
88 |
1958 | 89 for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) { |
90 if (rec->keywords[i] != 0) | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
91 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
92 } |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
93 |
1958 | 94 if (i == INDEX_KEYWORDS_BYTE_COUNT) |
95 return FALSE; /* no keywords set */ | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
96 |
1958 | 97 /*FIXME:keywords = mail_keywords_list_get(index->keywords); |
98 for (i = 0; i < MAIL_KEYWORDS_COUNT; i++) { | |
99 if (keywords[i] != NULL && | |
100 strcasecmp(keywords[i], value) == 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
|
101 return rec->msg_flags & |
1958 | 102 (1 << (MAIL_KEYWORD_1_BIT+i)); |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
103 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
104 }*/ |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
105 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
106 return FALSE; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
107 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
108 |
0 | 109 /* Returns >0 = matched, 0 = not matched, -1 = unknown */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
110 static int search_arg_match_index(struct index_mailbox *ibox, |
1947 | 111 struct index_mail *imail, |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
112 enum mail_search_arg_type type, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
113 const char *value) |
0 | 114 { |
1947 | 115 const struct mail_index_record *rec = imail->data.rec; |
116 const struct mail_full_flags *full_flags; | |
117 | |
0 | 118 switch (type) { |
119 case SEARCH_ALL: | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
120 return 1; |
0 | 121 |
122 /* flags */ | |
123 case SEARCH_ANSWERED: | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
124 return rec->flags & MAIL_ANSWERED; |
0 | 125 case SEARCH_DELETED: |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
126 return rec->flags & MAIL_DELETED; |
0 | 127 case SEARCH_DRAFT: |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
128 return rec->flags & MAIL_DRAFT; |
0 | 129 case SEARCH_FLAGGED: |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
130 return rec->flags & MAIL_FLAGGED; |
0 | 131 case SEARCH_SEEN: |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
132 return rec->flags & MAIL_SEEN; |
0 | 133 case SEARCH_RECENT: |
1947 | 134 full_flags = imail->mail.get_flags(&imail->mail); |
135 return full_flags->flags & MAIL_RECENT; | |
0 | 136 case SEARCH_KEYWORD: |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
137 return search_keyword(ibox->index, rec, value); |
0 | 138 |
139 default: | |
140 return -1; | |
141 } | |
142 } | |
143 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
144 static void search_index_arg(struct mail_search_arg *arg, void *context) |
0 | 145 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
146 struct index_search_context *ctx = context; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
147 int found; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
148 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
149 if (arg->type == SEARCH_SEQSET) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
150 found = seqset_contains(arg->value.seqset, ctx->mail->seq); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
151 ARG_SET_RESULT(arg, found); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
152 return; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
153 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
154 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
155 if (ctx->imail.data.rec == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
156 /* expunged message */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
157 ARG_SET_RESULT(arg, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
158 return; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
159 } |
0 | 160 |
1947 | 161 switch (search_arg_match_index(ctx->ibox, &ctx->imail, |
0 | 162 arg->type, arg->value.str)) { |
163 case -1: | |
164 /* unknown */ | |
165 break; | |
166 case 0: | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
167 ARG_SET_RESULT(arg, 0); |
0 | 168 break; |
169 default: | |
170 ARG_SET_RESULT(arg, 1); | |
171 break; | |
172 } | |
173 } | |
174 | |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
175 /* 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
|
176 static int search_arg_match_cached(struct index_search_context *ctx, |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
177 enum mail_search_arg_type type, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
178 const char *value) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
179 { |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
180 time_t date, search_time; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
181 uoff_t virtual_size, search_size; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
182 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
|
183 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
184 switch (type) { |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
185 /* 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
|
186 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
|
187 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
|
188 case SEARCH_SINCE: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
189 date = ctx->mail->get_received_date(ctx->mail); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
190 if (date == (time_t)-1) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
191 return -1; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
192 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
193 if (!imap_parse_date(value, &search_time)) |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
194 return 0; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
195 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
196 switch (type) { |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
197 case SEARCH_BEFORE: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
198 return date < search_time; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
199 case SEARCH_ON: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
200 return date >= search_time && |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
201 date < search_time + 3600*24; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
202 case SEARCH_SINCE: |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
203 return date >= search_time; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
204 default: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
205 /* unreachable */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
206 break; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
207 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
208 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
209 /* 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
|
210 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
|
211 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
|
212 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
|
213 /* 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
|
214 in searches. date is returned as UTC, so change it. */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
215 date = ctx->mail->get_date(ctx->mail, &timezone_offset); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
216 if (date == (time_t)-1) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
217 return -1; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
218 date += timezone_offset * 60; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
219 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
220 if (!imap_parse_date(value, &search_time)) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
221 return 0; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
222 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
223 switch (type) { |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
224 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
|
225 return date < search_time; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
226 case SEARCH_SENTON: |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
227 return date >= search_time && |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
228 date < search_time + 3600*24; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
229 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
|
230 return date >= search_time; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
231 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
232 /* unreachable */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
233 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
234 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
235 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
236 /* sizes */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
237 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
|
238 case SEARCH_LARGER: |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
239 virtual_size = ctx->mail->get_size(ctx->mail); |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
240 if (virtual_size == (uoff_t)-1) |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
241 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
|
242 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
243 search_size = str_to_uoff_t(value); |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
244 if (type == SEARCH_SMALLER) |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
245 return virtual_size < search_size; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
246 else |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
247 return virtual_size > search_size; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
248 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
249 default: |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
250 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
|
251 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
252 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
253 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
254 static void search_cached_arg(struct mail_search_arg *arg, void *context) |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
255 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
256 struct index_search_context *ctx = context; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
257 |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
258 switch (search_arg_match_cached(ctx, arg->type, |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
259 arg->value.str)) { |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
260 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
|
261 /* unknown */ |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
262 break; |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
263 case 0: |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
264 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
|
265 break; |
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 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
|
268 break; |
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 } |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
505
diff
changeset
|
271 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
272 static int search_sent(enum mail_search_arg_type type, const char *search_value, |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
273 const unsigned char *sent_value, size_t sent_value_len) |
0 | 274 { |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
275 time_t search_time, sent_time; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
276 int timezone_offset; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
277 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
278 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
|
279 return 0; |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
280 |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
281 if (!imap_parse_date(search_value, &search_time)) |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
282 return 0; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
283 |
1340
087a9f4304ca
s/latest IMAP4rev1 draft/RFC-3501/
Timo Sirainen <tss@iki.fi>
parents:
1322
diff
changeset
|
284 /* 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
|
285 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
|
286 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
|
287 &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
|
288 return 0; |
1604 | 289 sent_time += timezone_offset * 60; |
0 | 290 |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
291 switch (type) { |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
292 case SEARCH_SENTBEFORE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
293 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
|
294 case SEARCH_SENTON: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
295 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
|
296 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
|
297 case SEARCH_SENTSINCE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
298 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
|
299 default: |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
534
diff
changeset
|
300 i_unreached(); |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
301 } |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
302 } |
0 | 303 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
304 static struct header_search_context * |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
305 search_header_context(struct index_search_context *ctx, |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
306 struct mail_search_arg *arg) |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
307 { |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
308 int unknown_charset; |
408
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
309 |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
310 if (arg->context != NULL) { |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
311 message_header_search_reset(arg->context); |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
312 return arg->context; |
0 | 313 } |
314 | |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
315 if (ctx->hdr_pool == NULL) { |
825
8afbafd5deac
We don't have separate read-write pools, so renamed pool_create(.., FALSE)
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
316 ctx->hdr_pool = |
8afbafd5deac
We don't have separate read-write pools, so renamed pool_create(.., FALSE)
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
317 pool_alloconly_create("message_header_search", 8192); |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
318 } |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
319 |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
320 arg->context = message_header_search_init(ctx->hdr_pool, arg->value.str, |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
321 ctx->charset, |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
322 &unknown_charset); |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
323 if (arg->context == NULL) { |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
324 ctx->error = 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
|
325 TXT_UNKNOWN_CHARSET : TXT_INVALID_SEARCH_KEY; |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
326 } |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
327 |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
328 return arg->context; |
0 | 329 } |
330 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
331 static void search_header_arg(struct mail_search_arg *arg, void *context) |
0 | 332 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
333 struct search_header_context *ctx = context; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
334 struct header_search_context *hdr_search_ctx; |
0 | 335 int ret; |
336 | |
337 /* first check that the field name matches to argument. */ | |
338 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
|
339 case SEARCH_SENTBEFORE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
340 case SEARCH_SENTON: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
341 case SEARCH_SENTSINCE: |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
342 /* 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
|
343 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
|
344 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
|
345 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
|
346 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
347 } |
1070 | 348 ret = search_sent(arg->type, arg->value.str, |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
349 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
|
350 ctx->hdr->full_value_len); |
1070 | 351 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
|
352 } |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
353 return; |
e057845d94ca
Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
354 |
0 | 355 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
|
356 case SEARCH_HEADER_ADDRESS: |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
357 ctx->custom_header = TRUE; |
0 | 358 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
359 if (strcasecmp(ctx->hdr->name, arg->hdr_field_name) != 0) |
0 | 360 return; |
569
cafe57140f5c
SEARCH TEXT now checks only field values (not names) from headers. RFC
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
361 case SEARCH_TEXT: |
cafe57140f5c
SEARCH TEXT now checks only field values (not names) from headers. RFC
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
362 /* TEXT goes through all headers */ |
cafe57140f5c
SEARCH TEXT now checks only field values (not names) from headers. RFC
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
363 ctx->custom_header = TRUE; |
cafe57140f5c
SEARCH TEXT now checks only field values (not names) from headers. RFC
Timo Sirainen <tss@iki.fi>
parents:
568
diff
changeset
|
364 break; |
0 | 365 default: |
366 return; | |
367 } | |
368 | |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
369 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
|
370 /* we're just testing existence of the field. always matches. */ |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
371 ret = 1; |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
372 } else { |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
373 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
|
374 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
|
375 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
376 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
377 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
378 t_push(); |
765
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
764
diff
changeset
|
379 |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
380 hdr_search_ctx = search_header_context(ctx->index_context, arg); |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
381 if (hdr_search_ctx == NULL) |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
382 ret = 0; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
383 else if (arg->type == SEARCH_HEADER_ADDRESS) { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
384 /* we have to match against normalized address */ |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
385 struct message_address *addr; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
386 string_t *str; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
387 |
1782
2f3d906d99d8
data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents:
1765
diff
changeset
|
388 addr = message_address_parse(pool_datastack_create(), |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
389 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
|
390 ctx->hdr->full_value_len, |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
391 0); |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
392 str = t_str_new(ctx->hdr->value_len); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
393 message_address_write(str, addr); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
394 ret = message_header_search(str_data(str), str_len(str), |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
395 hdr_search_ctx) ? 1 : 0; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
396 } else { |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
397 ret = message_header_search(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
|
398 ctx->hdr->full_value_len, |
880
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
399 hdr_search_ctx) ? 1 : 0; |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
400 } |
d5168cca2052
SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
401 t_pop(); |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
402 } |
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
403 |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
404 if (ret == 1 || |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
405 (arg->type != SEARCH_TEXT && arg->type != SEARCH_HEADER)) { |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
406 /* set only when we definitely know if it's a match */ |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
407 ARG_SET_RESULT(arg, ret); |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
408 } |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
409 } |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
410 |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
411 static void search_header_unmatch(struct mail_search_arg *arg, |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
412 void *context __attr_unused__) |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
413 { |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
414 switch (arg->type) { |
1070 | 415 case SEARCH_SENTBEFORE: |
416 case SEARCH_SENTON: | |
417 case SEARCH_SENTSINCE: | |
418 if (arg->not) { | |
419 /* date header not found, so we match only for | |
420 NOT searches */ | |
421 ARG_SET_RESULT(arg, 0); | |
422 } | |
423 break; | |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
424 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
|
425 case SEARCH_HEADER_ADDRESS: |
1069
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
426 ARG_SET_RESULT(arg, 0); |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
427 break; |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
428 default: |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
429 break; |
8024a2cdc406
Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents:
1066
diff
changeset
|
430 } |
0 | 431 } |
432 | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
433 static void search_header(struct message_part *part, |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
434 struct message_header_line *hdr, void *context) |
0 | 435 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
436 struct search_header_context *ctx = context; |
0 | 437 |
1322
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
438 if (hdr == NULL) { |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
439 /* 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
|
440 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
|
441 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
442 } |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
443 |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
444 if (hdr->eoh) |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
445 return; |
97f8c00b8d4c
Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents:
1070
diff
changeset
|
446 |
1765
6c0c2ff2c113
Stop parsing cached headers when we've got everything.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
447 index_mail_parse_header(part, 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
|
448 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
449 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
|
450 ctx->hdr = hdr; |
0 | 451 |
10
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
452 ctx->custom_header = FALSE; |
82b7de533f98
s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
453 mail_search_args_foreach(ctx->args, search_header_arg, ctx); |
0 | 454 } |
455 } | |
456 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
457 static void search_body(struct mail_search_arg *arg, void *context) |
0 | 458 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
459 struct search_body_context *ctx = context; |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
460 int ret, unknown_charset; |
0 | 461 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
462 if (ctx->index_ctx->error != NULL) |
0 | 463 return; |
464 | |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
465 if (arg->type == SEARCH_TEXT || arg->type == SEARCH_BODY) { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
761
diff
changeset
|
466 i_stream_seek(ctx->input, 0); |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
467 ret = message_body_search(arg->value.str, |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
468 ctx->index_ctx->charset, |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
761
diff
changeset
|
469 &unknown_charset, ctx->input, |
716
dd574ac271c1
Body searching wasn't working with unknown charsets, and SEARCH BODY
Timo Sirainen <tss@iki.fi>
parents:
715
diff
changeset
|
470 ctx->part, arg->type == SEARCH_TEXT); |
0 | 471 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
472 if (ret < 0) { |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
473 ctx->index_ctx->error = unknown_charset ? |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
474 TXT_UNKNOWN_CHARSET : TXT_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
|
475 } |
290
3dcc2275b4ca
IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
476 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
477 ARG_SET_RESULT(arg, ret > 0); |
290
3dcc2275b4ca
IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents:
223
diff
changeset
|
478 } |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
479 } |
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
480 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
481 static int search_arg_match_text(struct mail_search_arg *args, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
482 struct index_search_context *ctx) |
0 | 483 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
484 struct istream *input; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
485 const char *const *headers; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
486 int have_headers, have_body; |
0 | 487 |
488 /* 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
|
489 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
|
490 if (!have_headers && !have_body) |
0 | 491 return TRUE; |
492 | |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
493 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
|
494 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
|
495 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
496 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
|
497 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
|
498 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
499 input = 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
|
500 ctx->mail->get_stream(ctx->mail, NULL, NULL) : |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
501 ctx->mail->get_headers(ctx->mail, headers); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
502 if (input == NULL) |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
503 return FALSE; |
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
504 |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
505 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
|
506 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
|
507 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
|
508 hdr_ctx.args = args; |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
509 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
510 index_mail_parse_header_init(&ctx->imail, headers); |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
761
diff
changeset
|
511 message_parse_header(NULL, input, NULL, |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
512 search_header, &hdr_ctx); |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
513 } else { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
514 struct message_size hdr_size; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
515 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
516 input = ctx->mail->get_stream(ctx->mail, &hdr_size, NULL); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
517 if (input == NULL) |
715
3e952f64b2ec
Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
518 return FALSE; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
519 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
520 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
|
521 } |
0 | 522 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
523 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
|
524 struct search_body_context body_ctx; |
0 | 525 |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
526 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
|
527 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
|
528 body_ctx.input = input; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
529 body_ctx.part = ctx->mail->get_parts(ctx->mail); |
608
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
530 |
debb8468514e
SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents:
569
diff
changeset
|
531 mail_search_args_foreach(args, search_body, &body_ctx); |
0 | 532 } |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
533 return TRUE; |
0 | 534 } |
535 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
536 static int search_msgset_fix(struct index_mailbox *ibox, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
537 const struct mail_index_header *hdr, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
538 struct mail_search_seqset *set, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
539 uint32_t *seq1_r, uint32_t *seq2_r) |
0 | 540 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
541 for (; set != NULL; set = set->next) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
542 if (set->seq1 == (uint32_t)-1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
543 set->seq1 = hdr->messages_count; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
544 if (set->seq2 == (uint32_t)-1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
545 set->seq2 = hdr->messages_count; |
0 | 546 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
547 if (set->seq1 == 0 || set->seq2 == 0 || |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
548 set->seq1 > hdr->messages_count || |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
549 set->seq2 > hdr->messages_count) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
550 mail_storage_set_syntax_error(ibox->box.storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
551 "Invalid messageset"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
552 return -1; |
0 | 553 } |
554 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
555 if (*seq1_r > set->seq1 || *seq1_r == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
556 *seq1_r = set->seq1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
557 if (*seq2_r < set->seq2) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
558 *seq2_r = set->seq2; |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
559 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
560 return 0; |
0 | 561 } |
562 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
563 static int search_parse_msgset_args(struct index_mailbox *ibox, |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
564 const struct mail_index_header *hdr, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
565 struct mail_search_arg *args, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
566 uint32_t *seq1_r, uint32_t *seq2_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
567 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
568 *seq1_r = *seq2_r = 0; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
569 |
0 | 570 for (; args != NULL; args = args->next) { |
1376 | 571 if (args->type == SEARCH_SUB) { |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
572 if (search_parse_msgset_args(ibox, hdr, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
573 args->value.subargs, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
574 seq1_r, seq2_r) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
575 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
576 } else if (args->type == SEARCH_OR) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
577 /* FIXME: in cases like "SEEN OR 5 7" we shouldn't |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
578 limit the range, but in cases like "1 OR 5 7" we |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
579 should expand the range. A bit tricky, we'll |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
580 just go through everything now to make it work |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
581 right. */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
582 *seq1_r = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
583 *seq2_r = hdr->messages_count; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
584 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
585 /* We still have to fix potential seqsets though */ |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
586 if (search_parse_msgset_args(ibox, hdr, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
587 args->value.subargs, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
588 seq1_r, seq2_r) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
589 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
590 } else if (args->type == SEARCH_SEQSET) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
591 if (search_msgset_fix(ibox, hdr, args->value.seqset, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
592 seq1_r, seq2_r) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
593 return -1; |
1376 | 594 } else if (args->type == SEARCH_ALL) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
595 /* go through everything. don't stop, have to fix |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
596 seqsets. */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
597 *seq1_r = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
598 *seq2_r = hdr->messages_count; |
0 | 599 } |
600 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
601 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
602 } |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
603 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
604 static int search_limit_lowwater(struct index_mailbox *ibox, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
605 uint32_t uid_lowwater, uint32_t *first_seq) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
606 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
607 uint32_t seq1, seq2; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
608 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
609 if (uid_lowwater == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
610 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
611 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
612 if (mail_index_lookup_uid_range(ibox->view, uid_lowwater, (uint32_t)-1, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
613 &seq1, &seq2) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
614 mail_storage_set_index_error(ibox); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
615 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
616 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
617 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
618 if (*first_seq < seq1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
619 *first_seq = seq1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
620 return 0; |
0 | 621 } |
622 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
623 static int search_limit_by_flags(struct index_mailbox *ibox, |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
624 const struct mail_index_header *hdr, |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
625 struct mail_search_arg *args, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
626 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
|
627 { |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
628 for (; args != NULL; args = args->next) { |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
629 if (args->type == SEARCH_SEEN) { |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
630 /* SEEN with 0 seen? */ |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
631 if (!args->not && hdr->seen_messages_count == 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
632 return 0; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
633 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
634 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
|
635 /* UNSEEN with all seen? */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
636 if (args->not) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
637 return 0; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
638 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
639 /* SEEN with all seen */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
640 args->match_always = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
641 } else if (args->not) { |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
642 /* UNSEEN with lowwater limiting */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
643 if (search_limit_lowwater(ibox, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
644 hdr->first_unseen_uid_lowwater, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
645 seq1) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
646 return -1; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
647 } |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
648 } |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
649 |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
650 if (args->type == SEARCH_DELETED) { |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
651 /* DELETED with 0 deleted? */ |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
652 if (!args->not && hdr->deleted_messages_count == 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
653 return 0; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
654 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
655 if (hdr->deleted_messages_count == |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
656 hdr->messages_count) { |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
657 /* UNDELETED with all deleted? */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
658 if (args->not) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
659 return 0; |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
660 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
661 /* DELETED with all deleted */ |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
662 args->match_always = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
663 } else if (!args->not) { |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
664 /* DELETED with lowwater limiting */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
665 if (search_limit_lowwater(ibox, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
666 hdr->first_deleted_uid_lowwater, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
667 seq1) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
668 return -1; |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
669 } |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
670 } |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
671 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
672 /*FIXME:if (args->type == SEARCH_RECENT) { |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
673 uid = ibox->index->first_recent_uid; |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
674 if (!args->not && *first_uid < uid) |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
675 *first_uid = ibox->index->first_recent_uid; |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
676 else if (args->not && *last_uid >= uid) |
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
677 *last_uid = uid-1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
678 }*/ |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
679 } |
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
680 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
681 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
|
682 } |
0 | 683 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
684 static int search_get_seqset(struct index_search_context *ctx, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
685 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
|
686 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
687 const struct mail_index_header *hdr; |
0 | 688 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
689 if (mail_index_get_header(ctx->ibox->view, &hdr) < 0) { |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
690 mail_storage_set_index_error(ctx->ibox); |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
691 return -1; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
692 } |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
693 |
1985
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
694 if (hdr->messages_count == 0) { |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
695 ctx->seq1 = 1; |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
696 ctx->seq2 = 0; |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
697 return 0; |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
698 } |
3ccd4eb52ee4
don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
699 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
700 if (search_parse_msgset_args(ctx->ibox, hdr, args, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
701 &ctx->seq1, &ctx->seq2) < 0) |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
702 return -1; |
0 | 703 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
704 if (ctx->seq1 == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
705 ctx->seq1 = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
706 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
|
707 } |
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
708 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
709 i_assert(ctx->seq1 <= ctx->seq2); |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
710 |
442
2a25bf21557b
SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents:
441
diff
changeset
|
711 /* UNSEEN and DELETED in root search level may limit the range */ |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
712 if (search_limit_by_flags(ctx->ibox, hdr, args, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
713 &ctx->seq1, &ctx->seq2) < 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
714 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
715 return 0; |
0 | 716 } |
717 | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
718 int index_storage_search_get_sorting(struct mailbox *box __attr_unused__, |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
719 enum mail_sort_type *sort_program) |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
720 { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
721 /* currently we don't support sorting */ |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
722 *sort_program = MAIL_SORT_END; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
723 return 0; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
724 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
725 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
726 struct mail_search_context * |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
727 index_storage_search_init(struct mailbox_transaction_context *_t, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
728 const char *charset, struct mail_search_arg *args, |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
729 const enum mail_sort_type *sort_program, |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
730 enum mail_fetch_field wanted_fields, |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
731 const char *const wanted_headers[]) |
0 | 732 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
733 struct index_transaction_context *t = |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
734 (struct index_transaction_context *)_t; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
735 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
|
736 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
737 if (sort_program != NULL && *sort_program != MAIL_SORT_END) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
738 i_fatal("BUG: index_storage_search_init(): " |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
739 "invalid sort_program"); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
740 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
741 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
742 /*FIXME:if (!index_storage_sync_and_lock(ibox, TRUE, TRUE, MAIL_LOCK_SHARED)) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
743 return NULL;*/ |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
744 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
745 ctx = i_new(struct index_search_context, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
746 ctx->mail_ctx.box = &t->ibox->box; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
747 ctx->trans = t; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
748 ctx->ibox = t->ibox; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
749 ctx->charset = i_strdup(charset); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
750 ctx->args = args; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
751 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
752 ctx->mail = &ctx->imail.mail; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
753 index_mail_init(t, &ctx->imail, wanted_fields, wanted_headers); |
51 | 754 |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
755 mail_search_args_reset(ctx->args, TRUE); |
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
756 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
757 if (search_get_seqset(ctx, args) < 0) { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
758 ctx->failed = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
759 ctx->seq1 = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
760 ctx->seq2 = 0; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
761 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
762 return &ctx->mail_ctx; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
763 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
764 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
765 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
|
766 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
767 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
|
768 int ret; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
769 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
770 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
|
771 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
772 if (ctx->imail.pool != NULL) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
773 index_mail_deinit(&ctx->imail); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
774 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
775 if (ctx->error != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
776 mail_storage_set_error(ctx->ibox->box.storage, |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
777 "%s", ctx->error); |
962
3b139ccc1858
SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents:
951
diff
changeset
|
778 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
779 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
780 if (ctx->hdr_pool != NULL) |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
781 pool_unref(ctx->hdr_pool); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
782 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
783 i_free(ctx); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
784 return ret; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
785 } |
327
276b7a53c264
Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents:
317
diff
changeset
|
786 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
787 static int 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
|
788 { |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
789 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
|
790 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
|
791 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
792 /* check the index matches first */ |
1844
4c2678dd65f1
Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
793 mail_search_args_reset(ctx->args, FALSE); |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
794 ret = mail_search_args_foreach(ctx->args, search_index_arg, ctx); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
795 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
|
796 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
|
797 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
798 if (ctx->imail.data.rec == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
799 /* expunged message, no way to check if the rest would have |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
800 matched */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
801 return FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
802 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
803 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
804 /* next search only from cached arguments */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
805 ret = mail_search_args_foreach(ctx->args, search_cached_arg, ctx); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
806 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
|
807 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
|
808 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
809 /* open the mail file and check the rest */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
810 if (!search_arg_match_text(ctx->args, ctx)) |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
811 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
|
812 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
813 for (arg = ctx->args; arg != NULL; arg = arg->next) { |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
814 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
|
815 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
|
816 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
817 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
818 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
|
819 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
820 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
821 struct mail *index_storage_search_next(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
|
822 { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
823 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
|
824 const struct mail_index_record *rec; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
825 int ret; |
0 | 826 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
827 ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
828 while (ctx->seq1 <= ctx->seq2) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
829 if (mail_index_lookup(ctx->ibox->view, ctx->seq1, &rec) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
830 ctx->failed = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
831 mail_storage_set_index_error(ctx->ibox); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
832 return 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
|
833 } |
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
|
834 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
835 ctx->imail.data.rec = rec; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
836 ctx->mail->seq = ctx->seq1++; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
837 ctx->mail->uid = rec == NULL ? 0 : rec->uid; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
838 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
839 ret = index_mail_next(&ctx->imail, rec, ctx->mail->seq, TRUE); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
840 if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
841 break; |
568
f2aa58c2afd0
SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents:
559
diff
changeset
|
842 |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
843 t_push(); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
844 ret = search_match_next(ctx); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
845 t_pop(); |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
846 |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
847 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
|
848 ret = -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
849 if (ret != 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
850 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
851 } |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
852 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
853 if (ret <= 0) { |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
854 /* error or last record */ |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
855 return NULL; |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1638
diff
changeset
|
856 } |
0 | 857 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
962
diff
changeset
|
858 return ctx->mail; |
0 | 859 } |