Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/cmd-append.c @ 6267:3a1eed408cad HEAD
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
only usable way to get it returned correctly. Removed maildir-specific
mailbox_get_status() handling, it's supposed to return the current state of
the mailbox, not the latest state. It was useful only for returning non-zero
UIDVALIDITY for newly created mailboxes, and that's no longer needed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 12 Aug 2007 15:10:35 +0300 |
parents | 6c0bfc35af03 |
children | 913b188f4dd4 |
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, |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
87 const struct imap_arg **flags_r, |
5835
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 { |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
95 *flags_r = IMAP_ARG_LIST_ARGS(args); |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
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. */ |
6142
6c0bfc35af03
Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents:
6049
diff
changeset
|
189 ctx->input = i_stream_create_limit(ctx->client->input, |
2670
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
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; |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
204 const struct imap_arg *flags_list; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
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; |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
238 uint32_t uid_validity, uid1, uid2; |
5574 | 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 ret = mailbox_transaction_commit_get_uids(&ctx->t, 0, |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
251 &uid_validity, |
5574 | 252 &uid1, &uid2); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
253 if (ret < 0) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
254 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
|
255 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
256 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
257 } |
5574 | 258 i_assert(ctx->count == uid2 - uid1 + 1); |
259 | |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
260 if (uid1 == uid2) { |
5574 | 261 msg = t_strdup_printf("OK [APPENDUID %u %u] " |
262 "Append completed.", | |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
263 uid_validity, uid1); |
5574 | 264 } else { |
265 msg = t_strdup_printf("OK [APPENDUID %u %u:%u] " | |
266 "Append completed.", | |
6267
3a1eed408cad
mailbox_transaction_commit_get_uids() now returns also UIDVALIDITY. It's the
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
267 uid_validity, uid1, uid2); |
5574 | 268 } |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
269 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
270 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
|
271 0 : MAILBOX_SYNC_FLAG_FAST; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
272 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
273 cmd_append_finish(ctx); |
5574 | 274 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
|
275 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
276 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
277 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
|
278 &ctx->msg_size, &nonsync)) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
279 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
|
280 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
|
281 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
282 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
283 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
|
284 /* 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
|
285 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
|
286 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
287 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
288 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
289 if (flags_list != NULL) { |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
290 if (!client_parse_mail_flags(cmd, flags_list, |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
291 &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
|
292 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
|
293 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
|
294 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
|
295 } else { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
296 flags = 0; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2878
diff
changeset
|
297 keywords = NULL; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
298 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
299 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
300 if (internal_date_str == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
301 /* no time given, default to now. */ |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
302 internal_date = (time_t)-1; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
303 timezone_offset = 0; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
304 } 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
|
305 &internal_date, &timezone_offset)) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
306 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
|
307 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
308 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
309 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
310 if (ctx->msg_size == 0) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
311 /* no message data, abort */ |
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, "NO Append aborted."); |
5801
3d14f363f921
APPEND {0+} didn't eat the finishing CRLF.
Timo Sirainen <tss@iki.fi>
parents:
5669
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 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
316 /* save the mail */ |
6142
6c0bfc35af03
Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents:
6049
diff
changeset
|
317 ctx->input = i_stream_create_limit(client->input, |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
324 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
|
325 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
|
326 |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
327 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
|
328 /* 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
|
329 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
|
330 return cmd_append_cancel(ctx, nonsync); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
331 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
332 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
333 /* 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
|
334 client->input_skip_line = TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
335 |
4044
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
336 if (!nonsync) { |
da1d65e064f8
mailbox_save_init() supports now returning failure. Quota plugin now checks
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4041
diff
changeset
|
337 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
|
338 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
|
339 o_stream_uncork(client->output); |
5669 | 340 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
|
341 } |
3138
fbe844061fe2
Internal changes in how keywords are handled. struct mail_keywords isn't
Timo Sirainen <tss@iki.fi>
parents:
3131
diff
changeset
|
342 |
5574 | 343 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
|
344 ctx->message_input = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
345 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
|
346 return cmd_append_continue_message(cmd); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
347 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
348 |
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
|
349 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
|
350 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
351 struct client *client = cmd->client; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
352 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
|
353 size_t size; |
5110 | 354 int ret; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
355 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
356 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
|
357 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
|
358 return TRUE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
359 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
360 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
361 if (ctx->save_ctx != NULL) { |
5110 | 362 while (ctx->input->v_offset != ctx->msg_size) { |
363 ret = i_stream_read(ctx->input); | |
364 if (mailbox_save_continue(ctx->save_ctx) < 0) { | |
365 /* we still have to finish reading the message | |
366 from client */ | |
367 mailbox_save_cancel(&ctx->save_ctx); | |
5208
f5fdc9dd1023
Don't crash if mail saving fails.
Timo Sirainen <tss@iki.fi>
parents:
5151
diff
changeset
|
368 break; |
5110 | 369 } |
5151
59604f7d92e8
APPEND ate all CPU if client didn't send the message fast enough.
Timo Sirainen <tss@iki.fi>
parents:
5132
diff
changeset
|
370 if (ret == -1 || ret == 0) |
5110 | 371 break; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
372 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
373 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
374 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
375 if (ctx->save_ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
376 (void)i_stream_read(ctx->input); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
377 (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
|
378 i_stream_skip(ctx->input, size); |
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 |
3442
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
381 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
|
382 bool all_written = ctx->input->v_offset == ctx->msg_size; |
3443 | 383 |
5110 | 384 /* finished */ |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
385 i_stream_unref(&ctx->input); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
386 ctx->input = NULL; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
387 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
388 if (ctx->save_ctx == NULL) { |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
389 /* failed above */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
390 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
|
391 ctx->failed = TRUE; |
3443 | 392 } else if (!all_written) { |
3442
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
393 /* client disconnected before it finished sending the |
877fa3d04313
Yet another try at fixing APPEND.
Timo Sirainen <tss@iki.fi>
parents:
3439
diff
changeset
|
394 whole message. */ |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
395 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
|
396 mailbox_save_cancel(&ctx->save_ctx); |
4287 | 397 } 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
|
398 ctx->failed = TRUE; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
399 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
|
400 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
401 ctx->save_ctx = NULL; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
402 |
5277
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
403 if (client->input->closed) { |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
404 cmd_append_finish(ctx); |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
405 return TRUE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
406 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
407 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
408 /* 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
|
409 ctx->message_input = FALSE; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
410 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
|
411 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
|
412 return cmd_append_continue_parsing(cmd); |
2446
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 return FALSE; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
416 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
417 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
418 static struct mailbox * |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
419 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
|
420 { |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
421 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
|
422 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
|
423 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
424 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
|
425 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
|
426 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 |
4041
9d7420b0e1ef
Make life easier for plugins:
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4024
diff
changeset
|
435 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
|
436 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
|
437 if (box == NULL) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
438 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
|
439 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
|
440 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
441 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
|
442 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
443 |
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
|
444 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
|
445 { |
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
|
446 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
|
447 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
|
448 |
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
|
449 /* 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 &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
|
455 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
|
456 |
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 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
|
458 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
|
459 |
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 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
|
461 client->keywords.pool = |
5284
6ba1cd2580ee
Use a larger initial pool size for keywords.
Timo Sirainen <tss@iki.fi>
parents:
5279
diff
changeset
|
462 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
|
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 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
|
465 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
|
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 |
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
|
468 bool cmd_append(struct client_command_context *cmd) |
0 | 469 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
470 struct client *client = cmd->client; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
471 struct cmd_append_context *ctx; |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
472 const char *mailbox; |
0 | 473 |
1015
40a327d356de
Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents:
988
diff
changeset
|
474 /* <mailbox> */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
475 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
|
476 return FALSE; |
0 | 477 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
478 /* 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
|
479 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
|
480 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
481 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
|
482 ctx->cmd = cmd; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
483 ctx->client = client; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
484 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
|
485 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
|
486 ctx->failed = TRUE; |
be3d55491b37
When using MULTIAPPEND and LITERAL+ and message saving failed, we stopped
Timo Sirainen <tss@iki.fi>
parents:
5208
diff
changeset
|
487 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
|
488 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
|
489 |
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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 } 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
|
495 ctx->t = mailbox_transaction_begin(ctx->box, |
5574 | 496 MAILBOX_TRANSACTION_FLAG_EXTERNAL | |
497 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
|
498 } |
e24c801dbc09
If message was APPENDed with LITERALPLUS and it failed for some reason (eg.
Timo Sirainen <tss@iki.fi>
parents:
2518
diff
changeset
|
499 } |
1168
03f1455664d7
Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents:
1041
diff
changeset
|
500 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
501 io_remove(&client->io); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
502 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
|
503 client_input, cmd); |
2878 | 504 /* append is special because we're only waiting on client input, not |
505 client output, so disable the standard output handler until we're | |
506 finished */ | |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4287
diff
changeset
|
507 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
|
508 |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2427
diff
changeset
|
509 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
|
510 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
|
511 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
512 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
|
513 cmd->context = ctx; |
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
514 return cmd_append_continue_parsing(cmd); |
0 | 515 } |