Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/cmd-append.c @ 764:f57c52738f90 HEAD
Renamed IBuffer and OBuffer to IStream and OStream which describes their
functionality better. I tried to keep the variable names and comments also
sensible.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 06 Dec 2002 03:09:22 +0200 |
parents | e1254b838e0b |
children | 8b3518bb327e |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "common.h" | |
117 | 4 #include "ioloop.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
5 #include "ostream.h" |
0 | 6 #include "commands.h" |
7 #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
|
8 #include "imap-date.h" |
0 | 9 |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
10 #include <sys/time.h> |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
11 |
0 | 12 /* Returns -1 = error, 0 = need more data, 1 = successful. flags and |
13 internal_date may be NULL as a result, but mailbox and msg_size are always | |
14 set when successful. */ | |
15 static int validate_args(Client *client, const char **mailbox, | |
16 ImapArgList **flags, const char **internal_date, | |
184 | 17 uoff_t *msg_size, unsigned int count) |
0 | 18 { |
19 ImapArg *args; | |
20 | |
21 i_assert(count >= 2 && count <= 4); | |
22 | |
23 *flags = NULL; | |
24 *internal_date = NULL; | |
25 | |
117 | 26 if (!client_read_args(client, count, IMAP_PARSE_FLAG_LITERAL_SIZE, |
27 &args)) | |
28 return 0; | |
0 | 29 |
30 switch (count) { | |
31 case 2: | |
32 /* do we have flags or internal date parameter? */ | |
33 if (args[1].type == IMAP_ARG_LIST || | |
34 args[1].type == IMAP_ARG_STRING) | |
35 return validate_args(client, mailbox, flags, | |
36 internal_date, msg_size, 3); | |
37 | |
38 break; | |
39 case 3: | |
40 /* do we have both flags and internal date? */ | |
41 if (args[1].type == IMAP_ARG_LIST && | |
42 args[2].type == IMAP_ARG_STRING) | |
43 return validate_args(client, mailbox, flags, | |
44 internal_date, msg_size, 4); | |
45 | |
46 if (args[1].type == IMAP_ARG_LIST) | |
47 *flags = args[1].data.list; | |
48 else if (args[1].type == IMAP_ARG_STRING) | |
49 *internal_date = args[1].data.str; | |
50 else | |
51 return -1; | |
52 break; | |
53 case 4: | |
54 /* we have all parameters */ | |
55 *flags = args[1].data.list; | |
56 *internal_date = args[2].data.str; | |
57 break; | |
58 default: | |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
59 i_unreached(); |
0 | 60 } |
61 | |
62 /* check that mailbox and message arguments are ok */ | |
63 *mailbox = imap_arg_string(&args[0]); | |
64 if (*mailbox == NULL) | |
65 return -1; | |
66 | |
117 | 67 if (args[count-1].type != IMAP_ARG_LITERAL_SIZE) |
0 | 68 return -1; |
69 | |
117 | 70 *msg_size = args[count-1].data.literal_size; |
0 | 71 return 1; |
72 } | |
73 | |
74 int cmd_append(Client *client) | |
75 { | |
76 ImapArgList *flags_list; | |
77 Mailbox *box; | |
78 MailFlags flags; | |
79 time_t internal_date; | |
80 const char *custom_flags[MAIL_CUSTOM_FLAGS_COUNT]; | |
81 const char *mailbox, *internal_date_str; | |
184 | 82 uoff_t msg_size; |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
83 int failed, timezone_offset; |
0 | 84 |
85 /* <mailbox> [<flags>] [<internal date>] <message literal> */ | |
86 switch (validate_args(client, &mailbox, &flags_list, | |
87 &internal_date_str, &msg_size, 2)) { | |
88 case -1: | |
89 /* error */ | |
90 client_send_command_error(client, "Invalid APPEND arguments."); | |
91 return TRUE; | |
92 case 0: | |
93 /* need more data */ | |
94 return FALSE; | |
95 } | |
96 | |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
97 if (flags_list != NULL) { |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
98 if (!client_parse_mail_flags(client, flags_list->args, |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
99 flags_list->size, |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
100 &flags, custom_flags)) |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
101 return TRUE; |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
102 } else { |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
103 if (!client_parse_mail_flags(client, NULL, 0, |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
104 &flags, custom_flags)) |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
105 return TRUE; |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
106 } |
0 | 107 |
117 | 108 if (internal_date_str == NULL) { |
109 /* no time given, default to now. */ | |
110 internal_date = ioloop_time; | |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
111 timezone_offset = ioloop_timezone.tz_minuteswest; |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
112 } else if (!imap_parse_datetime(internal_date_str, &internal_date, |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
113 &timezone_offset)) { |
0 | 114 client_send_tagline(client, "BAD Invalid internal date."); |
115 return TRUE; | |
116 } | |
117 | |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
118 /* open the mailbox */ |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
119 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
|
120 return TRUE; |
0 | 121 |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
122 box = client->storage->open_mailbox(client->storage, |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
123 mailbox, FALSE, TRUE); |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
124 if (box == NULL) { |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
125 client_send_storage_error(client); |
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
126 return TRUE; |
0 | 127 } |
128 | |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
129 o_stream_send(client->output, "+ OK\r\n", 6); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
130 o_stream_flush(client->output); |
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
|
131 |
0 | 132 /* save the mail */ |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
133 failed = !box->save(box, flags, custom_flags, |
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
450
diff
changeset
|
134 internal_date, timezone_offset, |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
135 client->input, msg_size); |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
136 box->close(box); |
0 | 137 |
237
06d6eca0a45f
Fixes for no diskspace handling. seems to work now.
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
138 if (failed) { |
06d6eca0a45f
Fixes for no diskspace handling. seems to work now.
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
139 client_send_storage_error(client); |
06d6eca0a45f
Fixes for no diskspace handling. seems to work now.
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
140 } else { |
450
925d6eb5f8be
MailStorage interface change. We now let storage call several sync-functions
Timo Sirainen <tss@iki.fi>
parents:
444
diff
changeset
|
141 client_sync_full(client); |
237
06d6eca0a45f
Fixes for no diskspace handling. seems to work now.
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
142 client_send_tagline(client, "OK Append completed."); |
06d6eca0a45f
Fixes for no diskspace handling. seems to work now.
Timo Sirainen <tss@iki.fi>
parents:
184
diff
changeset
|
143 } |
0 | 144 return TRUE; |
145 } |