annotate src/lib-storage/index/index-search.c @ 903:fd8888f6f037 HEAD

Naming style changes, finally got tired of most of the typedefs. Also the previous enum -> macro change reverted so that we don't use the highest bit anymore, that's incompatible with old indexes so they will be rebuilt.
author Timo Sirainen <tss@iki.fi>
date Sun, 05 Jan 2003 15:09:51 +0200
parents 0d5be52d7131
children 4f697dde0fca
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"
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
5 #include "ostream.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "mmap-util.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"
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
8 #include "message-size.h"
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
9 #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
10 #include "message-header-search.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"
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
12 #include "imap-envelope.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include "index-storage.h"
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
14 #include "index-sort.h"
160
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
15 #include "mail-index-util.h"
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
16 #include "mail-modifylog.h"
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
17 #include "mail-custom-flags.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include "mail-search.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #include <stdlib.h>
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 #include <ctype.h>
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 #define ARG_SET_RESULT(arg, res) \
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 STMT_START { \
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 (arg)->result = !(arg)->not ? (res) : -(res); \
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 } STMT_END
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
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
28 #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
29 #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
30
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
31 struct search_index_context {
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
32 pool_t hdr_pool;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
33 struct index_mailbox *ibox;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
34 struct mail_index_record *rec;
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
35 unsigned int client_seq;
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
36 int cached;
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
37 const char *charset;
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
38 const char *error;
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 };
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
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 search_header_context {
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
42 struct search_index_context *index_context;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
43 struct mail_search_arg *args;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 int custom_header;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
46 const unsigned char *name, *value;
184
4223b9ed0c80 move size_t fixes
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
47 size_t name_len, value_len;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
48 };
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
50 struct search_body_context {
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 search_index_context *index_ctx;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
52 struct istream *input;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
53 struct message_part *part;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
54 };
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
56 static enum mail_sort_type sort_unsorted[] = { MAIL_SORT_END };
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
57
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 static int msgset_contains(const char *set, unsigned int match_num,
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 unsigned int max_num)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 unsigned int num, num2;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 while (*set != '\0') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 if (*set == '*') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 set++;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 num = max_num;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 } else {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 num = 0;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 while (*set >= '0' && *set <= '9') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 num = num*10 + (*set-'0');
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 set++;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 if (*set == ',' || *set == '\0') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 if (num == match_num)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 if (*set == '\0')
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 } else if (*set == ':') {
109
27fd7817b226 specifying messageset/uidset in SEARCH broke it
Timo Sirainen <tss@iki.fi>
parents: 66
diff changeset
81 set++;
27fd7817b226 specifying messageset/uidset in SEARCH broke it
Timo Sirainen <tss@iki.fi>
parents: 66
diff changeset
82
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 if (*set == '*') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 set++;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 if (match_num >= num && num <= max_num)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 } else {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 num2 = 0;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 while (*set >= '0' && *set <= '9') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 num2 = num2*10 + (*set-'0');
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 set++;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 if (match_num >= num && match_num <= num2)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 if (*set != ',')
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 set++;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 return FALSE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108
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
109 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
110 {
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
111 uoff_t num;
46
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
112
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
113 num = 0;
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
114 while (*str != '\0') {
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
115 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
116 return 0;
46
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
117
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
118 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
119 str++;
46
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
120 }
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
121
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
122 return num;
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
123 }
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
124
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
125 static int search_keyword(struct mail_index *index,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
126 struct mail_index_record *rec, 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
127 {
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
128 const char **custom_flags;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
129 int i;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
130
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
131 if ((rec->msg_flags & MAIL_CUSTOM_FLAGS_MASK) == 0)
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
132 return FALSE;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
133
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
134 custom_flags = mail_custom_flags_list_get(index->custom_flags);
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
135 for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
136 if (custom_flags[i] != NULL &&
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
137 strcasecmp(custom_flags[i], value) == 0) {
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
138 return rec->msg_flags &
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
139 (1 << (MAIL_CUSTOM_FLAG_1_BIT+i));
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
140 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
141 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
142
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
143 return FALSE;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
144 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
145
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
147 static int search_arg_match_index(struct index_mailbox *ibox,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
148 struct mail_index_record *rec,
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
149 unsigned int client_seq,
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
150 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
151 const char *value)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153 switch (type) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 case SEARCH_ALL:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 case SEARCH_SET:
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
157 return msgset_contains(value, client_seq,
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
158 ibox->synced_messages_count);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 case SEARCH_UID:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 return msgset_contains(value, rec->uid,
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 ibox->synced_messages_count);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 /* flags */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 case SEARCH_ANSWERED:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 return rec->msg_flags & MAIL_ANSWERED;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 case SEARCH_DELETED:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 return rec->msg_flags & MAIL_DELETED;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 case SEARCH_DRAFT:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 return rec->msg_flags & MAIL_DRAFT;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 case SEARCH_FLAGGED:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 return rec->msg_flags & MAIL_FLAGGED;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 case SEARCH_SEEN:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 return rec->msg_flags & MAIL_SEEN;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 case SEARCH_RECENT:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 return rec->uid >= ibox->index->first_recent_uid;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 case SEARCH_KEYWORD:
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
177 return search_keyword(ibox->index, rec, value);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 default:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 return -1;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
184 static void search_index_arg(struct mail_search_arg *arg, void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
186 struct search_index_context *ctx = context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
188 switch (search_arg_match_index(ctx->ibox, ctx->rec, ctx->client_seq,
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 arg->type, arg->value.str)) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190 case -1:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 /* unknown */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 case 0:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 ARG_SET_RESULT(arg, -1);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196 default:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 ARG_SET_RESULT(arg, 1);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
202 static struct imap_message_cache *
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
203 search_open_cache(struct search_index_context *ctx)
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
204 {
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
205 if (!ctx->cached) {
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
206 (void)index_msgcache_open(ctx->ibox->cache,
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
207 ctx->ibox->index, ctx->rec, 0);
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
208 ctx->cached = TRUE;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
209 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
210 return ctx->ibox->cache;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
211 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
212
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
213 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
214 static int search_arg_match_cached(struct search_index_context *ctx,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
215 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
216 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
217 {
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
218 time_t internal_date, 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
219 uoff_t 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
220
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
221 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
222 /* 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
223 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
224 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
225 case SEARCH_SINCE:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
226 internal_date = imap_msgcache_get_internal_date(
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
227 search_open_cache(ctx));
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
228 if (internal_date == (time_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
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 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
232 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
233
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
234 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
235 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
236 return internal_date < 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
237 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
238 return internal_date >= 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
239 internal_date < search_time + 3600*24;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
240 case SEARCH_SINCE:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
241 return internal_date >= 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
242 default:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
243 /* unreachable */
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 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
246
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
247 /* sizes */
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
248 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
249 case SEARCH_LARGER:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
250 virtual_size = imap_msgcache_get_virtual_size(
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
251 search_open_cache(ctx));
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
252 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
253 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
254
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
255 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
256 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
257 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
258 else
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
259 return 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
260
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
261 default:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
262 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
263 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
264 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
265
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
266 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
267 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
268 struct search_index_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
269
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
270 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
271 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
272 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
273 /* unknown */
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
274 break;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
275 case 0:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
276 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
277 break;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
278 default:
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
279 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
280 break;
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
281 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
282 }
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
283
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
284 static int search_sent(enum mail_search_arg_type type, const char *search_value,
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
285 const char *sent_value)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 {
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
287 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
288 int timezone_offset;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
289
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
290 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
291 return 0;
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
292
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
293 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
294 return 0;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
295
881
fe91b60fdb7c comment update
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
296 /* NOTE: Latest IMAP4rev1 draft specifies that timezone is ignored
fe91b60fdb7c comment update
Timo Sirainen <tss@iki.fi>
parents: 880
diff changeset
297 in searches. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
298 if (!message_date_parse(sent_value, &sent_time, &timezone_offset))
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
299 return 0;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
301 switch (type) {
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
302 case SEARCH_SENTBEFORE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
303 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
304 case SEARCH_SENTON:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
305 return sent_time >= search_time &&
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
306 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
307 case SEARCH_SENTSINCE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
308 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
309 default:
546
e1254b838e0b Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents: 534
diff changeset
310 i_unreached();
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
311 }
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
312 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
314 static struct header_search_context *
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
315 search_header_context(struct search_index_context *ctx,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
316 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
317 {
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
318 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
319
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
320 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
321 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
322 return arg->context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
325 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
326 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
327 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
328 }
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
329
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
330 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
331 ctx->charset,
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
332 &unknown_charset);
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
333 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
334 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
335 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
336 }
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
337
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
338 return arg->context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
342 static int search_arg_match_envelope(struct search_index_context *ctx,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
343 struct mail_search_arg *arg)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
345 struct mail_index *index = ctx->ibox->index;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
346 enum imap_envelope_field env_field;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
347 struct header_search_context *hdr_search_ctx;
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
348 const char *envelope, *field;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
349 int ret;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
350
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
351 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
352 case SEARCH_SENTBEFORE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
353 case SEARCH_SENTON:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
354 case SEARCH_SENTSINCE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
355 env_field = IMAP_ENVELOPE_DATE;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
356 break;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
357
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358 case SEARCH_FROM:
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
359 env_field = IMAP_ENVELOPE_FROM;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
360 break;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361 case SEARCH_TO:
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
362 env_field = IMAP_ENVELOPE_TO;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
363 break;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
364 case SEARCH_CC:
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
365 env_field = IMAP_ENVELOPE_CC;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
366 break;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 case SEARCH_BCC:
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
368 env_field = IMAP_ENVELOPE_BCC;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
369 break;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370 case SEARCH_SUBJECT:
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
371 env_field = IMAP_ENVELOPE_SUBJECT;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
372 break;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
373
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
374 case SEARCH_IN_REPLY_TO:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
375 env_field = IMAP_ENVELOPE_IN_REPLY_TO;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
376 break;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
377 case SEARCH_MESSAGE_ID:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
378 env_field = IMAP_ENVELOPE_MESSAGE_ID;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
379 break;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380 default:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381 return -1;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 }
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
383
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
384 t_push();
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
385
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
386 /* get field from hopefully cached envelope */
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
387 envelope = index->lookup_field(index, ctx->rec, DATA_FIELD_ENVELOPE);
792
d573c53946ac Full not-too-well-tested support for SORT extension. Required a few
Timo Sirainen <tss@iki.fi>
parents: 765
diff changeset
388 if (envelope != NULL) {
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
389 ret = imap_envelope_parse(envelope, env_field,
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
390 IMAP_ENVELOPE_RESULT_TYPE_STRING,
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
391 &field) ? 1 : -1;
792
d573c53946ac Full not-too-well-tested support for SORT extension. Required a few
Timo Sirainen <tss@iki.fi>
parents: 765
diff changeset
392 } else {
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
393 index->cache_fields_later(index, DATA_FIELD_ENVELOPE);
458
06377dd1e2a9 Added cache_fields_later() to MailIndex interface. That can be used to
Timo Sirainen <tss@iki.fi>
parents: 456
diff changeset
394 field = NULL;
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
395 ret = -1;
458
06377dd1e2a9 Added cache_fields_later() to MailIndex interface. That can be used to
Timo Sirainen <tss@iki.fi>
parents: 456
diff changeset
396 }
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
397
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
398 if (ret != -1) {
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
399 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
400 case SEARCH_SENTBEFORE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
401 case SEARCH_SENTON:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
402 case SEARCH_SENTSINCE:
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
403 ret = search_sent(arg->type, arg->value.str, field);
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
404 default:
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
405 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
406 /* we're just testing existence of the field.
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
407 assume it matches with non-NIL values. */
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
408 ret = field != NULL ? 1 : 0;
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
409 break;
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
410 }
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
411
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
412 if (field == NULL) {
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
413 /* doesn't exist */
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
414 ret = 0;
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
415 break;
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
416 }
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
417
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
418 hdr_search_ctx = search_header_context(ctx, arg);
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
419 if (hdr_search_ctx == NULL) {
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
420 ret = 0;
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
421 break;
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
422 }
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
423
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
424 ret = message_header_search(
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
425 (const unsigned char *) field,
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
426 strlen(field),
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
427 hdr_search_ctx) ? 1 : 0;
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
428 }
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
429 }
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
430 t_pop();
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
431 return ret;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
434 static void search_envelope_arg(struct mail_search_arg *arg, void *context)
0
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 struct search_index_context *ctx = context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
438 switch (search_arg_match_envelope(ctx, arg)) {
160
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
439 case -1:
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
440 /* unknown */
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
441 break;
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
442 case 0:
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
443 ARG_SET_RESULT(arg, -1);
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
444 break;
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
445 default:
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
446 ARG_SET_RESULT(arg, 1);
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
447 break;
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
448 }
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
449 }
ff05b320482c Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
450
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
451 static void search_header_arg(struct mail_search_arg *arg, void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
453 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
454 struct header_search_context *hdr_search_ctx;
184
4223b9ed0c80 move size_t fixes
Timo Sirainen <tss@iki.fi>
parents: 183
diff changeset
455 size_t len;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456 int ret;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458 /* first check that the field name matches to argument. */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459 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
460 case SEARCH_SENTBEFORE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
461 case SEARCH_SENTON:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
462 case SEARCH_SENTSINCE:
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
463 /* date is handled differently than others */
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
464 if (ctx->name_len == 4 &&
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
465 memcasecmp(ctx->name, "Date", 4) == 0) {
408
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
466 search_sent(arg->type, arg->value.str,
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
467 t_strndup(ctx->value, ctx->value_len));
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
468 }
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
469 return;
e057845d94ca Dropped sent_time and alignment from MailIndexRecord. SEARCH can now use
Timo Sirainen <tss@iki.fi>
parents: 369
diff changeset
470
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 case SEARCH_FROM:
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
472 if (ctx->name_len != 4 || memcasecmp(ctx->name, "From", 4) != 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 case SEARCH_TO:
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
476 if (ctx->name_len != 2 || memcasecmp(ctx->name, "To", 2) != 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 case SEARCH_CC:
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
480 if (ctx->name_len != 2 || memcasecmp(ctx->name, "Cc", 2) != 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
483 case SEARCH_BCC:
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
484 if (ctx->name_len != 3 || memcasecmp(ctx->name, "Bcc", 3) != 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
486 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
487 case SEARCH_SUBJECT:
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
488 if (ctx->name_len != 7 ||
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
489 memcasecmp(ctx->name, "Subject", 7) != 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
490 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
491 break;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
492 case SEARCH_HEADER:
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
493 ctx->custom_header = TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
494
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
495 len = strlen(arg->hdr_field_name);
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
496 if (ctx->name_len != len ||
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
497 memcasecmp(ctx->name, arg->hdr_field_name, len) != 0)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
498 return;
569
cafe57140f5c SEARCH TEXT now checks only field values (not names) from headers. RFC
Timo Sirainen <tss@iki.fi>
parents: 568
diff changeset
499 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
500 /* 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
501 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
502 break;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 default:
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
504 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
505 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
506
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
507 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
508 /* 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
509 ret = 1;
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
510 } else {
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
511 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
512
880
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
513 /* then check if the value matches */
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
514 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
515 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
516 ret = 0;
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
517 else {
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
518 len = ctx->value_len;
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
519 ret = message_header_search(ctx->value, len,
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
520 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
521 }
d5168cca2052 SEARCHing headers with "" value should always match if the header is found.
Timo Sirainen <tss@iki.fi>
parents: 825
diff changeset
522 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
523 }
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
524
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
525 ARG_SET_RESULT(arg, ret);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
526 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
527
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
528 static void search_header(struct message_part *part __attr_unused__,
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
529 const unsigned char *name, size_t name_len,
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
530 const unsigned char *value, size_t value_len,
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
531 void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
532 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
533 struct search_header_context *ctx = context;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
534
369
d037915978ca message_parse_header() now calls the function with empty name/value at end
Timo Sirainen <tss@iki.fi>
parents: 364
diff changeset
535 if ((name_len > 0 && ctx->custom_header) ||
898
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
536 (name_len == 4 && memcasecmp(name, "Date", 4) == 0) ||
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
537 (name_len == 4 && memcasecmp(name, "From", 4) == 0) ||
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
538 (name_len == 2 && memcasecmp(name, "To", 2) == 0) ||
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
539 (name_len == 2 && memcasecmp(name, "Cc", 2) == 0) ||
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
540 (name_len == 3 && memcasecmp(name, "Bcc", 3) == 0) ||
0d5be52d7131 Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents: 896
diff changeset
541 (name_len == 7 && memcasecmp(name, "Subject", 7) == 0)) {
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
542 ctx->name = name;
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
543 ctx->value = value;
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
544 ctx->name_len = name_len;
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
545 ctx->value_len = value_len;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
546
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
547 ctx->custom_header = FALSE;
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
548 mail_search_args_foreach(ctx->args, search_header_arg, ctx);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
549 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
550 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
551
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
552 static void search_body(struct mail_search_arg *arg, void *context)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
553 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
554 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
555 int ret, unknown_charset;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
556
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
557 if (ctx->index_ctx->error != NULL)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
558 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
559
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
560 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
561 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
562 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
563 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
564 &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
565 ctx->part, arg->type == SEARCH_TEXT);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
566
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
567 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
568 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
569 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
570 }
290
3dcc2275b4ca IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents: 223
diff changeset
571
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
572 ARG_SET_RESULT(arg, ret > 0);
290
3dcc2275b4ca IOBuffer cleanup, hopefully fixes some mbox problems.
Timo Sirainen <tss@iki.fi>
parents: 223
diff changeset
573 }
5
1b34ec11fff8 Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
574 }
1b34ec11fff8 Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
575
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
576 static int search_arg_match_text(struct mail_search_arg *args,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
577 struct search_index_context *ctx)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
578 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
579 struct istream *input;
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
580 int have_headers, have_body, have_text;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
582 /* first check what we need to use */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
583 mail_search_args_analyze(args, &have_headers, &have_body, &have_text);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
584 if (!have_headers && !have_body && !have_text)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
585 return TRUE;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
586
569
cafe57140f5c SEARCH TEXT now checks only field values (not names) from headers. RFC
Timo Sirainen <tss@iki.fi>
parents: 568
diff changeset
587 if (have_headers || have_text) {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
588 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
589
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
590 if (!imap_msgcache_get_data(search_open_cache(ctx), &input))
715
3e952f64b2ec Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents: 678
diff changeset
591 return FALSE;
3e952f64b2ec Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents: 678
diff changeset
592
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
593 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
594 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
595 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
596 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
597
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
598 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
599 search_header, &hdr_ctx);
715
3e952f64b2ec Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents: 678
diff changeset
600 } else {
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
601 if (!imap_msgcache_get_rfc822(search_open_cache(ctx), &input,
716
dd574ac271c1 Body searching wasn't working with unknown charsets, and SEARCH BODY
Timo Sirainen <tss@iki.fi>
parents: 715
diff changeset
602 NULL, NULL))
715
3e952f64b2ec Non-envelope-cached header searching wasn't working. Also now search works
Timo Sirainen <tss@iki.fi>
parents: 678
diff changeset
603 return FALSE;
5
1b34ec11fff8 Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
604 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
605
5
1b34ec11fff8 Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
606 if (have_text || have_body) {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
607 struct search_body_context body_ctx;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
608
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
609 memset(&body_ctx, 0, sizeof(body_ctx));
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
610 body_ctx.index_ctx = ctx;
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
611 body_ctx.input = input;
608
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
612 body_ctx.part = imap_msgcache_get_parts(search_open_cache(ctx));
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
613
debb8468514e SEARCH CHARSET now works properly with message bodies, and in general body
Timo Sirainen <tss@iki.fi>
parents: 569
diff changeset
614 mail_search_args_foreach(args, search_body, &body_ctx);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
615 }
5
1b34ec11fff8 Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
616 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
617 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
618
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
619 static void seq_update(const char *set, unsigned int *first_seq,
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
620 unsigned int *last_seq, unsigned int max_value)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
621 {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
622 unsigned int seq;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
623
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
624 while (*set != '\0') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
625 if (*set == '*') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
626 seq = max_value;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
627 set++;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
628 } else {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
629 seq = 0;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
630 while (*set >= '0' && *set <= '9') {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
631 seq = seq*10 + (*set-'0');
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
632 set++;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
633 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
634 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
635
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
636 if (seq != 0) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
637 if (*first_seq == 0 || seq < *first_seq)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
638 *first_seq = seq;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
639 if (*last_seq == 0 || seq > *last_seq)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
640 *last_seq = seq;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
641 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
642
46
b2bc8d2e56ff fixes for messageset handling
Timo Sirainen <tss@iki.fi>
parents: 10
diff changeset
643 set++;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
644 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
645 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
646
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
647 static void search_get_sequid(struct index_mailbox *ibox,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
648 struct mail_search_arg *args,
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
649 unsigned int *first_seq, unsigned int *last_seq,
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
650 unsigned int *first_uid, unsigned int *last_uid)
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
651 {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
652 for (; args != NULL; args = args->next) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
653 if (args->type == SEARCH_OR || args->type == SEARCH_SUB) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
654 search_get_sequid(ibox, args->value.subargs,
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
655 first_seq, last_seq,
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
656 first_uid, last_uid);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
657 } if (args->type == SEARCH_SET) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
658 seq_update(args->value.str, first_seq, last_seq,
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
659 ibox->synced_messages_count);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
660 } else if (args->type == SEARCH_UID) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
661 seq_update(args->value.str, first_uid, last_uid,
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
662 ibox->index->header->next_uid-1);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
663 } else if (args->type == SEARCH_ALL) {
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
664 /* go through everything */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
665 *first_seq = 1;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
666 *last_seq = ibox->synced_messages_count;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
667 return;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
668 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
669 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
670 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
671
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
672 static int search_limit_by_flags(struct index_mailbox *ibox,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
673 struct mail_search_arg *args,
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
674 unsigned int *first_uid,
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
675 unsigned int *last_uid)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
676 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
677 struct mail_index_header *hdr;
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
678 unsigned int uid;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
679
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
680 hdr = ibox->index->header;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
681 for (; args != NULL; args = args->next) {
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
682 if (args->type == SEARCH_SEEN) {
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
683 /* SEEN with 0 seen? */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
684 if (!args->not && hdr->seen_messages_count == 0)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
685 return FALSE;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
686
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
687 /* UNSEEN with all seen? */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
688 if (args->not &&
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
689 hdr->seen_messages_count == hdr->messages_count)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
690 return FALSE;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
691
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
692 /* UNSEEN with lowwater limiting */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
693 uid = hdr->first_unseen_uid_lowwater;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
694 if (args->not && *first_uid < uid)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
695 *first_uid = uid;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
696 }
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
697
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
698 if (args->type == SEARCH_DELETED) {
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
699 /* DELETED with 0 deleted? */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
700 if (!args->not && hdr->deleted_messages_count == 0)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
701 return FALSE;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
702
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
703 /* UNDELETED with all deleted? */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
704 if (!args->not &&
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
705 hdr->deleted_messages_count == hdr->messages_count)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
706 return FALSE;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
707
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
708 /* DELETED with lowwater limiting */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
709 uid = hdr->first_deleted_uid_lowwater;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
710 if (!args->not && *first_uid < uid)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
711 *first_uid = uid;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
712 }
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
713
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
714 if (args->type == SEARCH_RECENT) {
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
715 uid = ibox->index->first_recent_uid;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
716 if (!args->not && *first_uid < uid)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
717 *first_uid = ibox->index->first_recent_uid;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
718 else if (args->not && *last_uid >= uid)
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
719 *last_uid = uid-1;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
720 }
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
721 }
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
722
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
723 return *first_uid <= *last_uid;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
724 }
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
725
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
726 static unsigned int client_seq_to_uid(struct mail_index *index,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
727 unsigned int seq)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
728 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
729 struct mail_index_record *rec;
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
730 unsigned int expunges_before;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
731
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
732 (void)mail_modifylog_seq_get_expunges(index->modifylog, seq, seq,
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
733 &expunges_before);
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
734 seq -= expunges_before;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
735
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
736 rec = index->lookup(index, seq);
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
737 return rec == NULL ? 0 : rec->uid;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
738 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
739
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
740 static int search_get_uid_range(struct index_mailbox *ibox,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
741 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
742 unsigned int *first_uid,
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
743 unsigned int *last_uid)
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
744 {
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
745 unsigned int first_seq, last_seq, uid;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
746
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
747 *first_uid = *last_uid = 0;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
748 first_seq = last_seq = 0;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
749
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
750 search_get_sequid(ibox, args, &first_seq, &last_seq,
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
751 first_uid, last_uid);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
752
51
b4adc3429867 Some cleanups, assertion fixes.
Timo Sirainen <tss@iki.fi>
parents: 50
diff changeset
753 /* seq_update() should make sure that these can't happen */
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
754 i_assert(first_seq <= last_seq);
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
755 i_assert(*first_uid <= *last_uid);
51
b4adc3429867 Some cleanups, assertion fixes.
Timo Sirainen <tss@iki.fi>
parents: 50
diff changeset
756
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
757 if (first_seq > 1) {
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
758 uid = client_seq_to_uid(ibox->index, first_seq);
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
759 if (uid == 0)
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
760 return FALSE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
761
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
762 if (*first_uid == 0 || uid < *first_uid)
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
763 *first_uid = uid;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
764 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
765
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
766 if (last_seq > 1 && last_seq != ibox->synced_messages_count) {
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
767 uid = client_seq_to_uid(ibox->index, last_seq);
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
768 if (uid == 0)
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
769 return FALSE;
51
b4adc3429867 Some cleanups, assertion fixes.
Timo Sirainen <tss@iki.fi>
parents: 50
diff changeset
770
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
771 if (uid > *last_uid)
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
772 *last_uid = uid;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
773 }
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
774
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
775 if (*first_uid == 0)
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
776 *first_uid = 1;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
777 if (*last_uid == 0)
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
778 *last_uid = ibox->index->header->next_uid-1;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
779
442
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
780 /* UNSEEN and DELETED in root search level may limit the range */
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
781 if (!search_limit_by_flags(ibox, args, first_uid, last_uid))
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
782 return FALSE;
2a25bf21557b SEARCH SEEN, UNSEEN, DELETED, UNDELETED, RECENT, UNRECENT optimizations.
Timo Sirainen <tss@iki.fi>
parents: 441
diff changeset
783
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
784 i_assert(*first_uid <= *last_uid);
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
785 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
786 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
787
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
788 static int search_messages(struct index_mailbox *ibox, const char *charset,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
789 struct mail_search_arg *args,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
790 struct mail_sort_context *sort_ctx,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
791 struct ostream *output, int uid_result)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
792 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
793 struct search_index_context ctx;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
794 struct mail_index_record *rec;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
795 struct mail_search_arg *arg;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
796 const struct modify_log_expunge *expunges;
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
797 unsigned int first_uid, last_uid, client_seq, expunges_before;
807
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
798 const char *str;
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
799 int found, failed;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
800
51
b4adc3429867 Some cleanups, assertion fixes.
Timo Sirainen <tss@iki.fi>
parents: 50
diff changeset
801 if (ibox->synced_messages_count == 0)
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
802 return TRUE;
51
b4adc3429867 Some cleanups, assertion fixes.
Timo Sirainen <tss@iki.fi>
parents: 50
diff changeset
803
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
804 /* see if we can limit the records we look at */
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
805 if (!search_get_uid_range(ibox, args, &first_uid, &last_uid))
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
806 return TRUE;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
807
355
0dc59fd3faed First version of binary tree file, still some locking issues while opening
Timo Sirainen <tss@iki.fi>
parents: 352
diff changeset
808 rec = ibox->index->lookup_uid_range(ibox->index, first_uid, last_uid,
0dc59fd3faed First version of binary tree file, still some locking issues while opening
Timo Sirainen <tss@iki.fi>
parents: 352
diff changeset
809 &client_seq);
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
810 if (rec == NULL)
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
811 return TRUE;
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
812
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
813 expunges = mail_modifylog_uid_get_expunges(ibox->index->modifylog,
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
814 rec->uid, last_uid,
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
815 &expunges_before);
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
816 client_seq += expunges_before;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
817
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
818 memset(&ctx, 0, sizeof(ctx));
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
819 ctx.ibox = ibox;
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
820 ctx.charset = charset;
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
821
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
822 for (; rec != NULL && rec->uid <= last_uid; client_seq++) {
453
0f6fd6802265 Modify log now stores the changes in ranges, so store 1:100 doesn't
Timo Sirainen <tss@iki.fi>
parents: 450
diff changeset
823 while (expunges->uid1 != 0 && expunges->uid1 < rec->uid) {
0f6fd6802265 Modify log now stores the changes in ranges, so store 1:100 doesn't
Timo Sirainen <tss@iki.fi>
parents: 450
diff changeset
824 i_assert(expunges->uid2 < rec->uid);
0f6fd6802265 Modify log now stores the changes in ranges, so store 1:100 doesn't
Timo Sirainen <tss@iki.fi>
parents: 450
diff changeset
825
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
826 expunges++;
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
827 client_seq += expunges->seq_count;
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
828 }
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
829 i_assert(!(expunges->uid1 <= rec->uid &&
0f6fd6802265 Modify log now stores the changes in ranges, so store 1:100 doesn't
Timo Sirainen <tss@iki.fi>
parents: 450
diff changeset
830 expunges->uid2 >= rec->uid));
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
831
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
832 ctx.rec = rec;
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
833 ctx.client_seq = client_seq;
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
834 ctx.cached = FALSE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
835
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
836 mail_search_args_reset(args);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
837
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
838 t_push();
10
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
839 mail_search_args_foreach(args, search_index_arg, &ctx);
82b7de533f98 s/user_data/context/ and some s/Data/Context/
Timo Sirainen <tss@iki.fi>
parents: 5
diff changeset
840 mail_search_args_foreach(args, search_cached_arg, &ctx);
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
841 mail_search_args_foreach(args, search_envelope_arg, &ctx);
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
842 failed = !search_arg_match_text(args, &ctx);
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
843 imap_msgcache_close(ibox->cache);
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
844 t_pop();
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
845
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
846 if (ctx.error != NULL)
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
847 break;
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
848
525
2cb2e0a3423b Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents: 505
diff changeset
849 if (!failed) {
317
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
850 found = TRUE;
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
851 for (arg = args; arg != NULL; arg = arg->next) {
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
852 if (arg->result != 1) {
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
853 found = FALSE;
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
854 break;
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
855 }
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
856 }
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
857
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
858 if (found) {
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
859 if (sort_ctx == NULL) {
807
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
860 t_push();
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
861 o_stream_send(output, " ", 1);
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
862
807
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
863 str = dec2str(uid_result ? rec->uid :
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
864 client_seq);
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
865 o_stream_send_str(output, str);
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
866 t_pop();
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
867 } else {
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
868 mail_sort_input(sort_ctx, rec->uid);
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
869 }
317
79d9a40fbb72 Only first search condition was checked.
Timo Sirainen <tss@iki.fi>
parents: 290
diff changeset
870 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
871 }
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
872
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
873 rec = ibox->index->next(ibox->index, rec);
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
874 }
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
875
568
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
876 if (ctx.hdr_pool != NULL)
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
877 pool_unref(ctx.hdr_pool);
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
878
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
879 if (ctx.error != NULL)
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
880 mail_storage_set_error(ibox->box.storage, "%s", ctx.error);
f2aa58c2afd0 SEARCH CHARSET support. Currently we do it through iconv() and only ASCII
Timo Sirainen <tss@iki.fi>
parents: 559
diff changeset
881 return ctx.error == NULL;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
882 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
883
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
884 int index_storage_search(struct mailbox *box, const char *charset,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
885 struct mail_search_arg *args,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
886 enum mail_sort_type *sorting,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
887 struct ostream *output, int uid_result)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
888 {
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
889 struct index_mailbox *ibox = (struct index_mailbox *) box;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
890 struct mail_sort_context *sort_ctx;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 898
diff changeset
891 struct index_sort_context index_sort_ctx;
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
892 int failed;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
893
559
c834e77b624c Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents: 557
diff changeset
894 if (!index_storage_sync_and_lock(ibox, TRUE, MAIL_LOCK_SHARED))
223
ca6967899c05 More cleanups. lib-storage should handle "out of disk space" conditions
Timo Sirainen <tss@iki.fi>
parents: 222
diff changeset
895 return FALSE;
222
cf4d065f2f85 lots of cleanups. also index/datafile is now capable of staying in memory,
Timo Sirainen <tss@iki.fi>
parents: 216
diff changeset
896
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
897 if (sorting == NULL) {
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
898 sort_ctx = NULL;
807
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
899 o_stream_send_str(output, "* SEARCH");
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
900 } else {
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
901 memset(&index_sort_ctx, 0, sizeof(index_sort_ctx));
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
902 index_sort_ctx.ibox = ibox;
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
903 index_sort_ctx.output = output;
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
904
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
905 sort_ctx = mail_sort_init(sort_unsorted, sorting,
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
906 index_sort_funcs, &index_sort_ctx);
807
35abd7a5d381 Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents: 792
diff changeset
907 o_stream_send_str(output, "* SORT");
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
908 }
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
909
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
910 failed = !search_messages(ibox, charset, args, sort_ctx,
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
911 output, uid_result);
761
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
912 if (sort_ctx != NULL)
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
913 mail_sort_deinit(sort_ctx);
d3bd41a56309 First implementation of SORT extension. String comparing still not up to
Timo Sirainen <tss@iki.fi>
parents: 716
diff changeset
914
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents: 761
diff changeset
915 o_stream_send(output, "\r\n", 2);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
916
674
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 608
diff changeset
917 if (!index_storage_lock(ibox, MAIL_LOCK_UNLOCK))
b7aefd0d7611 Locking changes triggered a bit larger cleanup :) If we have to wait for a
Timo Sirainen <tss@iki.fi>
parents: 608
diff changeset
918 return FALSE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
919
327
276b7a53c264 Modify log fixes. STORE and SEARCH didn't handle properly message sequence
Timo Sirainen <tss@iki.fi>
parents: 317
diff changeset
920 return !failed;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
921 }