32
32
client_destroy(client, "Disconnected for inactivity");
35
struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
35
struct client *client_create(int fd_in, int fd_out, const char *session_id,
36
struct mail_user *user,
36
37
struct mail_storage_service_user *service_user,
37
38
const struct imap_settings *set)
44
45
net_set_nonblock(fd_in, TRUE);
45
46
net_set_nonblock(fd_out, TRUE);
47
pool = pool_alloconly_create("imap client", 1024);
48
pool = pool_alloconly_create("imap client", 2048);
48
49
client = p_new(pool, struct client, 1);
49
50
client->pool = pool;
51
52
client->service_user = service_user;
53
client->session_id = p_strdup(pool, session_id);
52
54
client->fd_in = fd_in;
53
55
client->fd_out = fd_out;
54
56
client->input = i_stream_create_fd(fd_in,
82
84
str_append_c(client->capability_string, ' ');
83
85
str_append(client->capability_string, set->imap_capability + 1);
87
if (user->fuzzy_search) {
88
/* Enable FUZZY capability only when it actually has
89
a chance of working */
90
str_append(client->capability_string, " SEARCH=FUZZY");
86
93
ident = mail_user_get_anvil_userip_ident(client->user);
87
94
if (ident != NULL) {
126
cmd_ret = !cmd->cancel || cmd->func == NULL ? TRUE : cmd->func(cmd);
133
cmd_ret = !cmd->cancel || cmd->func == NULL ? TRUE :
127
135
if (!cmd_ret && cmd->state != CLIENT_COMMAND_STATE_DONE) {
128
136
if (cmd->client->output->closed)
129
137
i_panic("command didn't cancel itself: %s", cmd->name);
137
145
static struct var_expand_table static_tab[] = {
138
146
{ 'i', NULL, "input" },
139
147
{ 'o', NULL, "output" },
148
{ '\0', NULL, "session" },
140
149
{ '\0', NULL, NULL }
142
151
struct var_expand_table *tab;
148
157
tab[0].value = dec2str(i_stream_get_absolute_offset(client->input));
149
158
tab[1].value = dec2str(client->output->offset);
159
tab[2].value = client->session_id;
151
161
str = t_str_new(128);
152
162
var_expand(str, client->set->imap_logout_format, tab);
209
219
mail_user_unref(&client->user);
211
221
if (client->free_parser != NULL)
212
imap_parser_destroy(&client->free_parser);
222
imap_parser_unref(&client->free_parser);
213
223
if (client->io != NULL)
214
224
io_remove(&client->io);
215
225
if (client->to_idle_output != NULL)
547
557
client->mailbox_change_lock = NULL;
549
559
if (client->free_parser != NULL)
550
imap_parser_destroy(&cmd->parser);
560
imap_parser_unref(&cmd->parser);
552
562
imap_parser_reset(cmd->parser);
553
563
client->free_parser = cmd->parser;
670
680
if (cmd->func != NULL) {
671
681
/* command is being executed - continue it */
672
if (cmd->func(cmd) || cmd->state == CLIENT_COMMAND_STATE_DONE) {
682
if (command_exec(cmd) ||
683
cmd->state == CLIENT_COMMAND_STATE_DONE) {
673
684
/* command execution was finished */
674
685
client_command_free(&cmd);
675
686
client_add_missing_io(client);
839
850
/* continue processing command */
840
finished = cmd->func(cmd) || cmd->state == CLIENT_COMMAND_STATE_DONE;
851
finished = command_exec(cmd) || cmd->state == CLIENT_COMMAND_STATE_DONE;
843
854
(void)client_handle_unfinished_cmd(cmd);
926
void client_enable(struct client *client, enum mailbox_feature features)
937
int client_enable(struct client *client, enum mailbox_feature features)
928
939
struct mailbox_status status;
930
942
if ((client->enabled_features & features) == features)
933
945
client->enabled_features |= features;
934
946
if (client->mailbox == NULL)
937
mailbox_enable(client->mailbox, features);
938
if ((features & MAILBOX_FEATURE_CONDSTORE) != 0) {
949
ret = mailbox_enable(client->mailbox, features);
950
if ((features & MAILBOX_FEATURE_CONDSTORE) != 0 && ret == 0) {
939
951
/* CONDSTORE being enabled while mailbox is selected.
940
952
Notify client of the latest HIGHESTMODSEQ. */
941
mailbox_get_status(client->mailbox,
942
STATUS_HIGHESTMODSEQ, &status);
943
client_send_line(client, t_strdup_printf(
944
"* OK [HIGHESTMODSEQ %llu] Highest",
945
(unsigned long long)status.highest_modseq));
953
ret = mailbox_get_status(client->mailbox,
954
STATUS_HIGHESTMODSEQ, &status);
956
client_send_line(client, t_strdup_printf(
957
"* OK [HIGHESTMODSEQ %llu] Highest",
958
(unsigned long long)status.highest_modseq));
962
client_send_untagged_storage_error(client,
963
mailbox_get_storage(client->mailbox));
949
968
struct imap_search_update *