Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/index-sort.c @ 7564:4a9ce9df52c5 HEAD
Message sort index handling rewrite to fix several race conditions when
multiple processes are sorting at the same time. Also fixes sorting to work
correctly with 64bit timestamps and file sizes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 29 May 2008 06:16:06 +0300 |
parents | e6693a0ec8e1 |
children | b5a6e6783786 |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
7043
diff
changeset
|
1 /* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */ |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
2 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
4 #include "array.h" |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
5 #include "str.h" |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
6 #include "unichar.h" |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
7 #include "message-address.h" |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
8 #include "imap-base-subject.h" |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
9 #include "index-storage.h" |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
10 #include "index-sort-private.h" |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
11 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
12 #include <stdlib.h> |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
13 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
14 struct mail_sort_node_date { |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
15 uint32_t seq; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
16 time_t date; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
17 }; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
18 ARRAY_DEFINE_TYPE(mail_sort_node_date, struct mail_sort_node_date); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
19 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
20 struct mail_sort_node_size { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
21 uint32_t seq; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
22 uoff_t size; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
23 }; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
24 ARRAY_DEFINE_TYPE(mail_sort_node_size, struct mail_sort_node_size); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
25 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
26 struct sort_cmp_context { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
27 struct mail_search_sort_program *program; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
28 struct mail *mail; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
29 }; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
30 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
31 static struct sort_cmp_context static_node_cmp_context; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
32 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
33 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
34 index_sort_list_add_arrival(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
35 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
36 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
37 ARRAY_TYPE(mail_sort_node_date) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
38 struct mail_sort_node_date *node; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
39 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
40 node = array_append_space(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
41 node->seq = mail->seq; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
42 if (mail_get_received_date(mail, &node->date) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
43 node->date = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
44 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
45 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
46 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
47 index_sort_list_add_date(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
48 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
49 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
50 ARRAY_TYPE(mail_sort_node_date) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
51 struct mail_sort_node_date *node; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
52 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
53 node = array_append_space(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
54 node->seq = mail->seq; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
55 if (mail_get_date(mail, &node->date, NULL) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
56 node->date = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
57 else if (node->date == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
58 if (mail_get_received_date(mail, &node->date) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
59 node->date = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
60 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
61 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
62 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
63 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
64 index_sort_list_add_size(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
65 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
66 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
67 ARRAY_TYPE(mail_sort_node_size) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
68 struct mail_sort_node_size *node; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
69 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
70 node = array_append_space(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
71 node->seq = mail->seq; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
72 if (mail_get_virtual_size(mail, &node->size) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
73 node->size = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
74 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
75 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
76 void index_sort_list_add(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
77 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
78 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
79 i_assert(mail->transaction == program->t); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
80 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
81 program->sort_list_add(program, mail); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
82 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
83 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
84 static int sort_node_date_cmp(const void *p1, const void *p2) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
85 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
86 struct sort_cmp_context *ctx = &static_node_cmp_context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
87 const struct mail_sort_node_date *n1 = p1, *n2 = p2; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
88 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
89 if (n1->date < n2->date) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
90 return -1; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
91 if (n2->date > n2->date) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
92 return 1; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
93 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
94 return index_sort_node_cmp_type(ctx->mail, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
95 ctx->program->sort_program + 1, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
96 n1->seq, n2->seq); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
97 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
98 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
99 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
100 index_sort_list_finish_date(struct mail_search_sort_program *program) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
101 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
102 ARRAY_TYPE(mail_sort_node_date) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
103 struct mail_sort_node_date *date_nodes; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
104 unsigned int count; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
105 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
106 date_nodes = array_get_modifiable(nodes, &count); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
107 qsort(date_nodes, count, sizeof(struct mail_sort_node_date), |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
108 sort_node_date_cmp); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
109 memcpy(&program->seqs, nodes, sizeof(program->seqs)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
110 i_free(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
111 program->context = NULL; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
112 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
113 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
114 static int sort_node_size_cmp(const void *p1, const void *p2) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
115 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
116 struct sort_cmp_context *ctx = &static_node_cmp_context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
117 const struct mail_sort_node_size *n1 = p1, *n2 = p2; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
118 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
119 if (n1->size < n2->size) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
120 return -1; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
121 if (n2->size > n2->size) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
122 return 1; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
123 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
124 return index_sort_node_cmp_type(ctx->mail, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
125 ctx->program->sort_program + 1, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
126 n1->seq, n2->seq); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
127 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
128 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
129 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
130 index_sort_list_finish_size(struct mail_search_sort_program *program) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
131 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
132 ARRAY_TYPE(mail_sort_node_size) *nodes = program->context; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
133 struct mail_sort_node_size *size_nodes; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
134 unsigned int count; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
135 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
136 size_nodes = array_get_modifiable(nodes, &count); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
137 qsort(size_nodes, count, sizeof(struct mail_sort_node_size), |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
138 sort_node_size_cmp); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
139 memcpy(&program->seqs, nodes, sizeof(program->seqs)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
140 i_free(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
141 program->context = NULL; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
142 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
143 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
144 void index_sort_list_finish(struct mail_search_sort_program *program) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
145 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
146 memset(&static_node_cmp_context, 0, sizeof(static_node_cmp_context)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
147 static_node_cmp_context.program = program; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
148 static_node_cmp_context.mail = program->temp_mail; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
149 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
150 program->sort_list_finish(program); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
151 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
152 if (program->reverse) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
153 program->iter_idx = array_count(&program->seqs); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
154 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
155 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
156 bool index_sort_list_next(struct mail_search_sort_program *program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
157 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
158 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
159 const uint32_t *seqp; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
160 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
161 if (!program->reverse) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
162 if (program->iter_idx == array_count(&program->seqs)) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
163 return FALSE; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
164 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
165 seqp = array_idx(&program->seqs, program->iter_idx++); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
166 } else { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
167 if (program->iter_idx == 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
168 return FALSE; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
169 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
170 seqp = array_idx(&program->seqs, --program->iter_idx); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
171 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
172 mail_set_seq(mail, *seqp); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
173 return TRUE; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
174 } |
6970
891d2b36feee
Don't add arrival/date/size sort IDs to index file. They can be looked up
Timo Sirainen <tss@iki.fi>
parents:
6969
diff
changeset
|
175 |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
176 struct mail_search_sort_program * |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
177 index_sort_program_init(struct mailbox_transaction_context *t, |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
178 const enum mail_sort_type *sort_program) |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
179 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
180 struct mail_search_sort_program *program; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
181 unsigned int i; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
182 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
183 if (sort_program == NULL || sort_program[0] == MAIL_SORT_END) |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
184 return NULL; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
185 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
186 /* we support internal sorting by the primary condition */ |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
187 program = i_new(struct mail_search_sort_program, 1); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
188 program->t = t; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
189 program->temp_mail = mail_alloc(t, 0, NULL); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
190 |
6549 | 191 /* primary reversion isn't stored to sort_program. we handle it by |
192 iterating backwards at the end. */ | |
193 program->reverse = (sort_program[0] & MAIL_SORT_FLAG_REVERSE) != 0; | |
194 program->sort_program[0] = sort_program[0] & ~MAIL_SORT_FLAG_REVERSE; | |
195 for (i = 1; i < MAX_SORT_PROGRAM_SIZE; i++) { | |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
196 program->sort_program[i] = sort_program[i]; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
197 if (sort_program[i] == MAIL_SORT_END) |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
198 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
199 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
200 if (i == MAX_SORT_PROGRAM_SIZE) |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
201 i_panic("index_sort_program_init(): Invalid sort program"); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
202 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
203 switch (program->sort_program[0] & MAIL_SORT_MASK) { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
204 case MAIL_SORT_ARRIVAL: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
205 case MAIL_SORT_DATE: { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
206 ARRAY_TYPE(mail_sort_node_date) *nodes; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
207 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
208 nodes = i_malloc(sizeof(*nodes)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
209 i_array_init(nodes, 128); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
210 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
211 if ((program->sort_program[0] & |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
212 MAIL_SORT_MASK) == MAIL_SORT_ARRIVAL) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
213 program->sort_list_add = index_sort_list_add_arrival; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
214 else |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
215 program->sort_list_add = index_sort_list_add_date; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
216 program->sort_list_finish = index_sort_list_finish_date; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
217 program->context = nodes; |
6970
891d2b36feee
Don't add arrival/date/size sort IDs to index file. They can be looked up
Timo Sirainen <tss@iki.fi>
parents:
6969
diff
changeset
|
218 break; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
219 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
220 case MAIL_SORT_SIZE: { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
221 ARRAY_TYPE(mail_sort_node_size) *nodes; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
222 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
223 nodes = i_malloc(sizeof(*nodes)); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
224 i_array_init(nodes, 128); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
225 program->sort_list_add = index_sort_list_add_size; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
226 program->sort_list_finish = index_sort_list_finish_size; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
227 program->context = nodes; |
6970
891d2b36feee
Don't add arrival/date/size sort IDs to index file. They can be looked up
Timo Sirainen <tss@iki.fi>
parents:
6969
diff
changeset
|
228 break; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
229 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
230 case MAIL_SORT_CC: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
231 case MAIL_SORT_FROM: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
232 case MAIL_SORT_SUBJECT: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
233 case MAIL_SORT_TO: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
234 program->sort_list_add = index_sort_list_add_string; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
235 program->sort_list_finish = index_sort_list_finish_string; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
236 index_sort_list_init_string(program); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
237 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
238 default: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
239 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
240 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
241 return program; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
242 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
243 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
244 void index_sort_program_deinit(struct mail_search_sort_program **_program) |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
245 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
246 struct mail_search_sort_program *program = *_program; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
247 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
248 *_program = NULL; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
249 mail_free(&program->temp_mail); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
250 array_free(&program->seqs); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
251 i_free(program); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
252 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
253 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
254 static int |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
255 get_first_mailbox(struct mail *mail, const char *header, const char **mailbox_r) |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
256 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
257 struct message_address *addr; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
258 const char *str; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
259 int ret; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
260 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
261 if ((ret = mail_get_first_header_utf8(mail, header, &str)) <= 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
262 *mailbox_r = ""; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
263 return ret; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
264 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
265 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
266 addr = message_address_parse(pool_datastack_create(), |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
267 (const unsigned char *)str, |
4635
210bb1ff0e6e
Added fill_missing parameter to message_address_parse() which specifies if
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
268 strlen(str), 1, TRUE); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
269 *mailbox_r = addr != NULL ? addr->mailbox : ""; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
270 return 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
271 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
272 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
273 int index_sort_header_get(struct mail *mail, uint32_t seq, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
274 enum mail_sort_type sort_type, string_t *dest) |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
275 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
276 const char *str; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
277 int ret; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
278 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
279 mail_set_seq(mail, seq); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
280 str_truncate(dest, 0); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
281 |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
282 switch (sort_type & MAIL_SORT_MASK) { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
283 case MAIL_SORT_SUBJECT: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
284 if ((ret = mail_get_first_header(mail, "Subject", &str)) <= 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
285 return ret; |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
286 str = imap_get_base_subject_cased(pool_datastack_create(), |
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
287 str, NULL); |
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
288 str_append(dest, str); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
289 return 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
290 case MAIL_SORT_CC: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
291 ret = get_first_mailbox(mail, "Cc", &str); |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
292 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
293 case MAIL_SORT_FROM: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
294 ret = get_first_mailbox(mail, "From", &str); |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
295 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
296 case MAIL_SORT_TO: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
297 ret = get_first_mailbox(mail, "To", &str); |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
298 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
299 default: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
300 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
301 } |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
302 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
303 (void)uni_utf8_to_decomposed_titlecase(str, (size_t)-1, dest); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
304 return ret; |
6547
7a207cbc008b
Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents:
6546
diff
changeset
|
305 } |
7a207cbc008b
Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents:
6546
diff
changeset
|
306 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
307 int index_sort_node_cmp_type(struct mail *mail, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
308 const enum mail_sort_type *sort_program, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
309 uint32_t seq1, uint32_t seq2) |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
310 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
311 enum mail_sort_type sort_type; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
312 time_t time1, time2; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
313 uoff_t size1, size2; |
4935 | 314 int ret = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
315 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
316 sort_type = *sort_program & MAIL_SORT_MASK; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
317 switch (sort_type) { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
318 case MAIL_SORT_CC: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
319 case MAIL_SORT_FROM: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
320 case MAIL_SORT_TO: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
321 case MAIL_SORT_SUBJECT: |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7201
diff
changeset
|
322 T_BEGIN { |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
323 string_t *str1, *str2; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
324 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
325 str1 = t_str_new(256); |
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
326 str2 = t_str_new(256); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
327 index_sort_header_get(mail, seq1, sort_type, str1); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
328 index_sort_header_get(mail, seq2, sort_type, str2); |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6711
diff
changeset
|
329 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
330 ret = strcmp(str_c(str1), str_c(str2)); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7201
diff
changeset
|
331 } T_END; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
332 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
333 case MAIL_SORT_ARRIVAL: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
334 mail_set_seq(mail, seq1); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
335 if (mail_get_received_date(mail, &time1) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
336 time1 = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
337 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
338 mail_set_seq(mail, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
339 if (mail_get_received_date(mail, &time2) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
340 time1 = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
341 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
342 ret = time1 < time2 ? -1 : |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
343 (time1 > time2 ? 1 : 0); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
344 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
345 case MAIL_SORT_DATE: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
346 mail_set_seq(mail, seq1); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
347 if (mail_get_date(mail, &time1, NULL) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
348 time1 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
349 else if (time1 == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
350 if (mail_get_received_date(mail, &time1) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
351 time1 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
352 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
353 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
354 mail_set_seq(mail, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
355 if (mail_get_date(mail, &time2, NULL) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
356 time2 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
357 else if (time2 == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
358 if (mail_get_received_date(mail, &time2) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
359 time2 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
360 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
361 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
362 ret = time1 < time2 ? -1 : |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
363 (time1 > time2 ? 1 : 0); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
364 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
365 case MAIL_SORT_SIZE: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
366 mail_set_seq(mail, seq1); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
367 if (mail_get_virtual_size(mail, &size1) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
368 size1 = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
369 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
370 mail_set_seq(mail, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
371 if (mail_get_virtual_size(mail, &size2) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
372 size2 = 0; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
373 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
374 ret = size1 < size2 ? -1 : |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
375 (size1 > size2 ? 1 : 0); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
376 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
377 case MAIL_SORT_END: |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
378 return seq1 < seq2 ? -1 : |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
379 (seq1 > seq2 ? 1 : 0); |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
380 case MAIL_SORT_MASK: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
381 case MAIL_SORT_FLAG_REVERSE: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
382 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
383 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
384 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
385 if (ret == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
386 return index_sort_node_cmp_type(mail, sort_program+1, |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
387 seq1, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
388 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
389 |
6549 | 390 /* primary reversion isn't in sort_program */ |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
391 if ((*sort_program & MAIL_SORT_FLAG_REVERSE) != 0) |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
392 ret = ret < 0 ? 1 : -1; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
393 return ret; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
394 } |