annotate src/imap/cmd-append.c @ 2427:e1616067df5c HEAD

Syncing works now too without buffering everything. Also fixed handling input while command was being processed.
author Timo Sirainen <tss@iki.fi>
date Thu, 19 Aug 2004 02:53:39 +0300
parents d141e1bfdd63
children 47e1e05cede0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2002 Timo Sirainen */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
117
97d0b9fcc18a APPEND was broken.
Timo Sirainen <tss@iki.fi>
parents: 0
diff changeset
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
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "commands.h"
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
47ecd950a702 some header file cleanups
Timo Sirainen <tss@iki.fi>
parents: 1023
diff changeset
11 #include "mail-storage.h"
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
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
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 /* Returns -1 = error, 0 = need more data, 1 = successful. flags and
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 internal_date may be NULL as a result, but mailbox and msg_size are always
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 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
18 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
19 const char **internal_date, uoff_t *msg_size,
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
20 int *nonsync)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 {
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
22 /* [<flags>] */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
23 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
24 *flags = NULL;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
25 else {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
26 *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
27 args++;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
30 /* [<internal date>] */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
31 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
32 *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
33 else {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
34 *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
35 args++;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
36 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
1022
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
38 if (args->type != IMAP_ARG_LITERAL_SIZE &&
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
39 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
40 return FALSE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41
1022
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
42 *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
43 *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
44 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 877
diff changeset
47 int cmd_append(struct client *client)
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 {
1654
31c4bb26a1e9 Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents: 1622
diff changeset
49 struct mail_storage *storage;
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
50 struct mailbox *box;
1168
03f1455664d7 Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents: 1041
diff changeset
51 struct mailbox_status status;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
52 struct mailbox_transaction_context *t;
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
53 struct imap_parser *save_parser;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
54 struct imap_arg *args;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 877
diff changeset
55 struct imap_arg_list *flags_list;
1958
4dec6a3d79fd s/custom flags/keywords/
Timo Sirainen <tss@iki.fi>
parents: 1917
diff changeset
56 struct mailbox_keywords old_flags;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents: 903
diff changeset
57 struct mail_full_flags flags;
1870
c972ea085643 istream rewrite. instead of directly setting any limits to stream, you now
Timo Sirainen <tss@iki.fi>
parents: 1813
diff changeset
58 struct istream *input;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 time_t internal_date;
1813
cae2c9166bd0 cleanup
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
60 const char *mailbox, *internal_date_str;
2427
e1616067df5c Syncing works now too without buffering everything. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
61 enum mailbox_sync_flags sync_flags = 0;
184
4223b9ed0c80 move size_t fixes
Timo Sirainen <tss@iki.fi>
parents: 119
diff changeset
62 uoff_t msg_size;
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
63 unsigned int count;
1813
cae2c9166bd0 cleanup
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
64 int ret, failed, timezone_offset, nonsync;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
66 /* <mailbox> */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
67 if (!client_read_string_args(client, 1, &mailbox))
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
68 return FALSE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69
450
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 444
diff changeset
70 if (!client_verify_mailbox_name(client, mailbox, TRUE, FALSE))
925d6eb5f8be MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents: 444
diff changeset
71 return TRUE;
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72
2350
1371d41c375f Moved namespace and hierarchy separator handling to imap-specific code. LIST
Timo Sirainen <tss@iki.fi>
parents: 2222
diff changeset
73 storage = client_find_storage(client, &mailbox);
1654
31c4bb26a1e9 Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents: 1622
diff changeset
74 if (storage == NULL)
31c4bb26a1e9 Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents: 1622
diff changeset
75 return TRUE;
31c4bb26a1e9 Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents: 1622
diff changeset
76
2190
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
77 if (client->mailbox != NULL &&
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
78 mailbox_name_equals(mailbox_get_name(client->mailbox), mailbox))
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
79 box = client->mailbox;
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
80 else {
2199
89001f106f8d APPEND/COPY in non-selected mailbox must not remove the Recent-flag
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
81 box = mailbox_open(storage, mailbox, MAILBOX_OPEN_FAST |
89001f106f8d APPEND/COPY in non-selected mailbox must not remove the Recent-flag
Timo Sirainen <tss@iki.fi>
parents: 2190
diff changeset
82 MAILBOX_OPEN_KEEP_RECENT);
2190
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
83 if (box == NULL) {
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
84 client_send_storage_error(client, storage);
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
85 return TRUE;
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
86 }
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 }
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88
2222
c01f238a37a0 Removed UIDPLUS after all, it needs more thinking about with maildir.
Timo Sirainen <tss@iki.fi>
parents: 2199
diff changeset
89 if (mailbox_get_status(box, STATUS_KEYWORDS, &status) < 0) {
1654
31c4bb26a1e9 Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents: 1622
diff changeset
90 client_send_storage_error(client, storage);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
91 mailbox_close(box);
1168
03f1455664d7 Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents: 1041
diff changeset
92 return TRUE;
03f1455664d7 Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents: 1041
diff changeset
93 }
03f1455664d7 Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents: 1041
diff changeset
94 memset(&old_flags, 0, sizeof(old_flags));
1782
2f3d906d99d8 data_stack_pool split into two: unsafe_data_stack_pool which works like
Timo Sirainen <tss@iki.fi>
parents: 1654
diff changeset
95 old_flags.pool = pool_datastack_create();
1958
4dec6a3d79fd s/custom flags/keywords/
Timo Sirainen <tss@iki.fi>
parents: 1917
diff changeset
96 client_save_keywords(&old_flags, status.keywords,
4dec6a3d79fd s/custom flags/keywords/
Timo Sirainen <tss@iki.fi>
parents: 1917
diff changeset
97 status.keywords_count);
1168
03f1455664d7 Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents: 1041
diff changeset
98
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
99 t = mailbox_transaction_begin(box, FALSE);
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
100
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
101 /* if error occurs, the CRLF is already read. */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
102 client->input_skip_line = FALSE;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
103
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
104 count = 0;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
105 failed = TRUE;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
106 save_parser = imap_parser_create(client->input, client->output,
1591
6eca99b727a0 IMAP parser memory limits are now enforced by bytes per line rather than
Timo Sirainen <tss@iki.fi>
parents: 1552
diff changeset
107 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
108
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
109 for (;;) {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
110 /* [<flags>] [<internal date>] <message literal> */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
111 imap_parser_reset(save_parser);
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
112 for (;;) {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
113 ret = imap_parser_read_args(save_parser, 0,
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
114 IMAP_PARSE_FLAG_LITERAL_SIZE,
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
115 &args);
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
116 if (ret >= 0)
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
117 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
118 if (ret == -1) {
1813
cae2c9166bd0 cleanup
Timo Sirainen <tss@iki.fi>
parents: 1782
diff changeset
119 client_send_command_error(client, NULL);
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
120 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
121 }
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
122
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
123 /* need more data */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
124 ret = i_stream_read(client->input);
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
125 if (ret < 0) {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2350
diff changeset
126 if (ret == -2) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2350
diff changeset
127 client_send_command_error(client,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2350
diff changeset
128 "Too long argument.");
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2350
diff changeset
129 }
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
130 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
131 }
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
132 }
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
133
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2350
diff changeset
134 if (ret < 0)
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
135 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
136
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
137 if (args->type == IMAP_ARG_EOL) {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
138 /* last one */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
139 if (count > 0)
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
140 failed = FALSE;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
141 client->input_skip_line = TRUE;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
142 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
143 }
308
899d3e189dbf We didn't allow saving messages longer than 8192 bytes. Now we also send the
Timo Sirainen <tss@iki.fi>
parents: 302
diff changeset
144
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
145 if (!validate_args(args, &flags_list, &internal_date_str,
1022
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
146 &msg_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
147 /* error */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
148 client_send_command_error(client, "Invalid arguments.");
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
149 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
150 }
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
151
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
152 if (flags_list != NULL) {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
153 if (!client_parse_mail_flags(client, flags_list->args,
1168
03f1455664d7 Added setting to limit length of custom flag names.
Timo Sirainen <tss@iki.fi>
parents: 1041
diff changeset
154 &old_flags, &flags))
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
155 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
156 } else {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
157 memset(&flags, 0, sizeof(flags));
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
158 }
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
159
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
160 if (internal_date_str == NULL) {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
161 /* no time given, default to now. */
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
162 internal_date = (time_t)-1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
163 timezone_offset = 0;
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
164 } else if (!imap_parse_datetime(internal_date_str,
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
165 &internal_date,
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
166 &timezone_offset)) {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
167 client_send_tagline(client,
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
168 "BAD Invalid internal date.");
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
169 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
170 }
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
171
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
172 if (msg_size == 0) {
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
173 /* no message data, abort */
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
174 client_send_tagline(client, "NO Append aborted.");
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
175 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
176 }
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
177
1022
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
178 if (!nonsync) {
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
179 o_stream_send(client->output, "+ OK\r\n", 6);
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
180 o_stream_flush(client->output);
09bac2875ed8 Support for LITERAL+ extension.
Timo Sirainen <tss@iki.fi>
parents: 1015
diff changeset
181 }
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
182
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
183 /* save the mail */
1870
c972ea085643 istream rewrite. instead of directly setting any limits to stream, you now
Timo Sirainen <tss@iki.fi>
parents: 1813
diff changeset
184 input = i_stream_create_limit(default_pool, client->input,
c972ea085643 istream rewrite. instead of directly setting any limits to stream, you now
Timo Sirainen <tss@iki.fi>
parents: 1813
diff changeset
185 client->input->v_offset,
c972ea085643 istream rewrite. instead of directly setting any limits to stream, you now
Timo Sirainen <tss@iki.fi>
parents: 1813
diff changeset
186 msg_size);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
187 if (mailbox_save(t, &flags, internal_date, timezone_offset,
2222
c01f238a37a0 Removed UIDPLUS after all, it needs more thinking about with maildir.
Timo Sirainen <tss@iki.fi>
parents: 2199
diff changeset
188 NULL, input, NULL) < 0) {
1870
c972ea085643 istream rewrite. instead of directly setting any limits to stream, you now
Timo Sirainen <tss@iki.fi>
parents: 1813
diff changeset
189 i_stream_unref(input);
1654
31c4bb26a1e9 Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents: 1622
diff changeset
190 client_send_storage_error(client, storage);
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
191 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
192 }
1870
c972ea085643 istream rewrite. instead of directly setting any limits to stream, you now
Timo Sirainen <tss@iki.fi>
parents: 1813
diff changeset
193 i_stream_unref(input);
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
194
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
195 if (client->input->closed)
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
196 break;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
197
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
198 count++;
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
199 }
1509
69261ad92783 Fixed memory leak.
Timo Sirainen <tss@iki.fi>
parents: 1168
diff changeset
200 imap_parser_destroy(save_parser);
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
201
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
202 if (failed)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
203 mailbox_transaction_rollback(t);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
204 else {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
205 if (mailbox_transaction_commit(t) < 0) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
206 failed = TRUE;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
207 client_send_storage_error(client, storage);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1870
diff changeset
208 }
1015
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
209 }
40a327d356de Support for MULTIAPPEND extension. COPY now behaves like spec says - if it
Timo Sirainen <tss@iki.fi>
parents: 988
diff changeset
210
2427
e1616067df5c Syncing works now too without buffering everything. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
211 if (box != client->mailbox) {
e1616067df5c Syncing works now too without buffering everything. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
212 sync_flags |= MAILBOX_SYNC_FLAG_FAST;
2190
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
213 mailbox_close(box);
237
06d6eca0a45f Fixes for no diskspace handling. seems to work now.
Timo Sirainen <tss@iki.fi>
parents: 184
diff changeset
214 }
2190
755ec9442a58 mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents: 1958
diff changeset
215
2427
e1616067df5c Syncing works now too without buffering everything. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
216 return failed ? TRUE :
e1616067df5c Syncing works now too without buffering everything. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
217 cmd_sync(client, sync_flags, "OK Append completed.");
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 }