Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/cmd-append.c @ 5835:d59ed6a31b66 HEAD
Added more consts to imap-parser API
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 29 Jun 2007 19:03:45 +0300 |
parents | 3d14f363f921 |
children | 9f869a7a3d73 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
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 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
38 static void client_input(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; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
42 |
5110 | 43 i_assert(!client->destroyed); |
44 | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
45 client->last_input = ioloop_time; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
46 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
47 switch (i_stream_read(client->input)) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
48 case -1: |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
49 /* 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
|
50 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
|
51 /* 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
|
52 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
|
53 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
|
54 client_destroy(client, "Disconnected in APPEND"); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
55 return; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
56 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
|
57 if (ctx->message_input) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
58 /* message data, this is handled internally by |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
59 mailbox_save_continue() */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
60 break; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
61 } |
5325 | 62 cmd_append_finish(cmd->context); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
63 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
64 /* 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
|
65 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
|
66 until newline is found. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
67 client->input_skip_line = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
68 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 return; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
73 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
74 |
5669 | 75 o_stream_cork(client->output); |
5110 | 76 if (cmd->func(cmd)) { |
5669 | 77 o_stream_uncork(client->output); |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
78 client_command_free(cmd); |
5110 | 79 client_continue_pending_input(client); |
80 } | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
81 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
82 |
0 | 83 /* Returns -1 = error, 0 = need more data, 1 = successful. flags and |
84 internal_date may be NULL as a result, but mailbox and msg_size are always | |
85 set when successful. */ | |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
86 static int validate_args(const struct imap_arg *args, |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
87 const struct imap_arg_list **flags_r, |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
88 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
|
89 bool *nonsync_r) |
0 | 90 { |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
91 /* [<flags>] */ |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
92 if (args->type != IMAP_ARG_LIST) |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
93 *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
|
94 else { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
95 *flags_r = IMAP_ARG_LIST(args); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
96 args++; |
0 | 97 } |
98 | |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
99 /* [<internal date>] */ |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
100 if (args->type != IMAP_ARG_STRING) |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
101 *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
|
102 else { |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
103 *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
|
104 args++; |
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
105 } |
0 | 106 |
1022
09bac2875ed8
Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents:
1015
diff
changeset
|
107 if (args->type != IMAP_ARG_LITERAL_SIZE && |
2731
b63b4080c6b2
Handle failures without crashing
Timo Sirainen <tss@iki.fi>
parents:
2670
diff
changeset
|
108 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
|
109 *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
|
110 return FALSE; |
2731
b63b4080c6b2
Handle failures without crashing
Timo Sirainen <tss@iki.fi>
parents:
2670
diff
changeset
|
111 } |
0 | 112 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
113 *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
|
114 *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
|
115 return TRUE; |
0 | 116 } |
117 | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
118 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
|
119 { |
5110 | 120 imap_parser_destroy(&ctx->save_parser); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
121 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
122 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
|
123 |
4956 | 124 io_remove(&ctx->client->io); |
5415 | 125 /* we must put back the original flush callback before beginning to |
126 sync (the command is still unfinished at that point) */ | |
127 o_stream_set_flush_callback(ctx->client->output, | |
128 _client_output, ctx->client); | |
4956 | 129 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
130 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
|
131 i_stream_unref(&ctx->input); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
132 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
|
133 mailbox_save_cancel(&ctx->save_ctx); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 |
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
|
139 pool_unref(ctx->client->keywords.pool); |
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
|
140 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
|
141 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
142 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
143 |
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
|
144 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
|
145 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
146 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
|
147 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
|
148 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
149 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
|
150 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
|
151 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
152 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
153 |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
154 (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
|
155 (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
|
156 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
|
157 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 } |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
162 |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
163 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
|
164 /* 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
|
165 more messages. */ |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
166 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
|
167 ctx->input = NULL; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
168 |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 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
|
173 } |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
174 |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
175 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
|
176 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
177 |
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
|
178 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
|
179 { |
5279 | 180 ctx->failed = TRUE; |
181 | |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 } |
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 /* 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
|
188 data as commands. */ |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
189 ctx->input = i_stream_create_limit(default_pool, ctx->client->input, |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
190 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
|
191 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
|
192 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
193 ctx->message_input = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
194 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
|
195 ctx->cmd->context = ctx; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
196 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
|
197 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
198 |
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
|
199 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
|
200 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
201 struct client *client = cmd->client; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
202 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
|
203 const struct imap_arg *args; |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5801
diff
changeset
|
204 const struct imap_arg_list *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
|
205 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
|
206 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
|
207 struct mail_keywords *keywords; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
208 const char *internal_date_str; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
209 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
|
210 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
|
211 bool nonsync; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
212 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
213 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
|
214 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
|
215 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
216 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
217 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
218 /* 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
|
219 client->input_skip_line = FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
220 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
221 /* [<flags>] [<internal date>] <message literal> */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
222 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
|
223 IMAP_PARSE_FLAG_LITERAL_SIZE, &args); |
5296
542967561249
Logout crashfix in some conditions.
Timo Sirainen <tss@iki.fi>
parents:
5284
diff
changeset
|
224 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
|
225 if (!ctx->failed) |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
226 client_send_command_error(cmd, NULL); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
227 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
228 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
229 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
230 if (ret < 0) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
231 /* need more data */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
232 return FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
233 } |
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 (args->type == IMAP_ARG_EOL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
236 /* last message */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
237 enum mailbox_sync_flags sync_flags; |
5574 | 238 struct mailbox_status status; |
239 uint32_t uid1, uid2; | |
240 const char *msg; | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
241 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
242 /* 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
|
243 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
|
244 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
245 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
|
246 /* 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
|
247 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
|
248 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
|
249 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
250 |
5574 | 251 if (mailbox_get_status(ctx->box, STATUS_UIDVALIDITY, |
252 &status) < 0) { | |
253 client_send_storage_error(cmd, ctx->storage); | |
254 cmd_append_finish(ctx); | |
255 return TRUE; | |
256 } | |
257 | |
258 ret = mailbox_transaction_commit_get_uids(&ctx->t, 0, | |
259 &uid1, &uid2); | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
260 if (ret < 0) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
261 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
|
262 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
263 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
264 } |
5574 | 265 i_assert(ctx->count == uid2 - uid1 + 1); |
266 | |
267 if (uid1 == uid2) { | |
268 msg = t_strdup_printf("OK [APPENDUID %u %u] " | |
269 "Append completed.", | |
270 status.uidvalidity, uid1); | |
271 } else { | |
272 msg = t_strdup_printf("OK [APPENDUID %u %u:%u] " | |
273 "Append completed.", | |
274 status.uidvalidity, uid1, uid2); | |
275 } | |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
276 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
277 sync_flags = ctx->box == cmd->client->mailbox ? |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
278 0 : MAILBOX_SYNC_FLAG_FAST; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
279 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
280 cmd_append_finish(ctx); |
5574 | 281 return cmd_sync(cmd, sync_flags, 0, msg); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
282 } |
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 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
|
285 &ctx->msg_size, &nonsync)) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
286 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
|
287 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
|
288 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
289 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
290 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
|
291 /* 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
|
292 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
|
293 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
294 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
295 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
296 if (flags_list != NULL) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
297 if (!client_parse_mail_flags(cmd, flags_list->args, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
298 &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
|
299 return cmd_append_cancel(ctx, nonsync); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
300 keywords = keywords_list == NULL ? NULL : |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
301 mailbox_keywords_create(ctx->t, keywords_list); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
302 } else { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
303 flags = 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
304 keywords = NULL; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
305 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
306 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
307 if (internal_date_str == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
308 /* no time given, default to now. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
309 internal_date = (time_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
310 timezone_offset = 0; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
311 } 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
|
312 &internal_date, &timezone_offset)) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
313 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
|
314 return cmd_append_cancel(ctx, nonsync); |
2446
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 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
317 if (ctx->msg_size == 0) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
318 /* no message data, abort */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
319 client_send_tagline(cmd, "NO Append aborted."); |
5801
3d14f363f921
APPEND {0+} didn't eat the finishing CRLF.
Timo Sirainen <tss@iki.fi>
parents:
5669
diff
changeset
|
320 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
321 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
322 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
323 /* save the mail */ |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
324 ctx->input = i_stream_create_limit(default_pool, client->input, |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
331 if (keywords != NULL) |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
332 mailbox_keywords_free(ctx->t, &keywords); |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
333 |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
334 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
|
335 /* 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
|
336 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
|
337 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
338 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
339 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
340 /* 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
|
341 client->input_skip_line = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
342 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
343 if (!nonsync) { |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
344 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
|
345 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
|
346 o_stream_uncork(client->output); |
5669 | 347 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
|
348 } |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3131
diff
changeset
|
349 |
5574 | 350 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
|
351 ctx->message_input = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
352 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
|
353 return cmd_append_continue_message(cmd); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
354 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
355 |
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
|
356 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
|
357 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
358 struct client *client = cmd->client; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
359 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
|
360 size_t size; |
5110 | 361 int ret; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
362 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
363 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
|
364 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
|
365 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
366 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
367 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
368 if (ctx->save_ctx != NULL) { |
5110 | 369 while (ctx->input->v_offset != ctx->msg_size) { |
370 ret = i_stream_read(ctx->input); | |
371 if (mailbox_save_continue(ctx->save_ctx) < 0) { | |
372 /* we still have to finish reading the message | |
373 from client */ | |
374 mailbox_save_cancel(&ctx->save_ctx); | |
5208
f5fdc9dd1023
Don't crash if mail saving fails.
Timo Sirainen <tss@iki.fi>
parents:
5151
diff
changeset
|
375 break; |
5110 | 376 } |
5151
59604f7d92e8
APPEND ate all CPU if client didn't send the message fast enough.
Timo Sirainen <tss@iki.fi>
parents:
5132
diff
changeset
|
377 if (ret == -1 || ret == 0) |
5110 | 378 break; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
379 } |
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 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
382 if (ctx->save_ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
383 (void)i_stream_read(ctx->input); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
384 (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
|
385 i_stream_skip(ctx->input, size); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
386 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
387 |
3442
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
388 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
|
389 bool all_written = ctx->input->v_offset == ctx->msg_size; |
3443 | 390 |
5110 | 391 /* finished */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
392 i_stream_unref(&ctx->input); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
393 ctx->input = NULL; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
394 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
395 if (ctx->save_ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
396 /* failed above */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
397 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
|
398 ctx->failed = TRUE; |
3443 | 399 } else if (!all_written) { |
3442
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
400 /* client disconnected before it finished sending the |
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
401 whole message. */ |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
402 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
|
403 mailbox_save_cancel(&ctx->save_ctx); |
4287 | 404 } 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
|
405 ctx->failed = TRUE; |
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); |
2446
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 ctx->save_ctx = NULL; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
409 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
410 if (client->input->closed) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
411 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
412 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
413 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
414 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
415 /* 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
|
416 ctx->message_input = FALSE; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
417 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
|
418 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
|
419 return cmd_append_continue_parsing(cmd); |
2446
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 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
422 return FALSE; |
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 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
425 static struct mailbox * |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
426 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
|
427 { |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
428 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
|
429 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
|
430 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
431 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
|
432 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
|
433 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
434 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
|
435 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
|
436 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
|
437 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
438 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
|
439 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
|
440 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
|
441 |
4041
9d7420b0e1ef
Make life easier for plugins:
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4024
diff
changeset
|
442 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
|
443 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
|
444 if (box == NULL) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
445 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
|
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 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
448 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
|
449 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
450 |
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
|
451 static int get_keywords(struct cmd_append_context *ctx) |
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
|
452 { |
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
|
453 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
|
454 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
|
455 |
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
|
456 /* 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
|
457 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
|
458 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
|
459 need to restore the keywords list. */ |
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
|
460 if (mailbox_get_status(ctx->box, STATUS_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
|
461 &status) < 0) |
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 return -1; |
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 |
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 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
|
465 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
|
466 |
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 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
|
468 client->keywords.pool = |
5284
6ba1cd2580ee
Use a larger initial pool size for keywords.
Timo Sirainen <tss@iki.fi>
parents:
5279
diff
changeset
|
469 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
|
470 } |
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 client_save_keywords(&client->keywords, status.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
|
472 return 0; |
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 |
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
|
475 bool cmd_append(struct client_command_context *cmd) |
0 | 476 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
477 struct client *client = cmd->client; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
478 struct cmd_append_context *ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
479 const char *mailbox; |
0 | 480 |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
481 /* <mailbox> */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
482 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
|
483 return FALSE; |
0 | 484 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
485 /* 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
|
486 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
|
487 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
488 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
|
489 ctx->cmd = cmd; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
490 ctx->client = client; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
491 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
|
492 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
|
493 ctx->failed = TRUE; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
494 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
|
495 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
|
496 |
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
|
497 if (get_keywords(ctx) < 0) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
498 client_send_storage_error(cmd, ctx->storage); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
499 mailbox_close(&ctx->box); |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
500 ctx->failed = TRUE; |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
501 } else { |
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
|
502 ctx->t = mailbox_transaction_begin(ctx->box, |
5574 | 503 MAILBOX_TRANSACTION_FLAG_EXTERNAL | |
504 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
|
505 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
506 } |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
507 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
508 io_remove(&client->io); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
509 client->io = io_add(i_stream_get_fd(client->input), IO_READ, |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
510 client_input, cmd); |
2878 | 511 /* append is special because we're only waiting on client input, not |
512 client output, so disable the standard output handler until we're | |
513 finished */ | |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4287
diff
changeset
|
514 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
|
515 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
516 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
|
517 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
|
518 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
519 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
|
520 cmd->context = ctx; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
521 return cmd_append_continue_parsing(cmd); |
0 | 522 } |