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