Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/commands-util.c @ 8521:182552d20b17 HEAD
Changed imap-resp-code [ACL] to [NOPERM], which it will be in the next draft.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 06 Dec 2008 19:11:22 +0200 |
parents | 6e9100795d89 |
children | b9faf4db2a9f |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
7063
diff
changeset
|
1 /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "common.h" | |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3254
diff
changeset
|
4 #include "array.h" |
1958 | 5 #include "buffer.h" |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
809
diff
changeset
|
6 #include "str.h" |
4398
3e74b2b09ed1
Fixes to checking if mailbox name is valid. In case mailbox name is invalid,
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
7 #include "str-sanitize.h" |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
8 #include "imap-resp-code.h" |
1041 | 9 #include "imap-parser.h" |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
10 #include "imap-sync.h" |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
11 #include "imap-util.h" |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
12 #include "mail-storage.h" |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5298
diff
changeset
|
13 #include "mail-namespace.h" |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
14 #include "commands-util.h" |
0 | 15 |
809
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
16 /* Maximum length for mailbox name, including it's path. This isn't fully |
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
17 exact since the user can create folder hierarchy with small names, then |
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
18 rename them to larger names. Mail storages should set more strict limits |
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
19 to them, mbox/maildir currently allow paths only up to PATH_MAX. */ |
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
20 #define MAILBOX_MAX_NAME_LEN 512 |
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
21 |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5298
diff
changeset
|
22 struct mail_namespace * |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
23 client_find_namespace(struct client_command_context *cmd, const char **mailbox) |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
24 { |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5298
diff
changeset
|
25 struct mail_namespace *ns; |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
26 |
8082
db66611fd195
Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
27 ns = mail_namespace_find(cmd->client->user->namespaces, mailbox); |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
28 if (ns != NULL) |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
29 return ns; |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
30 |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
31 client_send_tagline(cmd, "NO Unknown namespace."); |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
32 return NULL; |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
33 } |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
34 |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
35 struct mail_storage * |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
36 client_find_storage(struct client_command_context *cmd, const char **mailbox) |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
37 { |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5298
diff
changeset
|
38 struct mail_namespace *ns; |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
39 |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
40 ns = client_find_namespace(cmd, mailbox); |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
41 return ns == NULL ? NULL : ns->storage; |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
42 } |
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
43 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3517
diff
changeset
|
44 bool client_verify_mailbox_name(struct client_command_context *cmd, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3517
diff
changeset
|
45 const char *mailbox, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3517
diff
changeset
|
46 bool should_exist, bool should_not_exist) |
0 | 47 { |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5298
diff
changeset
|
48 struct mail_namespace *ns; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
49 struct mailbox_list *list; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
891
diff
changeset
|
50 enum mailbox_name_status mailbox_status; |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
51 const char *orig_mailbox, *p; |
0 | 52 |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
53 orig_mailbox = mailbox; |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
54 ns = client_find_namespace(cmd, &mailbox); |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
55 if (ns == NULL) |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
56 return FALSE; |
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
57 |
0 | 58 /* make sure it even looks valid */ |
4398
3e74b2b09ed1
Fixes to checking if mailbox name is valid. In case mailbox name is invalid,
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
59 if (*mailbox == '\0') { |
3e74b2b09ed1
Fixes to checking if mailbox name is valid. In case mailbox name is invalid,
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
60 client_send_tagline(cmd, "NO Empty mailbox name."); |
0 | 61 return FALSE; |
62 } | |
63 | |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
64 if (ns->real_sep != ns->sep && ns->prefix_len < strlen(orig_mailbox)) { |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
65 /* make sure there are no real separators used in the mailbox |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
66 name. */ |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
67 orig_mailbox += ns->prefix_len; |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
68 for (p = orig_mailbox; *p != '\0'; p++) { |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
69 if (*p == ns->real_sep) { |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
70 client_send_tagline(cmd, t_strdup_printf( |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
71 "NO Character not allowed " |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
72 "in mailbox name: '%c'", |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
73 ns->real_sep)); |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
74 return FALSE; |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
75 } |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
76 } |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
77 } |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
78 |
0 | 79 /* make sure two hierarchy separators aren't next to each others */ |
80 for (p = mailbox+1; *p != '\0'; p++) { | |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
81 if (p[0] == ns->real_sep && p[-1] == ns->real_sep) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
82 client_send_tagline(cmd, "NO Invalid mailbox name."); |
0 | 83 return FALSE; |
84 } | |
85 } | |
86 | |
809
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
87 if (strlen(mailbox) > MAILBOX_MAX_NAME_LEN) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
88 client_send_tagline(cmd, "NO Mailbox name too long."); |
809
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
89 return FALSE; |
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
90 } |
27554afad17e
Limit the mailbox path. A few cleanups.
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
91 |
0 | 92 /* check what our storage thinks of it */ |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
93 list = mail_storage_get_list(ns->storage); |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
94 if (mailbox_list_get_mailbox_name_status(list, mailbox, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1730
diff
changeset
|
95 &mailbox_status) < 0) { |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
96 client_send_storage_error(cmd, ns->storage); |
0 | 97 return FALSE; |
98 } | |
99 | |
100 switch (mailbox_status) { | |
891
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
101 case MAILBOX_NAME_EXISTS: |
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
102 if (should_exist || !should_not_exist) |
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
103 return TRUE; |
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
104 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
105 client_send_tagline(cmd, "NO Mailbox exists."); |
891
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
106 break; |
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
107 |
0 | 108 case MAILBOX_NAME_VALID: |
109 if (!should_exist) | |
110 return TRUE; | |
111 | |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
112 client_send_tagline(cmd, t_strconcat( |
136
899ea73710fc
"Mailbox doesn't exist" error now gives the name of the mailbox that was
Timo Sirainen <tss@iki.fi>
parents:
10
diff
changeset
|
113 "NO [TRYCREATE] Mailbox doesn't exist: ", |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
114 str_sanitize(orig_mailbox, MAILBOX_MAX_NAME_LEN), |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
115 NULL)); |
0 | 116 break; |
117 | |
118 case MAILBOX_NAME_INVALID: | |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
119 client_send_tagline(cmd, t_strconcat( |
4398
3e74b2b09ed1
Fixes to checking if mailbox name is valid. In case mailbox name is invalid,
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
120 "NO Invalid mailbox name: ", |
5298
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
121 str_sanitize(orig_mailbox, MAILBOX_MAX_NAME_LEN), |
143c5942e392
Added client_find_namespace(). Handle virtual != real hierarchy separators
Timo Sirainen <tss@iki.fi>
parents:
4808
diff
changeset
|
122 NULL)); |
0 | 123 break; |
124 | |
891
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
125 case MAILBOX_NAME_NOINFERIORS: |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
126 client_send_tagline(cmd, |
891
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
127 "NO Mailbox parent doesn't allow inferior mailboxes."); |
fd754a6fa784
Handle the MAILBOX_NAME_NOINFERIORS case.
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
128 break; |
0 | 129 |
130 default: | |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
131 i_unreached(); |
0 | 132 } |
133 | |
134 return FALSE; | |
135 } | |
136 | |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3517
diff
changeset
|
137 bool client_verify_open_mailbox(struct client_command_context *cmd) |
0 | 138 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
139 if (cmd->client->mailbox != NULL) |
0 | 140 return TRUE; |
141 else { | |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
142 client_send_tagline(cmd, "BAD No mailbox selected."); |
0 | 143 return FALSE; |
144 } | |
145 } | |
146 | |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
147 static const char * |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
148 get_error_string(const char *error_string, enum mail_error error) |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
149 { |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
150 const char *resp_code = NULL; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
151 |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
152 switch (error) { |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
153 case MAIL_ERROR_NONE: |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
154 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
155 case MAIL_ERROR_TEMP: |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
156 resp_code = IMAP_RESP_CODE_SERVERBUG; |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
157 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
158 case MAIL_ERROR_NOTPOSSIBLE: |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
159 case MAIL_ERROR_PARAMS: |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
160 resp_code = IMAP_RESP_CODE_CANNOT; |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
161 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
162 case MAIL_ERROR_PERM: |
8521
182552d20b17
Changed imap-resp-code [ACL] to [NOPERM], which it will be in the next draft.
Timo Sirainen <tss@iki.fi>
parents:
8412
diff
changeset
|
163 resp_code = IMAP_RESP_CODE_NOPERM; |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
164 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
165 case MAIL_ERROR_NOSPACE: |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
166 resp_code = IMAP_RESP_CODE_OVERQUOTA; |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
167 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
168 case MAIL_ERROR_NOTFOUND: |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
169 resp_code = IMAP_RESP_CODE_NONEXISTENT; |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
170 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
171 case MAIL_ERROR_EXISTS: |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
172 resp_code = IMAP_RESP_CODE_ALREADYEXISTS; |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
173 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
174 case MAIL_ERROR_EXPUNGED: |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
175 resp_code = IMAP_RESP_CODE_EXPUNGEISSUED; |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
176 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
177 case MAIL_ERROR_INUSE: |
8412
6e9100795d89
Moved imap-resp-codes to macros.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
178 resp_code = IMAP_RESP_CODE_INUSE; |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
179 break; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
180 } |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
181 if (resp_code == NULL || *error_string == '[') |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
182 return t_strconcat("NO ", error_string, NULL); |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
183 else |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
184 return t_strdup_printf("NO [%s] %s", resp_code, error_string); |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
185 } |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
186 |
5611
44db6ddd5a17
Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents:
5607
diff
changeset
|
187 void client_send_list_error(struct client_command_context *cmd, |
44db6ddd5a17
Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents:
5607
diff
changeset
|
188 struct mailbox_list *list) |
44db6ddd5a17
Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents:
5607
diff
changeset
|
189 { |
5613 | 190 const char *error_string; |
191 enum mail_error error; | |
5611
44db6ddd5a17
Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents:
5607
diff
changeset
|
192 |
5613 | 193 error_string = mailbox_list_get_last_error(list, &error); |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
194 client_send_tagline(cmd, get_error_string(error_string, error)); |
5611
44db6ddd5a17
Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents:
5607
diff
changeset
|
195 } |
44db6ddd5a17
Removed mail_storage_set_list_error(). Handle the errors directly.
Timo Sirainen <tss@iki.fi>
parents:
5607
diff
changeset
|
196 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
197 void client_send_storage_error(struct client_command_context *cmd, |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
198 struct mail_storage *storage) |
0 | 199 { |
5613 | 200 const char *error_string; |
201 enum mail_error error; | |
883
39e0b536e708
Storage can now specify if errors should be sent to user as BAD or NO.
Timo Sirainen <tss@iki.fi>
parents:
877
diff
changeset
|
202 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
203 if (cmd->client->mailbox != NULL && |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
204 mailbox_is_inconsistent(cmd->client->mailbox)) { |
0 | 205 /* we can't do forced CLOSE, so have to disconnect */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
206 client_disconnect_with_error(cmd->client, |
7198
7f7e295910a5
"Mailbox is in inconsistent state" -> "IMAP session state is inconsistent".
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
207 "IMAP session state is inconsistent, please relogin."); |
0 | 208 return; |
209 } | |
210 | |
5613 | 211 error_string = mail_storage_get_last_error(storage, &error); |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
212 client_send_tagline(cmd, get_error_string(error_string, error)); |
0 | 213 } |
214 | |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
215 void client_send_untagged_storage_error(struct client *client, |
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
216 struct mail_storage *storage) |
1021
81cbc1467097
Added support for UNSELECT extension with some cleanups for SELECT and CLOSE.
Timo Sirainen <tss@iki.fi>
parents:
1002
diff
changeset
|
217 { |
5613 | 218 const char *error_string; |
219 enum mail_error error; | |
1021
81cbc1467097
Added support for UNSELECT extension with some cleanups for SELECT and CLOSE.
Timo Sirainen <tss@iki.fi>
parents:
1002
diff
changeset
|
220 |
1212 | 221 if (client->mailbox != NULL && |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1730
diff
changeset
|
222 mailbox_is_inconsistent(client->mailbox)) { |
1212 | 223 /* we can't do forced CLOSE, so have to disconnect */ |
224 client_disconnect_with_error(client, | |
7198
7f7e295910a5
"Mailbox is in inconsistent state" -> "IMAP session state is inconsistent".
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
225 "IMAP session state is inconsistent, please relogin."); |
1212 | 226 return; |
227 } | |
228 | |
5613 | 229 error_string = mail_storage_get_last_error(storage, &error); |
230 client_send_line(client, t_strconcat("* NO ", error_string, NULL)); | |
1021
81cbc1467097
Added support for UNSELECT extension with some cleanups for SELECT and CLOSE.
Timo Sirainen <tss@iki.fi>
parents:
1002
diff
changeset
|
231 } |
81cbc1467097
Added support for UNSELECT extension with some cleanups for SELECT and CLOSE.
Timo Sirainen <tss@iki.fi>
parents:
1002
diff
changeset
|
232 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3517
diff
changeset
|
233 bool client_parse_mail_flags(struct client_command_context *cmd, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
234 const struct imap_arg *args, |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
235 enum mail_flags *flags_r, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3517
diff
changeset
|
236 const char *const **keywords_r) |
0 | 237 { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
238 const char *atom; |
6353
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
239 ARRAY_DEFINE(keywords, const char *); |
0 | 240 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
241 *flags_r = 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
242 *keywords_r = NULL; |
6353
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
243 p_array_init(&keywords, cmd->pool, 16); |
0 | 244 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
245 while (args->type != IMAP_ARG_EOL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
246 if (args->type != IMAP_ARG_ATOM) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
247 client_send_command_error(cmd, |
444
85ab93a7693b
ImapArgList changed from linked list to array. easier to handle that way.
Timo Sirainen <tss@iki.fi>
parents:
325
diff
changeset
|
248 "Flags list contains non-atoms."); |
0 | 249 return FALSE; |
250 } | |
251 | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
252 atom = IMAP_ARG_STR(args); |
0 | 253 if (*atom == '\\') { |
254 /* system flag */ | |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
255 atom = t_str_ucase(atom); |
0 | 256 if (strcmp(atom, "\\ANSWERED") == 0) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
257 *flags_r |= MAIL_ANSWERED; |
0 | 258 else if (strcmp(atom, "\\FLAGGED") == 0) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
259 *flags_r |= MAIL_FLAGGED; |
0 | 260 else if (strcmp(atom, "\\DELETED") == 0) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
261 *flags_r |= MAIL_DELETED; |
0 | 262 else if (strcmp(atom, "\\SEEN") == 0) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
263 *flags_r |= MAIL_SEEN; |
0 | 264 else if (strcmp(atom, "\\DRAFT") == 0) |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2708
diff
changeset
|
265 *flags_r |= MAIL_DRAFT; |
0 | 266 else { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3024
diff
changeset
|
267 client_send_tagline(cmd, t_strconcat( |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
891
diff
changeset
|
268 "BAD Invalid system flag ", |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
891
diff
changeset
|
269 atom, NULL)); |
0 | 270 return FALSE; |
271 } | |
272 } else { | |
6353
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
273 /* keyword validity checks are done by lib-storage */ |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
274 array_append(&keywords, &atom, 1); |
0 | 275 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
276 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
277 args++; |
444
85ab93a7693b
ImapArgList changed from linked list to array. easier to handle that way.
Timo Sirainen <tss@iki.fi>
parents:
325
diff
changeset
|
278 } |
0 | 279 |
6353
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
280 if (array_count(&keywords) == 0) |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
281 *keywords_r = NULL; |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
282 else { |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
283 (void)array_append_space(&keywords); /* NULL-terminate */ |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
284 *keywords_r = array_idx(&keywords, 0); |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
285 } |
0 | 286 return TRUE; |
287 } | |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
288 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4398
diff
changeset
|
289 static const char *get_keywords_string(const ARRAY_TYPE(keywords) *keywords) |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
290 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
891
diff
changeset
|
291 string_t *str; |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3210
diff
changeset
|
292 const char *const *names; |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3210
diff
changeset
|
293 unsigned int i, count; |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
294 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
809
diff
changeset
|
295 str = t_str_new(256); |
3254
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3210
diff
changeset
|
296 names = array_get(keywords, &count); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3210
diff
changeset
|
297 for (i = 0; i < count; i++) { |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3210
diff
changeset
|
298 str_append_c(str, ' '); |
a2943c050571
Keywords are now stored in X-Keywords headers in mbox. Did several related
Timo Sirainen <tss@iki.fi>
parents:
3210
diff
changeset
|
299 str_append(str, names[i]); |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
300 } |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
809
diff
changeset
|
301 return str_c(str); |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
302 } |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
303 |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
304 #define SYSTEM_FLAGS "\\Answered \\Flagged \\Deleted \\Seen \\Draft" |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
305 |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
306 void client_send_mailbox_flags(struct client *client, bool selecting) |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
307 { |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
308 unsigned int count = array_count(client->keywords.names); |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
309 const char *str; |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
310 |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
311 if (!selecting && count == client->keywords.announce_count) { |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
312 /* no changes to keywords and we're not selecting a mailbox */ |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
313 return; |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
314 } |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
315 |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
316 client->keywords.announce_count = count; |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
317 str = count == 0 ? "" : get_keywords_string(client->keywords.names); |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
318 client_send_line(client, |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
319 t_strconcat("* FLAGS ("SYSTEM_FLAGS, str, ")", NULL)); |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
320 |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
321 if (mailbox_is_readonly(client->mailbox)) { |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
322 client_send_line(client, "* OK [PERMANENTFLAGS ()] " |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
323 "Read-only mailbox."); |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
324 } else { |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
325 bool star = mailbox_allow_new_keywords(client->mailbox); |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
326 |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
327 client_send_line(client, |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
328 t_strconcat("* OK [PERMANENTFLAGS ("SYSTEM_FLAGS, str, |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
329 star ? " \\*" : "", |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
330 ")] Flags permitted.", NULL)); |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
331 } |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
332 } |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1163
diff
changeset
|
333 |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
334 void client_update_mailbox_flags(struct client *client, |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
335 const ARRAY_TYPE(keywords) *keywords) |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1163
diff
changeset
|
336 { |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
337 client->keywords.names = keywords; |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
338 client->keywords.announce_count = 0; |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
339 } |
3515
1c9f3264f2fc
Send untagged FLAGS / PERMANENTFLAGS replies if keywords list changed.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
340 |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
341 const char *const * |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
342 client_get_keyword_names(struct client *client, ARRAY_TYPE(keywords) *dest, |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
343 const ARRAY_TYPE(keyword_indexes) *src) |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
344 { |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
345 const unsigned int *kw_indexes; |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
346 const char *const *all_names; |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
347 unsigned int i, kw_count, all_count; |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
348 |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
349 client_send_mailbox_flags(client, FALSE); |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
350 |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
351 all_names = array_get(client->keywords.names, &all_count); |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
352 kw_indexes = array_get(src, &kw_count); |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
353 |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
354 /* convert indexes to names */ |
7063
f9fa0f38cb0e
Last change broke fetching keywords
Timo Sirainen <tss@iki.fi>
parents:
7057
diff
changeset
|
355 array_clear(dest); |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
356 for (i = 0; i < kw_count; i++) { |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
357 i_assert(kw_indexes[i] < all_count); |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
358 array_append(dest, &all_names[kw_indexes[i]], 1); |
3515
1c9f3264f2fc
Send untagged FLAGS / PERMANENTFLAGS replies if keywords list changed.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
359 } |
1c9f3264f2fc
Send untagged FLAGS / PERMANENTFLAGS replies if keywords list changed.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
360 |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
361 (void)array_append_space(dest); |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
362 return array_idx(dest, 0); |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1163
diff
changeset
|
363 } |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
364 |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7198
diff
changeset
|
365 bool mailbox_equals(const struct mailbox *box1, |
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7198
diff
changeset
|
366 const struct mail_storage *storage2, const char *name2) |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
367 { |
3210
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
368 struct mail_storage *storage1 = mailbox_get_storage(box1); |
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
369 const char *name1; |
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
370 |
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
371 if (storage1 != storage2) |
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
372 return FALSE; |
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
373 |
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
374 name1 = mailbox_get_name(box1); |
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
375 if (strcmp(name1, name2) == 0) |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
376 return TRUE; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
377 |
3210
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
378 return strcasecmp(name1, "INBOX") == 0 && |
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
379 strcasecmp(name2, "INBOX") == 0; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
380 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
381 |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
382 void msgset_generator_init(struct msgset_generator_context *ctx, string_t *str) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
383 { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
384 memset(ctx, 0, sizeof(*ctx)); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
385 ctx->str = str; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
386 ctx->last_uid = (uint32_t)-1; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
387 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
388 |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
389 void msgset_generator_next(struct msgset_generator_context *ctx, uint32_t uid) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
390 { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
391 if (uid != ctx->last_uid+1) { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
392 if (ctx->first_uid == 0) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
393 ; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
394 else if (ctx->first_uid == ctx->last_uid) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
395 str_printfa(ctx->str, "%u,", ctx->first_uid); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
396 else { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
397 str_printfa(ctx->str, "%u:%u,", |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
398 ctx->first_uid, ctx->last_uid); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
399 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
400 ctx->first_uid = uid; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
401 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
402 ctx->last_uid = uid; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
403 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
404 |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
405 void msgset_generator_finish(struct msgset_generator_context *ctx) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
406 { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
407 if (ctx->first_uid == ctx->last_uid) |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
408 str_printfa(ctx->str, "%u", ctx->first_uid); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
409 else |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
410 str_printfa(ctx->str, "%u:%u", ctx->first_uid, ctx->last_uid); |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
411 } |