comparison src/pop3/client.c @ 5500:4862cb37106c HEAD

Moved namespace handling to lib-storage. Beginnings of namespace support for non-IMAP parts of Dovecot.
author Timo Sirainen <tss@iki.fi>
date Tue, 03 Apr 2007 11:34:27 +0300
parents bbe25ef34f03
children 74d3236313c1
comparison
equal deleted inserted replaced
5499:e1e19a0db57d 5500:4862cb37106c
9 #include "str.h" 9 #include "str.h"
10 #include "var-expand.h" 10 #include "var-expand.h"
11 #include "mail-storage.h" 11 #include "mail-storage.h"
12 #include "commands.h" 12 #include "commands.h"
13 #include "mail-search.h" 13 #include "mail-search.h"
14 #include "mail-namespace.h"
14 15
15 #include <stdlib.h> 16 #include <stdlib.h>
16 #include <unistd.h> 17 #include <unistd.h>
17 18
18 /* max. length of input command line (spec says 512) */ 19 /* max. length of input command line (spec says 512) */
122 buffer_free(message_sizes_buf); 123 buffer_free(message_sizes_buf);
123 return FALSE; 124 return FALSE;
124 } 125 }
125 126
126 struct client *client_create(int fd_in, int fd_out, 127 struct client *client_create(int fd_in, int fd_out,
127 struct mail_storage *storage) 128 struct mail_namespace *namespaces)
128 { 129 {
130 struct mail_storage *storage;
131 const char *inbox;
129 struct client *client; 132 struct client *client;
130 enum mailbox_open_flags flags; 133 enum mailbox_open_flags flags;
131 const char *errmsg; 134 const char *errmsg;
132 bool syntax_error, temporary_error; 135 bool syntax_error, temporary_error;
133 136
144 (size_t)-1, FALSE); 147 (size_t)-1, FALSE);
145 o_stream_set_flush_callback(client->output, client_output, client); 148 o_stream_set_flush_callback(client->output, client_output, client);
146 149
147 client->io = io_add(fd_in, IO_READ, client_input, client); 150 client->io = io_add(fd_in, IO_READ, client_input, client);
148 client->last_input = ioloop_time; 151 client->last_input = ioloop_time;
149 client->storage = storage; 152
150 153 client->namespaces = namespaces;
154
155 inbox = "INBOX";
156 client->inbox_ns = mail_namespace_find(namespaces, &inbox);
157 if (client->inbox_ns == NULL) {
158 client_send_line(client, "-ERR No INBOX namespace for user.");
159 client_destroy(client, "No INBOX namespace for user.");
160 return NULL;
161 }
162
163 storage = client->inbox_ns->storage;
151 mail_storage_set_callbacks(storage, &mail_storage_callbacks, client); 164 mail_storage_set_callbacks(storage, &mail_storage_callbacks, client);
152 165
153 flags = 0; 166 flags = 0;
154 if (no_flag_updates) 167 if (no_flag_updates)
155 flags |= MAILBOX_OPEN_KEEP_RECENT; 168 flags |= MAILBOX_OPEN_KEEP_RECENT;
235 message sizes. */ 248 message sizes. */
236 (void)mailbox_transaction_commit(&client->trans, 0); 249 (void)mailbox_transaction_commit(&client->trans, 0);
237 } 250 }
238 if (client->mailbox != NULL) 251 if (client->mailbox != NULL)
239 mailbox_close(&client->mailbox); 252 mailbox_close(&client->mailbox);
240 mail_storage_destroy(&client->storage); 253 mail_namespaces_deinit(&client->namespaces);
241 254
242 i_free(client->message_sizes); 255 i_free(client->message_sizes);
243 i_free(client->deleted_bitmask); 256 i_free(client->deleted_bitmask);
244 257
245 if (client->io != NULL) 258 if (client->io != NULL)
331 "state, please relogin."); 344 "state, please relogin.");
332 client_disconnect(client, "Mailbox is in inconsistent state."); 345 client_disconnect(client, "Mailbox is in inconsistent state.");
333 return; 346 return;
334 } 347 }
335 348
336 error = mail_storage_get_last_error(client->storage, &syntax, 349 error = mail_storage_get_last_error(client->inbox_ns->storage, &syntax,
337 &temporary_error); 350 &temporary_error);
338 client_send_line(client, "-ERR %s", error != NULL ? error : 351 client_send_line(client, "-ERR %s", error != NULL ? error :
339 "BUG: Unknown error"); 352 "BUG: Unknown error");
340 } 353 }
341 354