Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/cmd-append.c @ 9445:d7f8dbc38fd7 HEAD
imap: If client disconnects while appending, don't treat the rest of the message as commands.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 20 Oct 2009 13:21:13 -0400 |
parents | 39c234ab0b21 |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "common.h" | |
117 | 4 #include "ioloop.h" |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
5 #include "istream.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
6 #include "ostream.h" |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
1958
diff
changeset
|
7 #include "str.h" |
0 | 8 #include "commands.h" |
9 #include "imap-parser.h" | |
119
2f67de235489
Whops, we were using RFC822 dates everywhere instead of IMAP dates.
Timo Sirainen <tss@iki.fi>
parents:
117
diff
changeset
|
10 #include "imap-date.h" |
1041 | 11 #include "mail-storage.h" |
0 | 12 |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
13 #include <sys/time.h> |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
14 |
8906
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
15 /* Don't allow internaldates to be too far in the future. At least with Maildir |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
16 they can cause problems with incremental backups since internaldate is |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
17 stored in file's mtime. But perhaps there are also some other reasons why |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
18 it might not be wanted. */ |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
19 #define INTERNALDATE_MAX_FUTURE_SECS (2*3600) |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
20 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
21 struct cmd_append_context { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
22 struct client *client; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
23 struct client_command_context *cmd; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
24 struct mail_storage *storage; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
25 struct mailbox *box; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
26 struct mailbox_transaction_context *t; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
27 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
28 struct istream *input; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
29 uoff_t msg_size; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
30 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
31 struct imap_parser *save_parser; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
32 struct mail_save_context *save_ctx; |
5574 | 33 unsigned int count; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
34 |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
35 unsigned int message_input:1; |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
36 unsigned int failed:1; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
37 }; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
38 |
4024
7d7b0f427d68
If client disconnected or gave too long APPEND command line, we didn't properly deinitialize saving, which could have caused partially written mails with mbox, or files left lying in tmp/ with maildir.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3963
diff
changeset
|
39 static void cmd_append_finish(struct cmd_append_context *ctx); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
40 static bool cmd_append_continue_message(struct client_command_context *cmd); |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
41 static bool cmd_append_continue_parsing(struct client_command_context *cmd); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
42 |
6418
46d9ee79f292
Removed _ prefix from all public APIs.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
43 static void client_input_append(struct client_command_context *cmd) |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
44 { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
45 struct cmd_append_context *ctx = cmd->context; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
46 struct client *client = cmd->client; |
7018
b83be2b6ac8f
If post-APPEND syncing sent a lot of data, connection could have hanged.
Timo Sirainen <tss@iki.fi>
parents:
6983
diff
changeset
|
47 bool finished; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
48 |
5110 | 49 i_assert(!client->destroyed); |
50 | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
51 client->last_input = ioloop_time; |
7126
0861436bfe14
Reset idle timeout also in APPEND/IDLE.
Timo Sirainen <tss@iki.fi>
parents:
7103
diff
changeset
|
52 timeout_reset(client->to_idle); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
53 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
54 switch (i_stream_read(client->input)) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
55 case -1: |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
56 /* disconnected */ |
4024
7d7b0f427d68
If client disconnected or gave too long APPEND command line, we didn't properly deinitialize saving, which could have caused partially written mails with mbox, or files left lying in tmp/ with maildir.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3963
diff
changeset
|
57 cmd_append_finish(cmd->context); |
4169
8686345192e8
Don't crash if client disconnects while appending message.
Timo Sirainen <tss@iki.fi>
parents:
4096
diff
changeset
|
58 /* Reset command so that client_destroy() doesn't try to call |
8686345192e8
Don't crash if client disconnects while appending message.
Timo Sirainen <tss@iki.fi>
parents:
4096
diff
changeset
|
59 cmd_append_continue_message() anymore. */ |
7431
33d8adcc2d44
client_command_free()/cancel(): Take pointer-to-pointer parameter and set it
Timo Sirainen <tss@iki.fi>
parents:
7215
diff
changeset
|
60 client_command_free(&cmd); |
4096
904c53275e83
Log a line when IMAP client disconnects with a reason why it happened.
Timo Sirainen <tss@iki.fi>
parents:
4044
diff
changeset
|
61 client_destroy(client, "Disconnected in APPEND"); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
62 return; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
63 case -2: |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
64 if (ctx->message_input) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
65 /* message data, this is handled internally by |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
66 mailbox_save_continue() */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
67 break; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
68 } |
5325 | 69 cmd_append_finish(cmd->context); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
70 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
71 /* parameter word is longer than max. input buffer size. |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
72 this is most likely an error, so skip the new data |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
73 until newline is found. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
74 client->input_skip_line = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
75 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
76 client_send_command_error(cmd, "Too long argument."); |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
77 cmd->param_error = TRUE; |
7431
33d8adcc2d44
client_command_free()/cancel(): Take pointer-to-pointer parameter and set it
Timo Sirainen <tss@iki.fi>
parents:
7215
diff
changeset
|
78 client_command_free(&cmd); |
4024
7d7b0f427d68
If client disconnected or gave too long APPEND command line, we didn't properly deinitialize saving, which could have caused partially written mails with mbox, or files left lying in tmp/ with maildir.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3963
diff
changeset
|
79 return; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
80 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
81 |
9095
9a0aa39a3a14
imap: Cleaned up "command pending" handling code. Should fix hangs caused by recent changes.
Timo Sirainen <tss@iki.fi>
parents:
9028
diff
changeset
|
82 o_stream_cork(client->output); |
7018
b83be2b6ac8f
If post-APPEND syncing sent a lot of data, connection could have hanged.
Timo Sirainen <tss@iki.fi>
parents:
6983
diff
changeset
|
83 finished = cmd->func(cmd); |
7148
5e3188213724
Added "command state" for running commands. Use it instead of some bitfields
Timo Sirainen <tss@iki.fi>
parents:
7126
diff
changeset
|
84 if (!finished && cmd->state != CLIENT_COMMAND_STATE_DONE) |
7103
284dd5f2777d
Use separate idle timeouts to avoid unneededly checking them every n seconds.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
85 (void)client_handle_unfinished_cmd(cmd); |
7195
bca55675d77c
When pipelining commands, delay synchronizations so that only one combined
Timo Sirainen <tss@iki.fi>
parents:
7148
diff
changeset
|
86 else |
7431
33d8adcc2d44
client_command_free()/cancel(): Take pointer-to-pointer parameter and set it
Timo Sirainen <tss@iki.fi>
parents:
7215
diff
changeset
|
87 client_command_free(&cmd); |
7215
492c5dfc5fd8
Fixed a potential hang after APPEND.
Timo Sirainen <tss@iki.fi>
parents:
7195
diff
changeset
|
88 (void)cmd_sync_delayed(client); |
9095
9a0aa39a3a14
imap: Cleaned up "command pending" handling code. Should fix hangs caused by recent changes.
Timo Sirainen <tss@iki.fi>
parents:
9028
diff
changeset
|
89 o_stream_uncork(client->output); |
9a0aa39a3a14
imap: Cleaned up "command pending" handling code. Should fix hangs caused by recent changes.
Timo Sirainen <tss@iki.fi>
parents:
9028
diff
changeset
|
90 |
9a0aa39a3a14
imap: Cleaned up "command pending" handling code. Should fix hangs caused by recent changes.
Timo Sirainen <tss@iki.fi>
parents:
9028
diff
changeset
|
91 if (client->disconnected) |
9a0aa39a3a14
imap: Cleaned up "command pending" handling code. Should fix hangs caused by recent changes.
Timo Sirainen <tss@iki.fi>
parents:
9028
diff
changeset
|
92 client_destroy(client, NULL); |
9a0aa39a3a14
imap: Cleaned up "command pending" handling code. Should fix hangs caused by recent changes.
Timo Sirainen <tss@iki.fi>
parents:
9028
diff
changeset
|
93 else |
9a0aa39a3a14
imap: Cleaned up "command pending" handling code. Should fix hangs caused by recent changes.
Timo Sirainen <tss@iki.fi>
parents:
9028
diff
changeset
|
94 client_continue_pending_input(client); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
95 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
96 |
0 | 97 /* Returns -1 = error, 0 = need more data, 1 = successful. flags and |
98 internal_date may be NULL as a result, but mailbox and msg_size are always | |
99 set when successful. */ | |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
100 static int validate_args(const struct imap_arg *args, |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
101 const struct imap_arg **flags_r, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
102 const char **internal_date_r, uoff_t *msg_size_r, |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
103 bool *nonsync_r) |
0 | 104 { |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
105 /* [<flags>] */ |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
106 if (args->type != IMAP_ARG_LIST) |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
107 *flags_r = NULL; |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
108 else { |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
109 *flags_r = IMAP_ARG_LIST_ARGS(args); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
110 args++; |
0 | 111 } |
112 | |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
113 /* [<internal date>] */ |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
114 if (args->type != IMAP_ARG_STRING) |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
115 *internal_date_r = NULL; |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
116 else { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
117 *internal_date_r = IMAP_ARG_STR(args); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
118 args++; |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
119 } |
0 | 120 |
1022
09bac2875ed8
Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents:
1015
diff
changeset
|
121 if (args->type != IMAP_ARG_LITERAL_SIZE && |
2731
b63b4080c6b2
Handle failures without crashing
Timo Sirainen <tss@iki.fi>
parents:
2670
diff
changeset
|
122 args->type != IMAP_ARG_LITERAL_SIZE_NONSYNC) { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
123 *nonsync_r = FALSE; |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
124 return FALSE; |
2731
b63b4080c6b2
Handle failures without crashing
Timo Sirainen <tss@iki.fi>
parents:
2670
diff
changeset
|
125 } |
0 | 126 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
127 *nonsync_r = args->type == IMAP_ARG_LITERAL_SIZE_NONSYNC; |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
128 *msg_size_r = IMAP_ARG_LITERAL_SIZE(args); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
129 return TRUE; |
0 | 130 } |
131 | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
132 static void cmd_append_finish(struct cmd_append_context *ctx) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
133 { |
5110 | 134 imap_parser_destroy(&ctx->save_parser); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
135 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
136 i_assert(ctx->client->input_lock == ctx->cmd); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
137 |
4956 | 138 io_remove(&ctx->client->io); |
5415 | 139 /* we must put back the original flush callback before beginning to |
140 sync (the command is still unfinished at that point) */ | |
141 o_stream_set_flush_callback(ctx->client->output, | |
6418
46d9ee79f292
Removed _ prefix from all public APIs.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
142 client_output, ctx->client); |
4956 | 143 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
144 if (ctx->input != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
145 i_stream_unref(&ctx->input); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
146 if (ctx->save_ctx != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
147 mailbox_save_cancel(&ctx->save_ctx); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
148 if (ctx->t != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
149 mailbox_transaction_rollback(&ctx->t); |
7056
097c70cfa55e
client_parse_mail_flags() no longer does keyword verification, so there's no
Timo Sirainen <tss@iki.fi>
parents:
7031
diff
changeset
|
150 if (ctx->box != ctx->cmd->client->mailbox && ctx->box != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
151 mailbox_close(&ctx->box); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
152 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
153 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
154 static bool cmd_append_continue_cancel(struct client_command_context *cmd) |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
155 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
156 struct cmd_append_context *ctx = cmd->context; |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
157 size_t size; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
158 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
159 if (cmd->cancel) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
160 cmd_append_finish(ctx); |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
161 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
162 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
163 |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
164 (void)i_stream_read(ctx->input); |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
165 (void)i_stream_get_data(ctx->input, &size); |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
166 i_stream_skip(ctx->input, size); |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
167 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
168 if (cmd->client->input->closed) { |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
169 cmd_append_finish(ctx); |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
170 return TRUE; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
171 } |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
172 |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
173 if (ctx->input->v_offset == ctx->msg_size) { |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
174 /* finished, but with MULTIAPPEND and LITERAL+ we may get |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
175 more messages. */ |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
176 i_stream_unref(&ctx->input); |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
177 ctx->input = NULL; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
178 |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
179 ctx->message_input = FALSE; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
180 imap_parser_reset(ctx->save_parser); |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
181 cmd->func = cmd_append_continue_parsing; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
182 return cmd_append_continue_parsing(cmd); |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
183 } |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
184 |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
185 return FALSE; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
186 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
187 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
188 static bool cmd_append_cancel(struct cmd_append_context *ctx, bool nonsync) |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
189 { |
5279 | 190 ctx->failed = TRUE; |
191 | |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
192 if (!nonsync) { |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
193 cmd_append_finish(ctx); |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
194 return TRUE; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
195 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
196 |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
197 /* we have to read the nonsynced literal so we don't treat the message |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
198 data as commands. */ |
7031
4b51ee73ed51
Removed v_start_offset parameter from i_stream_create_limit(). We'll always
Timo Sirainen <tss@iki.fi>
parents:
7018
diff
changeset
|
199 ctx->input = i_stream_create_limit(ctx->client->input, ctx->msg_size); |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
200 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
201 ctx->message_input = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
202 ctx->cmd->func = cmd_append_continue_cancel; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
203 ctx->cmd->context = ctx; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
204 return cmd_append_continue_cancel(ctx->cmd); |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
205 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
206 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
207 static bool cmd_append_continue_parsing(struct client_command_context *cmd) |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
208 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
209 struct client *client = cmd->client; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
210 struct cmd_append_context *ctx = cmd->context; |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
211 const struct imap_arg *args; |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
212 const struct imap_arg *flags_list; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
213 enum mail_flags flags; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
214 const char *const *keywords_list; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
215 struct mail_keywords *keywords; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
216 const char *internal_date_str; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
217 time_t internal_date; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
218 int ret, timezone_offset; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
219 bool nonsync; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
220 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
221 if (cmd->cancel) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
222 cmd_append_finish(ctx); |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
223 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
224 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
225 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
226 /* if error occurs, the CRLF is already read. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
227 client->input_skip_line = FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
228 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
229 /* [<flags>] [<internal date>] <message literal> */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
230 ret = imap_parser_read_args(ctx->save_parser, 0, |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
231 IMAP_PARSE_FLAG_LITERAL_SIZE, &args); |
9445
d7f8dbc38fd7
imap: If client disconnects while appending, don't treat the rest of the message as commands.
Timo Sirainen <tss@iki.fi>
parents:
9135
diff
changeset
|
232 if (ret == -1) { |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
233 if (!ctx->failed) |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
234 client_send_command_error(cmd, NULL); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
235 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
236 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
237 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
238 if (ret < 0) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
239 /* need more data */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
240 return FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
241 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
242 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
243 if (args->type == IMAP_ARG_EOL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
244 /* last message */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
245 enum mailbox_sync_flags sync_flags; |
6454
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
246 enum imap_sync_flags imap_flags; |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
247 uint32_t uid_validity, uid1, uid2; |
5574 | 248 const char *msg; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
249 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
250 /* eat away the trailing CRLF */ |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
251 client->input_skip_line = TRUE; |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
252 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
253 if (ctx->failed) { |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
254 /* we failed earlier, error message is sent */ |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
255 cmd_append_finish(ctx); |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
256 return TRUE; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
257 } |
9028
fa9bc4ef6f32
APPEND: Don't assert-crash if message size parameter isn't given.
Timo Sirainen <tss@iki.fi>
parents:
8906
diff
changeset
|
258 if (ctx->count == 0) { |
fa9bc4ef6f32
APPEND: Don't assert-crash if message size parameter isn't given.
Timo Sirainen <tss@iki.fi>
parents:
8906
diff
changeset
|
259 client_send_tagline(cmd, "BAD Missing message size."); |
fa9bc4ef6f32
APPEND: Don't assert-crash if message size parameter isn't given.
Timo Sirainen <tss@iki.fi>
parents:
8906
diff
changeset
|
260 cmd_append_finish(ctx); |
fa9bc4ef6f32
APPEND: Don't assert-crash if message size parameter isn't given.
Timo Sirainen <tss@iki.fi>
parents:
8906
diff
changeset
|
261 return TRUE; |
fa9bc4ef6f32
APPEND: Don't assert-crash if message size parameter isn't given.
Timo Sirainen <tss@iki.fi>
parents:
8906
diff
changeset
|
262 } |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
263 |
6512
1a3604c8ee05
mailbox_transaction_commit*() doesn't sync the mailbox anymore, so it
Timo Sirainen <tss@iki.fi>
parents:
6454
diff
changeset
|
264 ret = mailbox_transaction_commit_get_uids(&ctx->t, |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
265 &uid_validity, |
5574 | 266 &uid1, &uid2); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
267 if (ret < 0) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
268 client_send_storage_error(cmd, ctx->storage); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
269 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
270 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
271 } |
5574 | 272 i_assert(ctx->count == uid2 - uid1 + 1); |
273 | |
8789
d153c72800e0
IMAP: Don't return APPENDUI/COPYUID if backend didn't provide them.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
274 if (uid1 == 0) |
d153c72800e0
IMAP: Don't return APPENDUI/COPYUID if backend didn't provide them.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
275 msg = "OK Append completed."; |
d153c72800e0
IMAP: Don't return APPENDUI/COPYUID if backend didn't provide them.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
276 else if (uid1 == uid2) { |
5574 | 277 msg = t_strdup_printf("OK [APPENDUID %u %u] " |
278 "Append completed.", | |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
279 uid_validity, uid1); |
5574 | 280 } else { |
281 msg = t_strdup_printf("OK [APPENDUID %u %u:%u] " | |
282 "Append completed.", | |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
283 uid_validity, uid1, uid2); |
5574 | 284 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
285 |
6454
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
286 if (ctx->box == cmd->client->mailbox) { |
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
287 sync_flags = 0; |
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
288 imap_flags = IMAP_SYNC_FLAG_SAFE; |
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
289 } else { |
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
290 sync_flags = MAILBOX_SYNC_FLAG_FAST; |
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
291 imap_flags = 0; |
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
292 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
293 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
294 cmd_append_finish(ctx); |
6454
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
295 return cmd_sync(cmd, sync_flags, imap_flags, msg); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
296 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
297 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
298 if (!validate_args(args, &flags_list, &internal_date_str, |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
299 &ctx->msg_size, &nonsync)) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
300 client_send_command_error(cmd, "Invalid arguments."); |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
301 return cmd_append_cancel(ctx, nonsync); |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
302 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
303 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
304 if (ctx->failed) { |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
305 /* we failed earlier, make sure we just eat nonsync-literal |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
306 if it's given. */ |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
307 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
308 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
309 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
310 if (flags_list != NULL) { |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
311 if (!client_parse_mail_flags(cmd, flags_list, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
312 &flags, &keywords_list)) |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
313 return cmd_append_cancel(ctx, nonsync); |
6353
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
6338
diff
changeset
|
314 if (keywords_list == NULL) |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
6338
diff
changeset
|
315 keywords = NULL; |
6354
8476d665530f
Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents:
6353
diff
changeset
|
316 else if (mailbox_keywords_create(ctx->box, keywords_list, |
6353
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
6338
diff
changeset
|
317 &keywords) < 0) { |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
6338
diff
changeset
|
318 client_send_storage_error(cmd, ctx->storage); |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
6338
diff
changeset
|
319 return cmd_append_cancel(ctx, nonsync); |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
6338
diff
changeset
|
320 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
321 } else { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
322 flags = 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
323 keywords = NULL; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
324 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
325 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
326 if (internal_date_str == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
327 /* no time given, default to now. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
328 internal_date = (time_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
329 timezone_offset = 0; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
330 } else if (!imap_parse_datetime(internal_date_str, |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
331 &internal_date, &timezone_offset)) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
332 client_send_tagline(cmd, "BAD Invalid internal date."); |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
333 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
334 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
335 |
8906
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
336 if (internal_date != (time_t)-1 && |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
337 internal_date > ioloop_time + INTERNALDATE_MAX_FUTURE_SECS) { |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
338 /* the client specified a time in the future, set it to now. */ |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
339 internal_date = (time_t)-1; |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
340 timezone_offset = 0; |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
341 } |
3c33885a717a
IMAP: Don't allow APPEND to specify INTERNALDATE more than 2 hours into future.
Timo Sirainen <tss@iki.fi>
parents:
8789
diff
changeset
|
342 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
343 if (ctx->msg_size == 0) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
344 /* no message data, abort */ |
6621 | 345 client_send_tagline(cmd, "NO Can't save a zero byte message."); |
5801
3d14f363f921
APPEND {0+} didn't eat the finishing CRLF.
Timo Sirainen <tss@iki.fi>
parents:
5669
diff
changeset
|
346 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
347 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
348 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
349 /* save the mail */ |
7031
4b51ee73ed51
Removed v_start_offset parameter from i_stream_create_limit(). We'll always
Timo Sirainen <tss@iki.fi>
parents:
7018
diff
changeset
|
350 ctx->input = i_stream_create_limit(client->input, ctx->msg_size); |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
7870
diff
changeset
|
351 ctx->save_ctx = mailbox_save_alloc(ctx->t); |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
7870
diff
changeset
|
352 mailbox_save_set_flags(ctx->save_ctx, flags, keywords); |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
7870
diff
changeset
|
353 mailbox_save_set_received_date(ctx->save_ctx, |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
7870
diff
changeset
|
354 internal_date, timezone_offset); |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
7870
diff
changeset
|
355 ret = mailbox_save_begin(&ctx->save_ctx, ctx->input); |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
356 |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
357 if (keywords != NULL) |
6354
8476d665530f
Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents:
6353
diff
changeset
|
358 mailbox_keywords_free(ctx->box, &keywords); |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
359 |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
360 if (ret < 0) { |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
361 /* save initialization failed */ |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
362 client_send_storage_error(cmd, ctx->storage); |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
363 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
364 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
365 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
366 /* after literal comes CRLF, if we fail make sure we eat it away */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
367 client->input_skip_line = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
368 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
369 if (!nonsync) { |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
370 o_stream_send(client->output, "+ OK\r\n", 6); |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
371 o_stream_flush(client->output); |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
372 o_stream_uncork(client->output); |
5669 | 373 o_stream_cork(client->output); |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
374 } |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3131
diff
changeset
|
375 |
5574 | 376 ctx->count++; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
377 ctx->message_input = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
378 cmd->func = cmd_append_continue_message; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
379 return cmd_append_continue_message(cmd); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
380 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
381 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
382 static bool cmd_append_continue_message(struct client_command_context *cmd) |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
383 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
384 struct client *client = cmd->client; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
385 struct cmd_append_context *ctx = cmd->context; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
386 size_t size; |
5110 | 387 int ret; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
388 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
389 if (cmd->cancel) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
390 cmd_append_finish(ctx); |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
391 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
392 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
393 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
394 if (ctx->save_ctx != NULL) { |
5110 | 395 while (ctx->input->v_offset != ctx->msg_size) { |
396 ret = i_stream_read(ctx->input); | |
397 if (mailbox_save_continue(ctx->save_ctx) < 0) { | |
398 /* we still have to finish reading the message | |
399 from client */ | |
400 mailbox_save_cancel(&ctx->save_ctx); | |
5208
f5fdc9dd1023
Don't crash if mail saving fails.
Timo Sirainen <tss@iki.fi>
parents:
5151
diff
changeset
|
401 break; |
5110 | 402 } |
5151
59604f7d92e8
APPEND ate all CPU if client didn't send the message fast enough.
Timo Sirainen <tss@iki.fi>
parents:
5132
diff
changeset
|
403 if (ret == -1 || ret == 0) |
5110 | 404 break; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
405 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
406 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
407 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
408 if (ctx->save_ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
409 (void)i_stream_read(ctx->input); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
410 (void)i_stream_get_data(ctx->input, &size); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
411 i_stream_skip(ctx->input, size); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
412 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
413 |
3442
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
414 if (ctx->input->eof || client->input->closed) { |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
415 bool all_written = ctx->input->v_offset == ctx->msg_size; |
3443 | 416 |
5110 | 417 /* finished */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
418 i_stream_unref(&ctx->input); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
419 ctx->input = NULL; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
420 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
421 if (ctx->save_ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
422 /* failed above */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
423 client_send_storage_error(cmd, ctx->storage); |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
424 ctx->failed = TRUE; |
3443 | 425 } else if (!all_written) { |
3442
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
426 /* client disconnected before it finished sending the |
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
427 whole message. */ |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
428 ctx->failed = TRUE; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
429 mailbox_save_cancel(&ctx->save_ctx); |
6338
bfb6aeddef9b
If append fails because input EOF, disconnect the client with EOF reason.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
430 client_disconnect(client, "EOF while appending"); |
4287 | 431 } else if (mailbox_save_finish(&ctx->save_ctx) < 0) { |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
432 ctx->failed = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
433 client_send_storage_error(cmd, ctx->storage); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
434 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
435 ctx->save_ctx = NULL; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
436 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
437 if (client->input->closed) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
438 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
439 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
440 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
441 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
442 /* prepare for next message */ |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
443 ctx->message_input = FALSE; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
444 imap_parser_reset(ctx->save_parser); |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
445 cmd->func = cmd_append_continue_parsing; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
446 return cmd_append_continue_parsing(cmd); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
447 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
448 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
449 return FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
450 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
451 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
452 static struct mailbox * |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
453 get_mailbox(struct client_command_context *cmd, const char *name) |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
454 { |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
455 struct mail_storage *storage; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
456 struct mailbox *box; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
457 |
9135
39c234ab0b21
IMAP: Send [ALREADYEXISTS], [NONEXISTENT] and [TRYCREATE] resp-codes correctly.
Timo Sirainen <tss@iki.fi>
parents:
9095
diff
changeset
|
458 if (!client_verify_mailbox_name(cmd, name, |
39c234ab0b21
IMAP: Send [ALREADYEXISTS], [NONEXISTENT] and [TRYCREATE] resp-codes correctly.
Timo Sirainen <tss@iki.fi>
parents:
9095
diff
changeset
|
459 CLIENT_VERIFY_MAILBOX_SHOULD_EXIST_TRYCREATE)) |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
460 return NULL; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
461 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
462 storage = client_find_storage(cmd, &name); |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
463 if (storage == NULL) |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
464 return NULL; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
465 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
466 if (cmd->client->mailbox != NULL && |
3210
2715077f9c3e
mailbox_name_equals() renamed to mailbox_equals(), which also now checks
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
467 mailbox_equals(cmd->client->mailbox, storage, name)) |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
468 return cmd->client->mailbox; |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
469 |
8468
d4eab639c253
mailbox_open() now takes struct mail_storage ** so it can be changed.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
470 box = mailbox_open(&storage, name, NULL, MAILBOX_OPEN_SAVEONLY | |
4041
9d7420b0e1ef
Make life easier for plugins:
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4024
diff
changeset
|
471 MAILBOX_OPEN_FAST | MAILBOX_OPEN_KEEP_RECENT); |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
472 if (box == NULL) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
473 client_send_storage_error(cmd, storage); |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
474 return NULL; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
475 } |
7620 | 476 if (cmd->client->enabled_features != 0) |
477 mailbox_enable(box, cmd->client->enabled_features); | |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
478 return box; |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
479 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
480 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3811
diff
changeset
|
481 bool cmd_append(struct client_command_context *cmd) |
0 | 482 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
483 struct client *client = cmd->client; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
484 struct cmd_append_context *ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
485 const char *mailbox; |
0 | 486 |
7195
bca55675d77c
When pipelining commands, delay synchronizations so that only one combined
Timo Sirainen <tss@iki.fi>
parents:
7148
diff
changeset
|
487 if (client->syncing) { |
bca55675d77c
When pipelining commands, delay synchronizations so that only one combined
Timo Sirainen <tss@iki.fi>
parents:
7148
diff
changeset
|
488 /* if transaction is created while its view is synced, |
bca55675d77c
When pipelining commands, delay synchronizations so that only one combined
Timo Sirainen <tss@iki.fi>
parents:
7148
diff
changeset
|
489 appends aren't allowed for it. */ |
bca55675d77c
When pipelining commands, delay synchronizations so that only one combined
Timo Sirainen <tss@iki.fi>
parents:
7148
diff
changeset
|
490 cmd->state = CLIENT_COMMAND_STATE_WAIT_UNAMBIGUITY; |
bca55675d77c
When pipelining commands, delay synchronizations so that only one combined
Timo Sirainen <tss@iki.fi>
parents:
7148
diff
changeset
|
491 return FALSE; |
bca55675d77c
When pipelining commands, delay synchronizations so that only one combined
Timo Sirainen <tss@iki.fi>
parents:
7148
diff
changeset
|
492 } |
bca55675d77c
When pipelining commands, delay synchronizations so that only one combined
Timo Sirainen <tss@iki.fi>
parents:
7148
diff
changeset
|
493 |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
494 /* <mailbox> */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
495 if (!client_read_string_args(cmd, 1, &mailbox)) |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
496 return FALSE; |
0 | 497 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
498 /* we keep the input locked all the time */ |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
499 client->input_lock = cmd; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
500 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
501 ctx = p_new(cmd->pool, struct cmd_append_context, 1); |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
502 ctx->cmd = cmd; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
503 ctx->client = client; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
504 ctx->box = get_mailbox(cmd, mailbox); |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
505 if (ctx->box == NULL) |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
506 ctx->failed = TRUE; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
507 else { |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
508 ctx->storage = mailbox_get_storage(ctx->box); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
509 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
6267
diff
changeset
|
510 ctx->t = mailbox_transaction_begin(ctx->box, |
5574 | 511 MAILBOX_TRANSACTION_FLAG_EXTERNAL | |
512 MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS); | |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
513 } |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
514 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
515 io_remove(&client->io); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
516 client->io = io_add(i_stream_get_fd(client->input), IO_READ, |
6418
46d9ee79f292
Removed _ prefix from all public APIs.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
517 client_input_append, cmd); |
2878 | 518 /* append is special because we're only waiting on client input, not |
519 client output, so disable the standard output handler until we're | |
520 finished */ | |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4287
diff
changeset
|
521 o_stream_unset_flush_callback(client->output); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
522 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
523 ctx->save_parser = imap_parser_create(client->input, client->output, |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
524 imap_max_line_length); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
525 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
526 cmd->func = cmd_append_continue_parsing; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
527 cmd->context = ctx; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
528 return cmd_append_continue_parsing(cmd); |
0 | 529 } |