Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/index-sort.c @ 7956:439636cce455 HEAD
Memory leak fixes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 27 Jun 2008 08:10:54 +0300 |
parents | f431c67621ed |
children | 0a3b5ddb0869 |
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; |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
29 bool reverse; |
4303
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 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
32 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
|
33 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
34 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
35 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
|
36 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
37 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
38 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
|
39 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
|
40 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
41 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
|
42 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
|
43 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
|
44 node->date = 0; |
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 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
47 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
48 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
|
49 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
50 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
51 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
|
52 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
|
53 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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 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
|
59 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
|
60 node->date = 0; |
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 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
64 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
65 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
|
66 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
67 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
68 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
|
69 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
|
70 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 node->size = 0; |
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 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
77 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
|
78 struct mail *mail) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
79 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
80 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
|
81 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
82 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
|
83 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
84 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
85 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
|
86 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
87 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
|
88 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
|
89 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
90 if (n1->date < n2->date) |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
91 return !ctx->reverse ? -1 : 1; |
7855
b5a6e6783786
Message sorting by date, arrival or size was broken.
Timo Sirainen <tss@iki.fi>
parents:
7564
diff
changeset
|
92 if (n1->date > n2->date) |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
93 return !ctx->reverse ? 1 : -1; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
94 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
99 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
100 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
101 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
|
102 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
103 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
|
104 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
|
105 unsigned int count; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
106 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 i_free(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
112 program->context = NULL; |
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 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
115 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
|
116 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
117 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
|
118 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
|
119 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
120 if (n1->size < n2->size) |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
121 return !ctx->reverse ? -1 : 1; |
7855
b5a6e6783786
Message sorting by date, arrival or size was broken.
Timo Sirainen <tss@iki.fi>
parents:
7564
diff
changeset
|
122 if (n1->size > n2->size) |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
123 return !ctx->reverse ? 1 : -1; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
124 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
129 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
130 static void |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
131 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
|
132 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
133 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
|
134 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
|
135 unsigned int count; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
136 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 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
|
141 i_free(nodes); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
142 program->context = NULL; |
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 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
145 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
|
146 { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
147 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
|
148 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
|
149 static_node_cmp_context.mail = program->temp_mail; |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
150 static_node_cmp_context.reverse = |
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
151 (program->sort_program[0] & MAIL_SORT_FLAG_REVERSE) != 0; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
152 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
153 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
|
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 |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
161 if (program->iter_idx == array_count(&program->seqs)) |
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
162 return FALSE; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
163 |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
164 seqp = array_idx(&program->seqs, program->iter_idx++); |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
165 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
|
166 return TRUE; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
167 } |
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
|
168 |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
173 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
|
174 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
|
175 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
176 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
|
177 return NULL; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
178 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
179 /* 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
|
180 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
|
181 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
|
182 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
|
183 |
7859
f431c67621ed
Reversing the primary sort criterion reversed also reversed secondary
Timo Sirainen <tss@iki.fi>
parents:
7855
diff
changeset
|
184 for (i = 0; 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
|
185 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
|
186 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
|
187 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
188 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
189 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
|
190 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
|
191 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
197 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
|
198 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
|
199 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 else |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
204 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
|
205 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
|
206 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
|
207 break; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
208 } |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
209 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
|
210 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
|
211 |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 break; |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
218 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
227 default: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
228 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
229 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
230 return program; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
231 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
232 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
233 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
|
234 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
235 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
|
236 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
237 *_program = NULL; |
7956 | 238 |
239 if (program->context != NULL) | |
240 index_sort_list_finish(program); | |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
241 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
|
242 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
|
243 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
|
244 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
245 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
246 static int |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
247 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
|
248 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
253 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
|
254 *mailbox_r = ""; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
255 return ret; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
256 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
257 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
258 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
|
259 (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
|
260 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
|
261 *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
|
262 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
|
263 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
264 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
265 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
|
266 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
|
267 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
268 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
|
269 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
|
270 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
271 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
|
272 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
|
273 |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 return ret; |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
278 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
|
279 str, NULL); |
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 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
|
284 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
285 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
|
286 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
|
287 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
288 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
|
289 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
|
290 break; |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
291 default: |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
292 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
293 } |
6135
bc0f8a8397a3
Use i;unicode-casemap for sorting also.
Timo Sirainen <tss@iki.fi>
parents:
5336
diff
changeset
|
294 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
295 (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
|
296 return ret; |
6547
7a207cbc008b
Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents:
6546
diff
changeset
|
297 } |
7a207cbc008b
Don't assert-crash with node.sort_id != 0.
Timo Sirainen <tss@iki.fi>
parents:
6546
diff
changeset
|
298 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 { |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
303 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
|
304 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
|
305 uoff_t size1, size2; |
4935 | 306 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
|
307 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 T_BEGIN { |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
315 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
|
316 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
317 str1 = t_str_new(256); |
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 |
6968
09e1e8d4aa53
Simplified and optimized the sorting code.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
322 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
|
323 } 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
|
324 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 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
|
329 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
330 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
|
331 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
|
332 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
|
333 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
334 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
|
335 (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
|
336 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 time1 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
341 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
|
342 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
|
343 time1 = 0; |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
344 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
345 |
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, seq2); |
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, &time2, NULL) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
348 time2 = 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 (time2 == 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, &time2) < 0) |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
351 time2 = 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 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
354 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
|
355 (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
|
356 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 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
|
361 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
366 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
|
367 (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
|
368 break; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
369 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
|
370 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
|
371 (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
|
372 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
|
373 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
|
374 i_unreached(); |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
375 } |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
376 |
7564
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
377 if (ret == 0) { |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
378 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
|
379 seq1, seq2); |
4a9ce9df52c5
Message sort index handling rewrite to fix several race conditions when
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
380 } |
4303
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
381 |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
382 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
|
383 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
|
384 return ret; |
5f03738219a6
Changed mail-storage API to do the mail sorting internally. Optimized it
Timo Sirainen <timo.sirainen@movial.fi>
parents:
diff
changeset
|
385 } |