annotate src/lib-storage/index/index-search.c @ 3039:d6910d273852 HEAD

Added rfc822 parser which will probably replace message_tokenizer at some point. Rewrote address parsing with the new parser. This fixes various bugs in it.
author Timo Sirainen <tss@iki.fi>
date Thu, 06 Jan 2005 20:14:28 +0200
parents 61c8d205d887
children 923ff19873d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2002 Timo Sirainen */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "mail-search.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #include <stdlib.h>
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <ctype.h>
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
24 struct mail_index_view *view;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
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
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
69
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
70 num = 0;
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
71 while (*str != '\0') {
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
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
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
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
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
77 }
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
78
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
79 return num;
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
80 }
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
81
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
83 static int search_arg_match_index(struct index_mail *imail,
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
84 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
85 const char *value)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 {
1947
777da553d1d3 Recent-flag should work now
Timo Sirainen <tss@iki.fi>
parents: 1917
diff changeset
87 const struct mail_index_record *rec = imail->data.rec;
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
88 const char *const *keywords;
1947
777da553d1d3 Recent-flag should work now
Timo Sirainen <tss@iki.fi>
parents: 1917
diff changeset
89
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 switch (type) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 case SEARCH_ALL:
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
92 return 1;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 /* flags */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 case SEARCH_ANSWERED:
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
96 return rec->flags & MAIL_ANSWERED;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 case SEARCH_DELETED:
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
98 return rec->flags & MAIL_DELETED;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 case SEARCH_DRAFT:
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
100 return rec->flags & MAIL_DRAFT;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 case SEARCH_FLAGGED:
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
102 return rec->flags & MAIL_FLAGGED;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 case SEARCH_SEEN:
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
104 return rec->flags & MAIL_SEEN;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 case SEARCH_RECENT:
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
106 return imail->mail.get_flags(&imail->mail) & MAIL_RECENT;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 case SEARCH_KEYWORD:
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
108 keywords = imail->mail.get_keywords(&imail->mail);
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
109 if (keywords != NULL) {
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
110 while (*keywords != NULL) {
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
111 if (strcasecmp(*keywords, value) == 0)
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
112 return 1;
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
113 keywords++;
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
114 }
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
115 }
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
116 return 0;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 default:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 return -1;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
123 static void search_index_arg(struct mail_search_arg *arg, void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
125 struct index_search_context *ctx = context;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
126 int found;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
127
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
128 if (arg->type == SEARCH_SEQSET) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
129 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
130 ARG_SET_RESULT(arg, found);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
131 return;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
132 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
133
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
134 if (ctx->imail.data.rec == NULL) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
135 /* expunged message */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
136 ARG_SET_RESULT(arg, 0);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
137 return;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
138 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
140 switch (search_arg_match_index(&ctx->imail, arg->type,
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
141 arg->value.str)) {
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 case -1:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 /* unknown */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 case 0:
1069
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
146 ARG_SET_RESULT(arg, 0);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 default:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 ARG_SET_RESULT(arg, 1);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
154 /* 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
155 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
156 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
157 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
158 {
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
159 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
160 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
161 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
162
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
163 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
164 /* 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
165 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
166 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
167 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
168 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
169 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
170 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
171
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
172 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
173 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
174
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 default:
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
184 /* unreachable */
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
185 break;
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
186 }
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
187
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
188 /* 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
189 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
190 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
191 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
192 /* 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
193 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
194 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
195 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
196 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
197 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
198
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
199 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
200 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
201
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 default:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
211 /* unreachable */
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
212 break;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
213 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
214
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
215 /* sizes */
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
216 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
217 case SEARCH_LARGER:
2504
98f6057f27a1 Added mail.get_physical_size().
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
218 virtual_size = ctx->mail->get_virtual_size(ctx->mail);
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
219 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
220 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
221
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
222 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
223 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
224 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
225 else
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
226 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
227
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
228 default:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
229 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
230 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
231 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
232
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
233 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
234 {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
235 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
236
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
237 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
238 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
239 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
240 /* unknown */
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
241 break;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
242 case 0:
1069
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
243 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
244 break;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
245 default:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
246 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
247 break;
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 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
250
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
251 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
252 const unsigned char *sent_value, size_t sent_value_len)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 {
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
254 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
255 int timezone_offset;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
256
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
257 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
258 return 0;
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
259
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
260 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
261 return 0;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
262
1340
087a9f4304ca s/latest IMAP4rev1 draft/RFC-3501/
Timo Sirainen <tss@iki.fi>
parents: 1322
diff changeset
263 /* 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
264 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
265 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
266 &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
267 return 0;
1604
6a18854e6856 Still more timezone fixes
Timo Sirainen <tss@iki.fi>
parents: 1552
diff changeset
268 sent_time += timezone_offset * 60;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
270 switch (type) {
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
271 case SEARCH_SENTBEFORE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
272 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
273 case SEARCH_SENTON:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
274 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
275 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
276 case SEARCH_SENTSINCE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
277 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
278 default:
546
e1254b838e0b Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents: 534
diff changeset
279 i_unreached();
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
280 }
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
281 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
283 static struct header_search_context *
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
284 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
285 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
286 {
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
287 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
288
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
289 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
290 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
291 return arg->context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
294 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
295 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
296 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
297 }
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
298
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
299 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
300 ctx->charset,
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
301 &unknown_charset);
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
302 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
303 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
304 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
305 }
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
306
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
307 return arg->context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
308 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
310 static void search_header_arg(struct mail_search_arg *arg, void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
312 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
313 struct header_search_context *hdr_search_ctx;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314 int ret;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316 /* first check that the field name matches to argument. */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 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
318 case SEARCH_SENTBEFORE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
319 case SEARCH_SENTON:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
320 case SEARCH_SENTSINCE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
321 /* 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
322 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
323 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
324 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
325 return;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
326 }
1070
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
327 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
328 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
329 ctx->hdr->full_value_len);
1070
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
330 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
331 }
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
332 return;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
333
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334 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
335 case SEARCH_HEADER_ADDRESS:
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
336 ctx->custom_header = TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
338 if (strcasecmp(ctx->hdr->name, arg->hdr_field_name) != 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 return;
569
cafe57140f5c SEARCH TEXT now checks only field values (not names) from headers. RFC
Timo Sirainen <tss@iki.fi>
parents: 568
diff changeset
340 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
341 /* 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
342 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
343 break;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 default:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
348 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
349 /* 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
350 ret = 1;
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
351 } else {
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
352 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
353 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
354 return;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
355 }
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
356
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
357 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
358
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
359 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
360 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
361 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
362 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
363 /* 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
364 struct message_address *addr;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
365 string_t *str;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
366
1782
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1765
diff changeset
367 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
368 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
369 ctx->hdr->full_value_len,
3039
d6910d273852 Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents: 3016
diff changeset
370 (unsigned int)-1);
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
371 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
372 message_address_write(str, addr);
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
373 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
374 hdr_search_ctx) ? 1 : 0;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
375 } else {
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
376 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
377 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
378 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
379 }
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
380 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
381 }
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
382
1069
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
383 if (ret == 1 ||
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
384 (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
385 /* 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
386 ARG_SET_RESULT(arg, ret);
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
387 }
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
388 }
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
389
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
390 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
391 void *context __attr_unused__)
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
392 {
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
393 switch (arg->type) {
1070
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
394 case SEARCH_SENTBEFORE:
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
395 case SEARCH_SENTON:
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
396 case SEARCH_SENTSINCE:
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
397 if (arg->not) {
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
398 /* date header not found, so we match only for
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
399 NOT searches */
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
400 ARG_SET_RESULT(arg, 0);
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
401 }
5c34c363a062 Fixes to SEARCH SENT*
Timo Sirainen <tss@iki.fi>
parents: 1069
diff changeset
402 break;
1069
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
403 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
404 case SEARCH_HEADER_ADDRESS:
1069
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
405 ARG_SET_RESULT(arg, 0);
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
406 break;
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
407 default:
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
408 break;
8024a2cdc406 Several search fixes, mostly related to matching multiple conditions.
Timo Sirainen <tss@iki.fi>
parents: 1066
diff changeset
409 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2899
diff changeset
412 static void search_header(struct message_part *part __attr_unused__,
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
413 struct message_header_line *hdr, void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
415 struct search_header_context *ctx = context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416
1322
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
417 if (hdr == NULL) {
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
418 /* 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
419 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
420 return;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
421 }
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
422
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
423 if (hdr->eoh)
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
424 return;
97f8c00b8d4c Better handling for multiline headers. Before we skipped headers larger than
Timo Sirainen <tss@iki.fi>
parents: 1070
diff changeset
425
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
426 index_mail_parse_header(NULL, hdr, &ctx->index_context->imail);
924
4f697dde0fca THREAD=REFERENCES implementation. Doesn't crash, but I'm not sure how
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
427
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
428 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
429 ctx->hdr = hdr;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
431 ctx->custom_header = FALSE;
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
432 mail_search_args_foreach(ctx->args, search_header_arg, ctx);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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 static void search_body(struct mail_search_arg *arg, void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
438 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
439 int ret, unknown_charset;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
441 if (ctx->index_ctx->error != NULL)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
444 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
445 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
446 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
447 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
448 &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
449 ctx->part, arg->type == SEARCH_TEXT);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
451 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
452 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
453 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
454 }
290
3dcc2275b4ca IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents: 223
diff changeset
455
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
456 ARG_SET_RESULT(arg, ret > 0);
290
3dcc2275b4ca IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents: 223
diff changeset
457 }
5
1b34ec11fff8 Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
458 }
1b34ec11fff8 Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
459
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
460 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
461 struct index_search_context *ctx)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
463 struct istream *input;
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
464 struct mailbox_header_lookup_ctx *headers_ctx;
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
465 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
466 int have_headers, have_body;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 /* 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
469 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
470 if (!have_headers && !have_body)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
473 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
474 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
475
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
476 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
477 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
478
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
479 if (headers == NULL) {
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
480 headers_ctx = NULL;
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
481 input = ctx->mail->get_stream(ctx->mail, NULL, NULL);
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
482 if (input == NULL)
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
483 return FALSE;
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
484 } else {
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
485 /* FIXME: do this once in init */
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
486 headers_ctx =
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
487 mailbox_header_lookup_init(&ctx->ibox->box,
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
488 headers);
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
489 input = ctx->mail->get_headers(ctx->mail, headers_ctx);
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
490 if (input == NULL) {
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
491 mailbox_header_lookup_deinit(headers_ctx);
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
492 return FALSE;
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
493 }
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
494 }
715
3e952f64b2ec Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents: 678
diff changeset
495
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
496 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
497 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
498 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
499 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
500
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
501 index_mail_parse_header_init(&ctx->imail, headers_ctx);
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
502 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
503 search_header, &hdr_ctx);
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
504 if (headers_ctx != NULL)
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
505 mailbox_header_lookup_deinit(headers_ctx);
715
3e952f64b2ec Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents: 678
diff changeset
506 } else {
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
507 struct message_size hdr_size;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
508
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
509 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
510 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
511 return FALSE;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
512
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
513 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
514 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
515
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
516 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
517 struct search_body_context body_ctx;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
518
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
519 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
520 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
521 body_ctx.input = input;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
522 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
523
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
524 mail_search_args_foreach(args, search_body, &body_ctx);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
525 }
5
1b34ec11fff8 Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
526 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
527 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
528
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
529 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
530 const struct mail_index_header *hdr,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
531 struct mail_search_seqset *set,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
532 uint32_t *seq1_r, uint32_t *seq2_r)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
533 {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
534 for (; set != NULL; set = set->next) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
535 if (set->seq1 == (uint32_t)-1)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
536 set->seq1 = hdr->messages_count;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
537 if (set->seq2 == (uint32_t)-1)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
538 set->seq2 = hdr->messages_count;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
539
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
540 if (set->seq1 == 0 || set->seq2 == 0 ||
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
541 set->seq1 > hdr->messages_count ||
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
542 set->seq2 > hdr->messages_count) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
543 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
544 "Invalid messageset");
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
545 return -1;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
546 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
547
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
548 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
549 *seq1_r = set->seq1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
550 if (*seq2_r < set->seq2)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
551 *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
552 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
553 return 0;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
554 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
555
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
556 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
557 const struct mail_index_header *hdr,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
558 struct mail_search_arg *args,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
559 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
560 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
561 *seq1_r = *seq2_r = 0;
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
562
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
563 for (; args != NULL; args = args->next) {
1376
1664a3d51a74 More SEARCH OR fixes.
Timo Sirainen <tss@iki.fi>
parents: 1375
diff changeset
564 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
565 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
566 args->value.subargs,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
567 seq1_r, seq2_r) < 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
568 return -1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
569 } else if (args->type == SEARCH_OR) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
570 /* 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
571 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
572 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
573 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
574 right. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
575 *seq1_r = 1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
576 *seq2_r = hdr->messages_count;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
577
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
578 /* 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
579 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
580 args->value.subargs,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
581 seq1_r, seq2_r) < 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
582 return -1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
583 } else if (args->type == SEARCH_SEQSET) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
584 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
585 seq1_r, seq2_r) < 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
586 return -1;
1376
1664a3d51a74 More SEARCH OR fixes.
Timo Sirainen <tss@iki.fi>
parents: 1375
diff changeset
587 } else if (args->type == SEARCH_ALL) {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
588 /* 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
589 seqsets. */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
590 *seq1_r = 1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
591 *seq2_r = hdr->messages_count;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
592 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
593 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
594 return 0;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
595 }
962
3b139ccc1858 SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents: 951
diff changeset
596
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
597 static int search_limit_lowwater(struct index_search_context *ctx,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
598 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
599 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
600 uint32_t seq1, seq2;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
601
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
602 if (uid_lowwater == 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
603 return 0;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
604
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
605 if (mail_index_lookup_uid_range(ctx->view, uid_lowwater,
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
606 (uint32_t)-1, &seq1, &seq2) < 0) {
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
607 mail_storage_set_index_error(ctx->ibox);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
608 return -1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
609 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
610
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
611 if (*first_seq < seq1)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
612 *first_seq = seq1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
613 return 0;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
614 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
615
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
616 static int search_limit_by_flags(struct index_search_context *ctx,
1917
68938dccbc45 Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
617 const struct mail_index_header *hdr,
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
618 struct mail_search_arg *args,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
619 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
620 {
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
621 for (; args != NULL; args = args->next) {
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
622 if (args->type == SEARCH_SEEN) {
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
623 /* SEEN with 0 seen? */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
624 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
625 return 0;
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
626
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
627 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
628 /* UNSEEN with all seen? */
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
629 if (args->not)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
630 return 0;
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
631
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
632 /* SEEN with all seen */
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
633 args->match_always = TRUE;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
634 } else if (args->not) {
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
635 /* UNSEEN with lowwater limiting */
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
636 if (search_limit_lowwater(ctx,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
637 hdr->first_unseen_uid_lowwater,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
638 seq1) < 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
639 return -1;
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
640 }
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
641 }
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
642
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
643 if (args->type == SEARCH_DELETED) {
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
644 /* DELETED with 0 deleted? */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
645 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
646 return 0;
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
647
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
648 if (hdr->deleted_messages_count ==
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
649 hdr->messages_count) {
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
650 /* UNDELETED with all deleted? */
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
651 if (args->not)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
652 return 0;
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
653
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
654 /* DELETED with all deleted */
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
655 args->match_always = TRUE;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
656 } else if (!args->not) {
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
657 /* DELETED with lowwater limiting */
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
658 if (search_limit_lowwater(ctx,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
659 hdr->first_deleted_uid_lowwater,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
660 seq1) < 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
661 return -1;
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
662 }
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
663 }
962
3b139ccc1858 SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents: 951
diff changeset
664 }
3b139ccc1858 SEARCH didn't properly complain about invalid messagesets. high:low never
Timo Sirainen <tss@iki.fi>
parents: 951
diff changeset
665
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
666 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
667 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
668
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
669 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
670 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
671 {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
672 const struct mail_index_header *hdr;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
673
2892
62d53b49110d Changed mail_index_get_header() to return the header as return value because
Timo Sirainen <tss@iki.fi>
parents: 2883
diff changeset
674 hdr = mail_index_get_header(ctx->view);
1985
3ccd4eb52ee4 don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
675 if (hdr->messages_count == 0) {
2899
1a05764af1e0 UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
676 /* no messages, don't check sequence ranges. although we could
1a05764af1e0 UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
677 give error message then for FETCH, we shouldn't do it for
1a05764af1e0 UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
678 UID FETCH. */
1985
3ccd4eb52ee4 don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
679 ctx->seq1 = 1;
3ccd4eb52ee4 don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
680 ctx->seq2 = 0;
3ccd4eb52ee4 don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
681 return 0;
3ccd4eb52ee4 don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
682 }
3ccd4eb52ee4 don't crash when requesting messages from empty mailbox
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
683
2899
1a05764af1e0 UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
684 if (search_parse_msgset_args(ctx->ibox, hdr, args,
1a05764af1e0 UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
685 &ctx->seq1, &ctx->seq2) < 0)
1a05764af1e0 UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
686 return -1;
1a05764af1e0 UID FETCH * gave error message with empty mailbox.
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
687
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
688 if (ctx->seq1 == 0) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
689 ctx->seq1 = 1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
690 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
691 }
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
692
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
693 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
694
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
695 /* UNSEEN and DELETED in root search level may limit the range */
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
696 if (search_limit_by_flags(ctx, hdr, args,
1917
68938dccbc45 Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
697 &ctx->seq1, &ctx->seq2) < 0)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
698 return -1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
699 return 0;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
700 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
701
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
702 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
703 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
704 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
705 /* 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
706 *sort_program = MAIL_SORT_END;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
707 return 0;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
708 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
709
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
710 struct mail_search_context *
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
711 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
712 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
713 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
714 enum mail_fetch_field wanted_fields,
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
715 struct mailbox_header_lookup_ctx *wanted_headers)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
716 {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
717 struct index_transaction_context *t =
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
718 (struct index_transaction_context *)_t;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
719 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
720
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
721 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
722 i_fatal("BUG: index_storage_search_init(): "
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
723 "invalid sort_program");
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
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
726 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
727 ctx->mail_ctx.box = &t->ibox->box;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
728 ctx->ibox = t->ibox;
2224
a816e2d88406 Added mail_index_transaction_get_updated_view() which can be used to access
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
729 ctx->view = t->trans_view;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
730 ctx->charset = i_strdup(charset);
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
731 ctx->args = args;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
732
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
733 ctx->mail = &ctx->imail.mail;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
734 index_mail_init(t, &ctx->imail, wanted_fields, wanted_headers);
51
b4adc3429867 Some cleanups, assertion fixes.
Timo Sirainen <tss@iki.fi>
parents: 50
diff changeset
735
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
736 mail_search_args_reset(ctx->args, TRUE);
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
737
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
738 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
739 ctx->failed = TRUE;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
740 ctx->seq1 = 1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
741 ctx->seq2 = 0;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
742 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
743 return &ctx->mail_ctx;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
744 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
745
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
746 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
747 {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
748 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
749 int ret;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
750
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
751 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
752
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
753 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
754 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
755
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
756 if (ctx->error != NULL) {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
757 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
758 "%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
759 }
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
760
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
761 if (ctx->hdr_pool != NULL)
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
762 pool_unref(ctx->hdr_pool);
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
763
2641
e357ebb3137b Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 2504
diff changeset
764 i_free(ctx->charset);
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
765 i_free(ctx);
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
766 return ret;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
767 }
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
768
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
769 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
770 {
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
771 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
772 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
773
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
774 /* check the index matches first */
1844
4c2678dd65f1 Some optimizations to messageset handling in search.
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
775 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
776 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
777 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
778 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
779
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
780 if (ctx->imail.data.rec == NULL) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
781 /* 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
782 matched */
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
783 return FALSE;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
784 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
785
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
786 /* 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
787 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
788 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
789 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
790
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
791 /* 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
792 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
793 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
794
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
795 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
796 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
797 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
798 }
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
799
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
800 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
801 }
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
802
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
803 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
804 {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
805 struct index_search_context *ctx = (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
806 int ret;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
807
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
808 ret = 0;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
809 while (ctx->seq1 <= ctx->seq2) {
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2224
diff changeset
810 if (index_mail_next(&ctx->imail, ctx->seq1++) < 0) {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
811 ctx->failed = TRUE;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
812 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
813 }
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
814
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
815 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
816 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
817 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
818
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
819 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
820 ret = -1;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
821 if (ret != 0)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
822 break;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
823 }
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1638
diff changeset
824
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
825 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
826 /* 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
827 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
828 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
829
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 962
diff changeset
830 return ctx->mail;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
831 }