Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/imap-fetch.c @ 6429:65c69a53a7be HEAD
Replaced my Copyright notices. The year range always ends with 2007 now.
My name was replaced with "Dovecot authors". In many cases I didn't really
even own the copyright, so this is more correct.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 16 Sep 2007 14:34:22 +0300 |
parents | 6a64e64fa3a3 |
children | b5e6543b4385 |
rev | line source |
---|---|
6429
65c69a53a7be
Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
1 /* Copyright (c) 2002-2007 Dovecot authors, see the included COPYING file */ |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "common.h" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3216
diff
changeset
|
4 #include "array.h" |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
5 #include "buffer.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "istream.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "ostream.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "str.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "message-send.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "message-size.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "imap-date.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "commands.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "imap-fetch.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
14 #include "imap-util.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
16 #include <stdlib.h> |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
18 #define BODY_NIL_REPLY \ |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
19 "\"text\" \"plain\" NIL NIL NIL \"7bit\" 0 0 NIL NIL NIL" |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
20 |
4972
0103df03b5d4
Removed accidentally committed TEXTSIZE FETCH parameter.
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
21 const struct imap_fetch_handler default_handlers[7]; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
22 static buffer_t *fetch_handlers = NULL; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
23 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
24 static int imap_fetch_handler_cmp(const void *p1, const void *p2) |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
25 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
26 const struct imap_fetch_handler *h1 = p1, *h2 = p2; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
27 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
28 return strcmp(h1->name, h2->name); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
29 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
30 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
31 void imap_fetch_handlers_register(const struct imap_fetch_handler *handlers, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
32 size_t count) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
33 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
34 void *data; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
35 size_t size; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
36 |
2708
f1e9f3ec8135
Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents:
2680
diff
changeset
|
37 if (fetch_handlers == NULL) |
f1e9f3ec8135
Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents:
2680
diff
changeset
|
38 fetch_handlers = buffer_create_dynamic(default_pool, 128); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
39 buffer_append(fetch_handlers, handlers, sizeof(*handlers) * count); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
40 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
41 data = buffer_get_modifiable_data(fetch_handlers, &size); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
42 qsort(data, size / sizeof(*handlers), sizeof(*handlers), |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
43 imap_fetch_handler_cmp); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
44 } |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
45 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
46 static int imap_fetch_handler_bsearch(const void *name_p, const void *handler_p) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
47 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
48 const char *name = name_p; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
49 const struct imap_fetch_handler *h = handler_p; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
50 int i; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
51 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
52 for (i = 0; h->name[i] != '\0'; i++) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
53 if (h->name[i] != name[i]) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
54 if (name[i] < 'A' || name[i] >= 'Z') |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
55 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
56 return name[i] - h->name[i]; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
57 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
58 } |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
59 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
60 return name[i] < 'A' || name[i] >= 'Z' ? 0 : -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
61 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
62 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
63 bool imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
64 const struct imap_arg **args) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
65 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
66 const struct imap_fetch_handler *handler; |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
67 |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
68 handler = bsearch(name, fetch_handlers->data, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
69 fetch_handlers->used / |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
70 sizeof(struct imap_fetch_handler), |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
71 sizeof(struct imap_fetch_handler), |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
72 imap_fetch_handler_bsearch); |
2497
5cab421f36be
Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents:
2483
diff
changeset
|
73 if (handler == NULL) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
74 client_send_command_error(ctx->cmd, |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
75 t_strconcat("Unknown command ", name, NULL)); |
2497
5cab421f36be
Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents:
2483
diff
changeset
|
76 return FALSE; |
5cab421f36be
Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents:
2483
diff
changeset
|
77 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
78 |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
79 return handler->init(ctx, name, args); |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
80 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
81 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
82 struct imap_fetch_context *imap_fetch_init(struct client_command_context *cmd) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
84 struct client *client = cmd->client; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
85 struct imap_fetch_context *ctx; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
86 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
87 if (fetch_handlers == NULL) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
88 imap_fetch_handlers_register(default_handlers, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
89 sizeof(default_handlers) / |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
90 sizeof(default_handlers[0])); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
91 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
92 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
93 ctx = p_new(cmd->pool, struct imap_fetch_context, 1); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
94 ctx->client = client; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
95 ctx->cmd = cmd; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
96 ctx->box = client->mailbox; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
97 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
98 ctx->cur_str = str_new(default_pool, 8192); |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
99 ctx->all_headers_buf = buffer_create_dynamic(cmd->pool, 128); |
4596
bf4e98a0de3f
Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro
Timo Sirainen <tss@iki.fi>
parents:
4594
diff
changeset
|
100 p_array_init(&ctx->handlers, cmd->pool, 16); |
2730
eef378c0c07d
Don't send extra ")" line with bad FETCH parameters.
Timo Sirainen <tss@iki.fi>
parents:
2716
diff
changeset
|
101 ctx->line_finished = TRUE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
102 return ctx; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
105 #undef imap_fetch_add_handler |
4073 | 106 void imap_fetch_add_handler(struct imap_fetch_context *ctx, |
107 bool buffered, bool want_deinit, | |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
108 const char *name, const char *nil_reply, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
109 imap_fetch_handler_t *handler, void *context) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 { |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
111 /* partially because of broken clients, but also partially because |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
112 it potentially can make client implementations faster, we have a |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
113 buffered parameter which basically means that the handler promises |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
114 to write the output in ctx->cur_str. The cur_str is then sent to |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
115 client before calling any non-buffered handlers. |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
116 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
117 We try to keep the handler registration order the same as the |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
118 client requested them. This is especially useful to get UID |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
119 returned first, which some clients rely on.. |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
120 */ |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
121 const struct imap_fetch_context_handler *handlers; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
122 struct imap_fetch_context_handler h; |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
123 unsigned int i, size; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
124 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
125 if (context == NULL) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
126 /* don't allow duplicate handlers */ |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
127 handlers = array_get(&ctx->handlers, &size); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
128 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
129 for (i = 0; i < size; i++) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
130 if (handlers[i].handler == handler && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
131 handlers[i].context == NULL) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
132 return; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
133 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
134 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
135 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
136 memset(&h, 0, sizeof(h)); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
137 h.handler = handler; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
138 h.context = context; |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
139 h.buffered = buffered; |
4073 | 140 h.want_deinit = want_deinit; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
141 h.name = p_strdup(ctx->cmd->pool, name); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
142 h.nil_reply = p_strdup(ctx->cmd->pool, nil_reply); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
143 |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
144 if (!buffered) |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
145 array_append(&ctx->handlers, &h, 1); |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
146 else { |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
147 array_insert(&ctx->handlers, ctx->buffered_handlers_count, |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
148 &h, 1); |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
149 ctx->buffered_handlers_count++; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
150 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
151 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
152 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
153 void imap_fetch_begin(struct imap_fetch_context *ctx, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
154 struct mail_search_arg *search_arg) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
155 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
156 const void *null = NULL; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
157 const void *data; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
158 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
159 if (ctx->flags_update_seen) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
160 if (mailbox_is_readonly(ctx->box)) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
161 ctx->flags_update_seen = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
162 else if (!ctx->flags_have_handler) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
163 ctx->flags_show_only_seen_changes = TRUE; |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
164 (void)imap_fetch_init_handler(ctx, "FLAGS", NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
165 } |
1638
e95c0e462591
API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents:
1534
diff
changeset
|
166 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
168 if (buffer_get_used_size(ctx->all_headers_buf) != 0 && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
169 ((ctx->fetch_data & (MAIL_FETCH_STREAM_HEADER | |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
170 MAIL_FETCH_STREAM_BODY)) == 0)) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
171 buffer_append(ctx->all_headers_buf, &null, sizeof(null)); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
172 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
173 data = buffer_get_data(ctx->all_headers_buf, NULL); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
174 ctx->all_headers_ctx = |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
175 mailbox_header_lookup_init(ctx->box, data); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
176 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
177 |
5949
1a80f37a4a12
Added MAIL_FETCH_NUL_STATE. Don't try to fetch cached flags now unless it's
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
178 if ((ctx->fetch_data & |
1a80f37a4a12
Added MAIL_FETCH_NUL_STATE. Don't try to fetch cached flags now unless it's
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
179 (MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY)) != 0) |
1a80f37a4a12
Added MAIL_FETCH_NUL_STATE. Don't try to fetch cached flags now unless it's
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
180 ctx->fetch_data |= MAIL_FETCH_NUL_STATE; |
1a80f37a4a12
Added MAIL_FETCH_NUL_STATE. Don't try to fetch cached flags now unless it's
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
181 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
182 ctx->trans = mailbox_transaction_begin(ctx->box, |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
183 MAILBOX_TRANSACTION_FLAG_HIDE); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
184 ctx->select_counter = ctx->client->select_counter; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
185 ctx->mail = mail_alloc(ctx->trans, ctx->fetch_data, |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
186 ctx->all_headers_ctx); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
187 ctx->search_ctx = |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
188 mailbox_search_init(ctx->trans, NULL, search_arg, NULL); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
191 static int imap_fetch_flush_buffer(struct imap_fetch_context *ctx) |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
192 { |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
193 const unsigned char *data; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
194 size_t len; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
195 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
196 data = str_data(ctx->cur_str); |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
197 len = str_len(ctx->cur_str); |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
198 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
199 /* there's an extra space at the end if we added any fetch items |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
200 to buffer */ |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
201 if (data[len-1] == ' ') { |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
202 len--; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
203 ctx->first = FALSE; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
204 } |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
205 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
206 if (o_stream_send(ctx->client->output, data, len) < 0) |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
207 return -1; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
208 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
209 str_truncate(ctx->cur_str, 0); |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
210 return 0; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
211 } |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
212 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
213 static int imap_fetch_send_nil_reply(struct imap_fetch_context *ctx) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
214 { |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
215 const struct imap_fetch_context_handler *handler; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
216 |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
217 if (!ctx->first) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
218 str_append_c(ctx->cur_str, ' '); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
219 |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
220 handler = array_idx(&ctx->handlers, ctx->cur_handler); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
221 str_printfa(ctx->cur_str, "%s %s ", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
222 handler->name, handler->nil_reply); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
223 |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
224 if (!handler->buffered) { |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
225 if (imap_fetch_flush_buffer(ctx) < 0) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
226 return -1; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
227 } |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
228 return 0; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
229 } |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
230 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
231 int imap_fetch(struct imap_fetch_context *ctx) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
233 struct client *client = ctx->client; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
234 const struct imap_fetch_context_handler *handlers; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
235 unsigned int count; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
236 int ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
237 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
238 if (ctx->cont_handler != NULL) { |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
239 ret = ctx->cont_handler(ctx); |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
240 if (ret == 0) |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
241 return 0; |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
242 |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
243 if (ret < 0) { |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
244 if (ctx->client->output->closed) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
245 return -1; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
246 |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
247 if (ctx->cur_mail->expunged) { |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
248 /* not an error, just lost it. */ |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
249 ctx->partial_fetch = TRUE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
250 if (imap_fetch_send_nil_reply(ctx) < 0) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
251 return -1; |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
252 } else { |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
253 return -1; |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
254 } |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
255 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
256 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
257 ctx->cont_handler = NULL; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
258 ctx->cur_offset = 0; |
2483
b0fc9984ddcd
Same FETCH handler could have been executed infinitely if client didn't read
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
259 ctx->cur_handler++; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
260 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
261 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
262 /* assume initially that we're locking it */ |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
263 i_assert(client->output_lock == NULL || |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
264 client->output_lock == ctx->cmd); |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
265 client->output_lock = ctx->cmd; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
266 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
267 handlers = array_get(&ctx->handlers, &count); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
268 for (;;) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
269 if (o_stream_get_buffer_used_size(client->output) >= |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
270 CLIENT_OUTPUT_OPTIMAL_SIZE) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
271 ret = o_stream_flush(client->output); |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
272 if (ret <= 0) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
273 if (!ctx->line_partial) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
274 /* last line was fully sent */ |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
275 client->output_lock = NULL; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
276 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
277 return ret; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
278 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
279 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
280 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
281 if (ctx->cur_mail == NULL) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
282 if (ctx->cmd->cancel) |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
283 return 1; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
284 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
285 if (ctx->cur_input != NULL) |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
286 i_stream_unref(&ctx->cur_input); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
287 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
288 if (mailbox_search_next(ctx->search_ctx, |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
289 ctx->mail) <= 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
290 break; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
291 ctx->cur_mail = ctx->mail; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
293 str_printfa(ctx->cur_str, "* %u FETCH (", |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
294 ctx->cur_mail->seq); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
295 ctx->first = TRUE; |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
296 ctx->line_finished = FALSE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
297 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
298 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
299 for (; ctx->cur_handler < count; ctx->cur_handler++) { |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
300 if (str_len(ctx->cur_str) > 0 && |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
301 !handlers[ctx->cur_handler].buffered) { |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
302 /* first non-buffered handler. |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
303 flush the buffer. */ |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
304 ctx->line_partial = TRUE; |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
305 if (imap_fetch_flush_buffer(ctx) < 0) |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
306 return -1; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
307 } |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
308 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
309 t_push(); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
310 ret = handlers[ctx->cur_handler]. |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
311 handler(ctx, ctx->cur_mail, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
312 handlers[ctx->cur_handler].context); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
313 t_pop(); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
315 if (ret == 0) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
316 if (!ctx->line_partial) { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
317 /* last line was fully sent */ |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
318 client->output_lock = NULL; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
319 } |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
320 return 0; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
321 } |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
322 |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
323 if (ret < 0) { |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
324 if (ctx->cur_mail->expunged) { |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
325 /* not an error, just lost it. */ |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
326 ctx->partial_fetch = TRUE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
327 if (imap_fetch_send_nil_reply(ctx) < 0) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
328 return -1; |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
329 } else { |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
330 i_assert(ret < 0 || |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
331 ctx->cont_handler != NULL); |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
332 return -1; |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
333 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
334 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
335 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
336 ctx->cont_handler = NULL; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
337 ctx->cur_offset = 0; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
338 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
339 |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
340 if (str_len(ctx->cur_str) > 0) { |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
341 /* no non-buffered handlers */ |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
342 if (imap_fetch_flush_buffer(ctx) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
343 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
344 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
345 |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
346 ctx->line_finished = TRUE; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
347 ctx->line_partial = FALSE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
348 if (o_stream_send(client->output, ")\r\n", 3) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
349 return -1; |
5759
6074f59f91ba
We didn't update last_output timestamp with long fetches, causing Dovecot to
Timo Sirainen <tss@iki.fi>
parents:
4973
diff
changeset
|
350 ctx->client->last_output = ioloop_time; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
351 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
352 ctx->cur_mail = NULL; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
353 ctx->cur_handler = 0; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
354 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
355 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
356 return 1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
359 int imap_fetch_deinit(struct imap_fetch_context *ctx) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 { |
4073 | 361 const struct imap_fetch_context_handler *handlers; |
362 unsigned int i, count; | |
363 | |
364 handlers = array_get(&ctx->handlers, &count); | |
365 for (i = 0; i < count; i++) { | |
366 if (handlers[i].want_deinit) | |
367 handlers[i].handler(ctx, NULL, handlers[i].context); | |
368 } | |
369 | |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
370 if (!ctx->line_finished) { |
6257
2618805b3d94
If FETCH failed internally, we could have sent broken output (")" lines).
Timo Sirainen <tss@iki.fi>
parents:
5949
diff
changeset
|
371 if (imap_fetch_flush_buffer(ctx) < 0) |
6261 | 372 ctx->failed = TRUE; |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
373 if (o_stream_send(ctx->client->output, ")\r\n", 3) < 0) |
3108
38fa28004689
The actual fix for last commit..
Timo Sirainen <tss@iki.fi>
parents:
3100
diff
changeset
|
374 ctx->failed = TRUE; |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
375 } |
6257
2618805b3d94
If FETCH failed internally, we could have sent broken output (")" lines).
Timo Sirainen <tss@iki.fi>
parents:
5949
diff
changeset
|
376 str_free(&ctx->cur_str); |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
377 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
378 if (ctx->cur_input != NULL) |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
379 i_stream_unref(&ctx->cur_input); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
381 if (ctx->mail != NULL) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
382 mail_free(&ctx->mail); |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
383 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
384 if (ctx->search_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
|
385 if (mailbox_search_deinit(&ctx->search_ctx) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
386 ctx->failed = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
387 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
388 if (ctx->all_headers_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
|
389 mailbox_header_lookup_deinit(&ctx->all_headers_ctx); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
391 if (ctx->trans != NULL) { |
5760
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
392 /* even if something failed, we want to commit changes to |
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
393 cache, as well as possible \Seen flag changes for FETCH |
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
394 replies we returned so far. */ |
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
395 if (mailbox_transaction_commit(&ctx->trans, 0) < 0) |
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
396 ctx->failed = TRUE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
397 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
398 return ctx->failed ? -1 : 0; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
401 static int fetch_body(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
402 void *context ATTR_UNUSED) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
404 const char *body; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
406 if (mail_get_special(mail, MAIL_FETCH_IMAP_BODY, &body) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
407 return -1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
408 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
409 if (ctx->first) |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
410 ctx->first = FALSE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
411 else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
412 if (o_stream_send(ctx->client->output, " ", 1) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
413 return -1; |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
414 } |
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
415 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
416 if (o_stream_send(ctx->client->output, "BODY (", 6) < 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
417 o_stream_send_str(ctx->client->output, body) < 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
418 o_stream_send(ctx->client->output, ")", 1) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
419 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
420 return 1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
421 } |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
422 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3470
diff
changeset
|
423 static bool fetch_body_init(struct imap_fetch_context *ctx, const char *name, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
424 const struct imap_arg **args) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
425 { |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
426 if (name[4] == '\0') { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
427 ctx->fetch_data |= MAIL_FETCH_IMAP_BODY; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
428 imap_fetch_add_handler(ctx, FALSE, FALSE, name, |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
429 "("BODY_NIL_REPLY")", fetch_body, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
430 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
431 } |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
432 return fetch_body_section_init(ctx, name, args); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
435 static int fetch_bodystructure(struct imap_fetch_context *ctx, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
436 struct mail *mail, void *context ATTR_UNUSED) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 const char *bodystructure; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
440 if (mail_get_special(mail, MAIL_FETCH_IMAP_BODYSTRUCTURE, |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
441 &bodystructure) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
442 return -1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
444 if (ctx->first) |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
445 ctx->first = FALSE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
446 else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
447 if (o_stream_send(ctx->client->output, " ", 1) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
448 return -1; |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
449 } |
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
450 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
451 if (o_stream_send(ctx->client->output, "BODYSTRUCTURE (", 15) < 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
452 o_stream_send_str(ctx->client->output, bodystructure) < 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
453 o_stream_send(ctx->client->output, ")", 1) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
454 return -1; |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
455 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
456 return 1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
457 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
458 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
459 static bool |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
460 fetch_bodystructure_init(struct imap_fetch_context *ctx, const char *name, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
461 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
462 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
463 ctx->fetch_data |= MAIL_FETCH_IMAP_BODYSTRUCTURE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
464 imap_fetch_add_handler(ctx, FALSE, FALSE, name, |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
465 "("BODY_NIL_REPLY" NIL NIL NIL NIL)", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
466 fetch_bodystructure, NULL); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 return TRUE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
470 static int fetch_envelope(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
471 void *context ATTR_UNUSED) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 const char *envelope; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
475 if (mail_get_special(mail, MAIL_FETCH_IMAP_ENVELOPE, &envelope) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
476 return -1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
478 if (ctx->first) |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
479 ctx->first = FALSE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
480 else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
481 if (o_stream_send(ctx->client->output, " ", 1) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
482 return -1; |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
483 } |
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
484 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
485 if (o_stream_send(ctx->client->output, "ENVELOPE (", 10) < 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
486 o_stream_send_str(ctx->client->output, envelope) < 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
487 o_stream_send(ctx->client->output, ")", 1) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
488 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
489 return 1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
490 } |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
491 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
492 static bool |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
493 fetch_envelope_init(struct imap_fetch_context *ctx, const char *name, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
494 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
495 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
496 ctx->fetch_data |= MAIL_FETCH_IMAP_ENVELOPE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
497 imap_fetch_add_handler(ctx, FALSE, FALSE, name, |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
498 "(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
499 fetch_envelope, NULL); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 return TRUE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
503 static int fetch_flags(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
504 void *context ATTR_UNUSED) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2742
diff
changeset
|
506 enum mail_flags flags; |
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2742
diff
changeset
|
507 const char *const *keywords; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
508 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
509 flags = mail_get_flags(mail); |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3156
diff
changeset
|
510 keywords = mail_get_keywords(mail); |
1638
e95c0e462591
API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents:
1534
diff
changeset
|
511 |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2742
diff
changeset
|
512 if (ctx->flags_update_seen && (flags & MAIL_SEEN) == 0) { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
513 /* Add \Seen flag */ |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2742
diff
changeset
|
514 flags |= MAIL_SEEN; |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6261
diff
changeset
|
515 mail_update_flags(mail, MODIFY_ADD, MAIL_SEEN); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
516 } else if (ctx->flags_show_only_seen_changes) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
517 return 1; |
1638
e95c0e462591
API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents:
1534
diff
changeset
|
518 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
520 str_append(ctx->cur_str, "FLAGS ("); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2742
diff
changeset
|
521 imap_write_flags(ctx->cur_str, flags, keywords); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
522 str_append(ctx->cur_str, ") "); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
523 return 1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
524 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
526 static bool |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
527 fetch_flags_init(struct imap_fetch_context *ctx, const char *name, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
528 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
529 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
530 ctx->flags_have_handler = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
531 ctx->fetch_data |= MAIL_FETCH_FLAGS; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
532 imap_fetch_add_handler(ctx, TRUE, FALSE, name, "()", fetch_flags, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
533 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
534 } |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
535 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
536 static int fetch_internaldate(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
537 void *context ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
538 { |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
539 time_t date; |
1926
982bd89b42fd
BYE if trying to fetch body[] of expunged message.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
540 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
541 if (mail_get_received_date(mail, &date) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
542 return -1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
543 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
544 str_printfa(ctx->cur_str, "INTERNALDATE \"%s\" ", |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
545 imap_to_datetime(date)); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
546 return 1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
547 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
548 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
549 static bool |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
550 fetch_internaldate_init(struct imap_fetch_context *ctx, const char *name, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
551 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
552 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
553 ctx->fetch_data |= MAIL_FETCH_RECEIVED_DATE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
554 imap_fetch_add_handler(ctx, TRUE, FALSE, name, |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
555 "\"01-01-1970 00:00:00 +0000\"", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
556 fetch_internaldate, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
557 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
558 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
559 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
560 static int fetch_uid(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
561 void *context ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
562 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
563 str_printfa(ctx->cur_str, "UID %u ", mail->uid); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
564 return 1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
565 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
566 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
567 static bool |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
568 fetch_uid_init(struct imap_fetch_context *ctx ATTR_UNUSED, const char *name, |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
569 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
570 { |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
571 imap_fetch_add_handler(ctx, TRUE, FALSE, name, NULL, fetch_uid, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
572 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
573 } |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
574 |
4972
0103df03b5d4
Removed accidentally committed TEXTSIZE FETCH parameter.
Timo Sirainen <tss@iki.fi>
parents:
4939
diff
changeset
|
575 const struct imap_fetch_handler default_handlers[7] = { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
576 { "BODY", fetch_body_init }, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
577 { "BODYSTRUCTURE", fetch_bodystructure_init }, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
578 { "ENVELOPE", fetch_envelope_init }, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
579 { "FLAGS", fetch_flags_init }, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
580 { "INTERNALDATE", fetch_internaldate_init }, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
581 { "RFC822", fetch_rfc822_init }, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
582 { "UID", fetch_uid_init } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
583 }; |