Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/cmd-append.c @ 7018:b83be2b6ac8f HEAD
If post-APPEND syncing sent a lot of data, connection could have hanged.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 22 Dec 2007 01:19:11 +0200 |
parents | 9a074ef38b02 |
children | 4b51ee73ed51 |
rev | line source |
---|---|
6429
65c69a53a7be
Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents:
6428
diff
changeset
|
1 /* Copyright (c) 2002-2007 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 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
15 struct cmd_append_context { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
16 struct client *client; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
17 struct client_command_context *cmd; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
18 struct mail_storage *storage; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
19 struct mailbox *box; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
20 struct mailbox_transaction_context *t; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
21 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
22 struct istream *input; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
23 uoff_t msg_size; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
24 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
25 struct imap_parser *save_parser; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
26 struct mail_save_context *save_ctx; |
5132
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
27 struct mailbox_keywords old_keywords; |
5574 | 28 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
|
29 |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
30 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
|
31 unsigned int failed:1; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
32 }; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
33 |
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
|
34 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
|
35 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
|
36 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
|
37 |
6418
46d9ee79f292
Removed _ prefix from all public APIs.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
38 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
|
39 { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
40 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
|
41 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
|
42 bool finished; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
43 |
5110 | 44 i_assert(!client->destroyed); |
45 | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
46 client->last_input = ioloop_time; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
47 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
48 switch (i_stream_read(client->input)) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
49 case -1: |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
50 /* 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
|
51 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
|
52 /* 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
|
53 cmd_append_continue_message() anymore. */ |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
54 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
|
55 client_destroy(client, "Disconnected in APPEND"); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
56 return; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
57 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
|
58 if (ctx->message_input) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
59 /* message data, this is handled internally by |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
60 mailbox_save_continue() */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
61 break; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
62 } |
5325 | 63 cmd_append_finish(cmd->context); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
64 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
65 /* 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
|
66 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
|
67 until newline is found. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
68 client->input_skip_line = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
69 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
70 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
|
71 cmd->param_error = TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
72 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
|
73 return; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
74 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
75 |
5669 | 76 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
|
77 finished = cmd->func(cmd); |
b83be2b6ac8f
If post-APPEND syncing sent a lot of data, connection could have hanged.
Timo Sirainen <tss@iki.fi>
parents:
6983
diff
changeset
|
78 o_stream_uncork(client->output); |
b83be2b6ac8f
If post-APPEND syncing sent a lot of data, connection could have hanged.
Timo Sirainen <tss@iki.fi>
parents:
6983
diff
changeset
|
79 if (finished) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
80 client_command_free(cmd); |
6531
d747bfbda43c
Fixed process hanging sometimes when disconnecting.
Timo Sirainen <tss@iki.fi>
parents:
6512
diff
changeset
|
81 client_continue_pending_input(&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
|
82 } else if (cmd->output_pending) { |
b83be2b6ac8f
If post-APPEND syncing sent a lot of data, connection could have hanged.
Timo Sirainen <tss@iki.fi>
parents:
6983
diff
changeset
|
83 /* syncing didn't send everything */ |
b83be2b6ac8f
If post-APPEND syncing sent a lot of data, connection could have hanged.
Timo Sirainen <tss@iki.fi>
parents:
6983
diff
changeset
|
84 o_stream_set_flush_pending(client->output, TRUE); |
5110 | 85 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
86 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
87 |
0 | 88 /* Returns -1 = error, 0 = need more data, 1 = successful. flags and |
89 internal_date may be NULL as a result, but mailbox and msg_size are always | |
90 set when successful. */ | |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
91 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
|
92 const struct imap_arg **flags_r, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
93 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
|
94 bool *nonsync_r) |
0 | 95 { |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
96 /* [<flags>] */ |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
97 if (args->type != IMAP_ARG_LIST) |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
98 *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
|
99 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
|
100 *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
|
101 args++; |
0 | 102 } |
103 | |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
104 /* [<internal date>] */ |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
105 if (args->type != IMAP_ARG_STRING) |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
106 *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
|
107 else { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
108 *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
|
109 args++; |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
110 } |
0 | 111 |
1022
09bac2875ed8
Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents:
1015
diff
changeset
|
112 if (args->type != IMAP_ARG_LITERAL_SIZE && |
2731
b63b4080c6b2
Handle failures without crashing
Timo Sirainen <tss@iki.fi>
parents:
2670
diff
changeset
|
113 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
|
114 *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
|
115 return FALSE; |
2731
b63b4080c6b2
Handle failures without crashing
Timo Sirainen <tss@iki.fi>
parents:
2670
diff
changeset
|
116 } |
0 | 117 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
118 *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
|
119 *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
|
120 return TRUE; |
0 | 121 } |
122 | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
123 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
|
124 { |
5110 | 125 imap_parser_destroy(&ctx->save_parser); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
126 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
127 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
|
128 |
4956 | 129 io_remove(&ctx->client->io); |
5415 | 130 /* we must put back the original flush callback before beginning to |
131 sync (the command is still unfinished at that point) */ | |
132 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
|
133 client_output, ctx->client); |
4956 | 134 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
135 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
|
136 i_stream_unref(&ctx->input); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
137 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
|
138 mailbox_save_cancel(&ctx->save_ctx); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
139 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
|
140 mailbox_transaction_rollback(&ctx->t); |
5132
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
141 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
|
142 mailbox_close(&ctx->box); |
5132
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
143 |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6418
diff
changeset
|
144 pool_unref(&ctx->client->keywords.pool); |
5132
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
145 ctx->client->keywords = ctx->old_keywords; |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
146 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
147 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
148 |
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
|
149 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
|
150 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
151 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
|
152 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
|
153 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
154 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
|
155 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
|
156 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
157 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
158 |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
159 (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
|
160 (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
|
161 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
|
162 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 } |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
167 |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
168 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
|
169 /* 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
|
170 more messages. */ |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
171 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
|
172 ctx->input = NULL; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
173 |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 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
|
178 } |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
179 |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
180 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
|
181 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
182 |
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
|
183 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
|
184 { |
5279 | 185 ctx->failed = TRUE; |
186 | |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
191 |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
192 /* 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
|
193 data as commands. */ |
6142
6c0bfc35af03
Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents:
6049
diff
changeset
|
194 ctx->input = i_stream_create_limit(ctx->client->input, |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
195 ctx->client->input->v_offset, |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
196 ctx->msg_size); |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
197 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
198 ctx->message_input = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
199 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
|
200 ctx->cmd->context = ctx; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
201 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
|
202 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
203 |
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
|
204 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
|
205 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
206 struct client *client = cmd->client; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 struct mail_keywords *keywords; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
213 const char *internal_date_str; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
214 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
|
215 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
|
216 bool nonsync; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
217 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
218 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
|
219 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
|
220 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
221 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
222 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
223 /* 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
|
224 client->input_skip_line = FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
225 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
226 /* [<flags>] [<internal date>] <message literal> */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
227 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
|
228 IMAP_PARSE_FLAG_LITERAL_SIZE, &args); |
5296
542967561249
Logout crashfix in some conditions.
Timo Sirainen <tss@iki.fi>
parents:
5284
diff
changeset
|
229 if (ret == -1 || client->output->closed) { |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
230 if (!ctx->failed) |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
231 client_send_command_error(cmd, NULL); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
232 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
233 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
234 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
235 if (ret < 0) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
236 /* need more data */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
237 return FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
238 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
239 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
240 if (args->type == IMAP_ARG_EOL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
241 /* last message */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
242 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
|
243 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
|
244 uint32_t uid_validity, uid1, uid2; |
5574 | 245 const char *msg; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
246 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
247 /* 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
|
248 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
|
249 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
250 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
|
251 /* 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
|
252 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
|
253 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
|
254 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
255 |
6512
1a3604c8ee05
mailbox_transaction_commit*() doesn't sync the mailbox anymore, so it
Timo Sirainen <tss@iki.fi>
parents:
6454
diff
changeset
|
256 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
|
257 &uid_validity, |
5574 | 258 &uid1, &uid2); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
259 if (ret < 0) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
260 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
|
261 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
262 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
263 } |
5574 | 264 i_assert(ctx->count == uid2 - uid1 + 1); |
265 | |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
266 if (uid1 == uid2) { |
5574 | 267 msg = t_strdup_printf("OK [APPENDUID %u %u] " |
268 "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
|
269 uid_validity, uid1); |
5574 | 270 } else { |
271 msg = t_strdup_printf("OK [APPENDUID %u %u:%u] " | |
272 "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
|
273 uid_validity, uid1, uid2); |
5574 | 274 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
275 |
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
|
276 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
|
277 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
|
278 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
|
279 } 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
|
280 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
|
281 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
|
282 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
283 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
284 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
|
285 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
|
286 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
287 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
288 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
|
289 &ctx->msg_size, &nonsync)) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
290 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
|
291 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
|
292 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
293 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
294 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
|
295 /* 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
|
296 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
|
297 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
298 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
299 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
300 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
|
301 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
|
302 &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
|
303 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
|
304 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
|
305 keywords = NULL; |
6354
8476d665530f
Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents:
6353
diff
changeset
|
306 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
|
307 &keywords) < 0) { |
23c9ac999578
mailbox_keywords_create() checks keyword validity now and returns failure if
Timo Sirainen <tss@iki.fi>
parents:
6338
diff
changeset
|
308 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
|
309 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
|
310 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
311 } else { |
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 = 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
313 keywords = NULL; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
314 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
315 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
316 if (internal_date_str == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
317 /* no time given, default to now. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
318 internal_date = (time_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
319 timezone_offset = 0; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
320 } 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
|
321 &internal_date, &timezone_offset)) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
322 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
|
323 return cmd_append_cancel(ctx, nonsync); |
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 (ctx->msg_size == 0) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
327 /* no message data, abort */ |
6621 | 328 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
|
329 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
330 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
331 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
332 /* save the mail */ |
6142
6c0bfc35af03
Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents:
6049
diff
changeset
|
333 ctx->input = i_stream_create_limit(client->input, |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
334 client->input->v_offset, |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
335 ctx->msg_size); |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
336 ret = mailbox_save_init(ctx->t, flags, keywords, |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
337 internal_date, timezone_offset, NULL, |
4277
c8af5a2492c5
If connection closes while appending, we crashed in some situations.
Timo Sirainen <tss@iki.fi>
parents:
4268
diff
changeset
|
338 ctx->input, FALSE, &ctx->save_ctx); |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
339 |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
340 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
|
341 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
|
342 |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
343 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
|
344 /* 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
|
345 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
|
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 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
349 /* 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
|
350 client->input_skip_line = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
351 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
352 if (!nonsync) { |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
353 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
|
354 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
|
355 o_stream_uncork(client->output); |
5669 | 356 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
|
357 } |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3131
diff
changeset
|
358 |
5574 | 359 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
|
360 ctx->message_input = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
361 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
|
362 return cmd_append_continue_message(cmd); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
363 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
364 |
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
|
365 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
|
366 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
367 struct client *client = cmd->client; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
368 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
|
369 size_t size; |
5110 | 370 int ret; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
371 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
372 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
|
373 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
|
374 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
375 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
376 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
377 if (ctx->save_ctx != NULL) { |
5110 | 378 while (ctx->input->v_offset != ctx->msg_size) { |
379 ret = i_stream_read(ctx->input); | |
380 if (mailbox_save_continue(ctx->save_ctx) < 0) { | |
381 /* we still have to finish reading the message | |
382 from client */ | |
383 mailbox_save_cancel(&ctx->save_ctx); | |
5208
f5fdc9dd1023
Don't crash if mail saving fails.
Timo Sirainen <tss@iki.fi>
parents:
5151
diff
changeset
|
384 break; |
5110 | 385 } |
5151
59604f7d92e8
APPEND ate all CPU if client didn't send the message fast enough.
Timo Sirainen <tss@iki.fi>
parents:
5132
diff
changeset
|
386 if (ret == -1 || ret == 0) |
5110 | 387 break; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
388 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
389 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
390 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
391 if (ctx->save_ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
392 (void)i_stream_read(ctx->input); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
393 (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
|
394 i_stream_skip(ctx->input, size); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
395 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
396 |
3442
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
397 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
|
398 bool all_written = ctx->input->v_offset == ctx->msg_size; |
3443 | 399 |
5110 | 400 /* finished */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
401 i_stream_unref(&ctx->input); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
402 ctx->input = NULL; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
403 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
404 if (ctx->save_ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
405 /* failed above */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
406 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
|
407 ctx->failed = TRUE; |
3443 | 408 } else if (!all_written) { |
3442
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
409 /* client disconnected before it finished sending the |
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
410 whole message. */ |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
411 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
|
412 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
|
413 client_disconnect(client, "EOF while appending"); |
4287 | 414 } 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
|
415 ctx->failed = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
416 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
|
417 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
418 ctx->save_ctx = NULL; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
419 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
420 if (client->input->closed) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
421 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
422 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
423 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
424 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
425 /* 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
|
426 ctx->message_input = FALSE; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
427 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
|
428 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
|
429 return cmd_append_continue_parsing(cmd); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
430 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
431 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
432 return FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
433 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
434 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
435 static struct mailbox * |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
436 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
|
437 { |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
438 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
|
439 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
|
440 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
441 if (!client_verify_mailbox_name(cmd, name, TRUE, FALSE)) |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
442 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
|
443 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
444 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
|
445 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
|
446 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
|
447 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 |
4041
9d7420b0e1ef
Make life easier for plugins:
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4024
diff
changeset
|
452 box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_SAVEONLY | |
9d7420b0e1ef
Make life easier for plugins:
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4024
diff
changeset
|
453 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
|
454 if (box == NULL) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
455 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
|
456 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
|
457 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
458 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
|
459 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
460 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
6267
diff
changeset
|
461 static void get_keywords(struct cmd_append_context *ctx) |
5132
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
462 { |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
463 struct client *client = ctx->client; |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
464 struct mailbox_status status; |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
465 |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
466 /* we'll need to get the current keywords so that |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
467 client_parse_mail_flags()'s keyword verification works. |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
468 however if we're not appending to selected mailbox, we'll |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
469 need to restore the keywords list. */ |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
6267
diff
changeset
|
470 mailbox_get_status(ctx->box, STATUS_KEYWORDS, &status); |
5132
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
471 if (ctx->box != client->mailbox) { |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
472 ctx->old_keywords = client->keywords; |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
473 |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
474 memset(&client->keywords, 0, sizeof(client->keywords)); |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
475 client->keywords.pool = |
5284
6ba1cd2580ee
Use a larger initial pool size for keywords.
Timo Sirainen <tss@iki.fi>
parents:
5279
diff
changeset
|
476 pool_alloconly_create("append keywords pool", 256); |
5132
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
477 } |
6983
9a074ef38b02
If APPEND updated keywords list in selected mailbox, send the list to client
Timo Sirainen <tss@iki.fi>
parents:
6621
diff
changeset
|
478 if (client_save_keywords(&client->keywords, status.keywords) && |
9a074ef38b02
If APPEND updated keywords list in selected mailbox, send the list to client
Timo Sirainen <tss@iki.fi>
parents:
6621
diff
changeset
|
479 ctx->box == client->mailbox) { |
9a074ef38b02
If APPEND updated keywords list in selected mailbox, send the list to client
Timo Sirainen <tss@iki.fi>
parents:
6621
diff
changeset
|
480 client_send_mailbox_flags(ctx->client, ctx->box, |
9a074ef38b02
If APPEND updated keywords list in selected mailbox, send the list to client
Timo Sirainen <tss@iki.fi>
parents:
6621
diff
changeset
|
481 status.keywords); |
9a074ef38b02
If APPEND updated keywords list in selected mailbox, send the list to client
Timo Sirainen <tss@iki.fi>
parents:
6621
diff
changeset
|
482 } |
5132
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
483 } |
c4fab2513f50
If we've a mailbox selected and we're appending to another mailbox, we got
Timo Sirainen <tss@iki.fi>
parents:
5110
diff
changeset
|
484 |
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
|
485 bool cmd_append(struct client_command_context *cmd) |
0 | 486 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
487 struct client *client = cmd->client; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
488 struct cmd_append_context *ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
489 const char *mailbox; |
0 | 490 |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
491 /* <mailbox> */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
492 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
|
493 return FALSE; |
0 | 494 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
495 /* 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
|
496 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
|
497 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
498 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
|
499 ctx->cmd = cmd; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
500 ctx->client = client; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
501 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
|
502 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
|
503 ctx->failed = TRUE; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
504 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
|
505 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
|
506 |
6275
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
6267
diff
changeset
|
507 get_keywords(ctx); |
913b188f4dd4
Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents:
6267
diff
changeset
|
508 ctx->t = mailbox_transaction_begin(ctx->box, |
5574 | 509 MAILBOX_TRANSACTION_FLAG_EXTERNAL | |
510 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
|
511 } |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
512 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
513 io_remove(&client->io); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
514 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
|
515 client_input_append, cmd); |
2878 | 516 /* append is special because we're only waiting on client input, not |
517 client output, so disable the standard output handler until we're | |
518 finished */ | |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4287
diff
changeset
|
519 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
|
520 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
521 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
|
522 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
|
523 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
524 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
|
525 cmd->context = ctx; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
526 return cmd_append_continue_parsing(cmd); |
0 | 527 } |