annotate src/imap/imap-fetch.c @ 4939:ff2272c228cc HEAD

Dovecot is now able to execute multiple commands at the same time. Practically this means commands: FETCH, LIST, SEARCH and syncing output for all commands. For example it's possible that doing two FETCH commands at the same time makes their output mixed together. Non-blocking SEARCH is done by doing search for 20 mails at a time, and then checking if another command is pending. Also added X-CANCEL <tag> command to cancel running commands.
author Timo Sirainen <tss@iki.fi>
date Wed, 20 Dec 2006 21:23:43 +0200
parents 5b4c9b20eba0
children 0103df03b5d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
1 /* Copyright (C) 2002-2004 Timo Sirainen */
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"
4537
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
11 #include "message-parser.h"
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "imap-date.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include "commands.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "imap-fetch.h"
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
15 #include "imap-util.h"
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
17 #include <stdlib.h>
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
4537
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
19 const struct imap_fetch_handler default_handlers[8];
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
20 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
21
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 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
23 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
24 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
25
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
26 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
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
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
29 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
30 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
31 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
32 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
33 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
34
2708
f1e9f3ec8135 Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents: 2680
diff changeset
35 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
36 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
37 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
38
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4073
diff changeset
39 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
40 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
41 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
42 }
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
43
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
44 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
45 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
46 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
47 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
48 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
49
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
50 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
51 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
52 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
53 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
54 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
55 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
56 }
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
57
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
58 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
59 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
60
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
61 bool imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
62 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
63 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
64 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
65
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
66 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
67 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
68 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
69 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
70 imap_fetch_handler_bsearch);
2497
5cab421f36be Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents: 2483
diff changeset
71 if (handler == NULL) {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
72 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
73 t_strconcat("Unknown command ", name, NULL));
2497
5cab421f36be Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents: 2483
diff changeset
74 return FALSE;
5cab421f36be Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents: 2483
diff changeset
75 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
76
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
77 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
78 }
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
79
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
80 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
81 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
82 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
83 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
84
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
85 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
86 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
87 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
88 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
89 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
90
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
91 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
92 ctx->client = client;
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
93 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
94 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
95
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->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
97 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
98 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
99 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
100 return ctx;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102
4907
5b4c9b20eba0 Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
103 #undef imap_fetch_add_handler
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
104 void imap_fetch_add_handler(struct imap_fetch_context *ctx,
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
105 bool buffered, bool want_deinit,
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
106 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
107 {
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
108 /* 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
109 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
110 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
111 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
112 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
113
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
114 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
115 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
116 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
117 */
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
118 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
119 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
120 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
121
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
122 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
123 /* 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
124 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
125
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
126 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
127 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
128 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
129 return;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
130 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
131 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
132
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
133 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
134 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
135 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
136 h.buffered = buffered;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
137 h.want_deinit = want_deinit;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
138
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
139 if (!buffered)
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
140 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
141 else {
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
142 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
143 &h, 1);
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
144 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
145 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
146 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
147
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
148 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
149 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
150 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
151 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
152 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
153
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
154 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
155 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
156 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
157 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
158 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
159 (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
160 }
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
161 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
163 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
164 ((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
165 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
166 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
167
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
168 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
169 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
170 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
171 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
172
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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
182 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
183 {
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
184 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
185 size_t len;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
186
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
187 i_assert(ctx->first);
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
188
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
189 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
190 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
191
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
192 /* 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
193 to buffer */
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
194 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
195 len--;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
196 ctx->first = FALSE;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
197 }
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 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
200 return -1;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
201
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
202 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
203 return 0;
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
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
206 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
207 {
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
208 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
209 const struct imap_fetch_context_handler *handlers;
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
210 unsigned int 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
211 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
212
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
213 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
214 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
215 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
216 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
217
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
218 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
219 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
220 /* 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
221 ctx->partial_fetch = TRUE;
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
222 ctx->partial_fetch = TRUE;
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
223 } else {
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
224 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
225 }
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
226 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
227
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
228 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
229 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
230 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
231 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
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 /* 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
234 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
235 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
236 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
237
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
238 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
239 for (;;) {
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
240 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
241 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
242 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
243 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
244 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
245 /* 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
246 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
247 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
248 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
249 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
250 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
251
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
252 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
253 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
254 return 1;
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
255
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
256 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
257 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
258
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
259 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
260 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
261 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
262 ctx->cur_mail = ctx->mail;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
263
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
264 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
265 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
266 ctx->first = TRUE;
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
267 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
268 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
269
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
270 for (; ctx->cur_handler < size; 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
271 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
272 !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
273 /* 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
274 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
275 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
276 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
277 return -1;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
278 }
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
279
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
280 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
281 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
282 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
283 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
284 t_pop();
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285
4939
ff2272c228cc Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
286 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
287 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
288 /* 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
289 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
290 }
3156
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
291 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
292 }
3156
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
293
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
294 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
295 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
296 /* 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
297 ctx->partial_fetch = TRUE;
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
298 } else {
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
299 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
300 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
301 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
302 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
303 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
304
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
305 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
306 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
307 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
308
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
309 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
310 /* 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
311 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
312 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
313 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
314
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
315 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
316 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
317 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
318 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
319
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
320 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
321 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
322 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
323
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
324 return 1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
327 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
328 {
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
329 const struct imap_fetch_context_handler *handlers;
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
330 unsigned int i, count;
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
331
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
332 handlers = array_get(&ctx->handlers, &count);
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
333 for (i = 0; i < count; i++) {
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
334 if (handlers[i].want_deinit)
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
335 handlers[i].handler(ctx, NULL, handlers[i].context);
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
336 }
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
337
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
338 str_free(&ctx->cur_str);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
339
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
340 if (!ctx->line_finished) {
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
341 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
342 ctx->failed = TRUE;
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
343 }
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
344
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
345 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
346 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
347
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
348 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
349 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
350
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 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
352 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
353 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
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 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
356 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
357
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
358 if (ctx->trans != NULL) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
359 if (ctx->failed)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
360 mailbox_transaction_rollback(&ctx->trans);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
361 else {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
362 if (mailbox_transaction_commit(&ctx->trans, 0) < 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
363 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
364 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
365 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
366 return ctx->failed ? -1 : 0;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
369 static int fetch_body(struct imap_fetch_context *ctx, struct mail *mail,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
370 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 const char *body;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373
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
374 body = mail_get_special(mail, MAIL_FETCH_IMAP_BODY);
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375 if (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
376 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
378 if (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
379 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
380 else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
381 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
382 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
383 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
384
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
385 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
386 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
387 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
388 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
389 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
390 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
391
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
392 static bool fetch_body_init(struct imap_fetch_context *ctx, const char *name,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
393 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
394 {
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
395 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
396 ctx->fetch_data |= MAIL_FETCH_IMAP_BODY;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
397 imap_fetch_add_handler(ctx, FALSE, FALSE, 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
398 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
399 }
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
400 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
401 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
403 static int fetch_bodystructure(struct imap_fetch_context *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
404 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
405 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
406 const char *bodystructure;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407
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
408 bodystructure = mail_get_special(mail, MAIL_FETCH_IMAP_BODYSTRUCTURE);
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 if (bodystructure == 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
410 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411
2421
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 (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
413 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
414 else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
415 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
416 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
417 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
418
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
419 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
420 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
421 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
422 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
423
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
424 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
425 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
426
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
427 static bool fetch_bodystructure_init(struct imap_fetch_context *ctx,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
428 const char *name __attr_unused__,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
429 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
430 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
431 ctx->fetch_data |= MAIL_FETCH_IMAP_BODYSTRUCTURE;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
432 imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_bodystructure, NULL);
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 return TRUE;
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
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
436 static int fetch_envelope(struct imap_fetch_context *ctx, struct mail *mail,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
437 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439 const char *envelope;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440
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
441 envelope = mail_get_special(mail, MAIL_FETCH_IMAP_ENVELOPE);
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442 if (envelope == 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
443 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
445 if (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
446 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
447 else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
448 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
449 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
450 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
451
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
452 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
453 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
454 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
455 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
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 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
458
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
459 static bool fetch_envelope_init(struct imap_fetch_context *ctx,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
460 const char *name __attr_unused__,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
461 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_ENVELOPE;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
464 imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_envelope, NULL);
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 return TRUE;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
468 static int fetch_flags(struct imap_fetch_context *ctx, struct mail *mail,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
469 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470 {
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2742
diff changeset
471 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
472 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
473
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
474 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
475 keywords = mail_get_keywords(mail);
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
476
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2742
diff changeset
477 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
478 /* 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
479 flags |= MAIL_SEEN;
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
480 if (mail_update_flags(mail, MODIFY_ADD, 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
481 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
482 } 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
483 return 1;
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
484 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
486 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
487 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
488 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
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 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
491
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
492 static bool fetch_flags_init(struct imap_fetch_context *ctx,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
493 const char *name __attr_unused__,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
494 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->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
497 ctx->fetch_data |= MAIL_FETCH_FLAGS;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
498 imap_fetch_add_handler(ctx, TRUE, FALSE, 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
499 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
500 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
501
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
502 static int fetch_internaldate(struct imap_fetch_context *ctx, struct mail *mail,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
503 void *context __attr_unused__)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
504 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
505 time_t time;
1926
982bd89b42fd BYE if trying to fetch body[] of expunged message.
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
506
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
507 time = mail_get_received_date(mail);
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 if (time == (time_t)-1)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
509 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
510
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
511 str_printfa(ctx->cur_str, "INTERNALDATE \"%s\" ",
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
512 imap_to_datetime(time));
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
513 return 1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
514 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
515
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
516
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
517 static bool fetch_internaldate_init(struct imap_fetch_context *ctx,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
518 const char *name __attr_unused__,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
519 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
520 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
521 ctx->fetch_data |= MAIL_FETCH_RECEIVED_DATE;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
522 imap_fetch_add_handler(ctx, TRUE, FALSE, 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
523 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
524 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
525
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
526 static int fetch_uid(struct imap_fetch_context *ctx, struct mail *mail,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
527 void *context __attr_unused__)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
528 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
529 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
530 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
531 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
532
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
533 static bool fetch_uid_init(struct imap_fetch_context *ctx __attr_unused__,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
534 const char *name __attr_unused__,
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3470
diff changeset
535 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
536 {
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
537 imap_fetch_add_handler(ctx, TRUE, FALSE, 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
538 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
539 }
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
540
4537
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
541 static uoff_t textsize_count(const struct message_part *part)
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
542 {
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
543 uoff_t size = 0;
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
544
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
545 for (; part != NULL; part = part->next) {
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
546 if (part->flags & (MESSAGE_PART_FLAG_TEXT |
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
547 MESSAGE_PART_FLAG_MESSAGE_RFC822)) {
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
548 size += part->header_size.physical_size +
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
549 part->body_size.physical_size;
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
550 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
551 if (part->children != NULL)
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
552 size += textsize_count(part->children);
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
553 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
554 return size;
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
555 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
556
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
557 static int fetch_textsize(struct imap_fetch_context *ctx, struct mail *mail,
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
558 void *context __attr_unused__)
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
559 {
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
560 const struct message_part *part;
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
561
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
562 part = mail_get_parts(mail);
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
563 if (part == NULL)
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
564 return -1;
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
565
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
566 str_printfa(ctx->cur_str, "TEXTSIZE %"PRIuUOFF_T" ",
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
567 textsize_count(part));
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
568 return 1;
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
569 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
570
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
571 static bool fetch_textsize_init(struct imap_fetch_context *ctx __attr_unused__,
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
572 const char *name __attr_unused__,
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
573 struct imap_arg **args __attr_unused__)
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
574 {
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
575 imap_fetch_add_handler(ctx, TRUE, FALSE, fetch_textsize, NULL);
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
576 return TRUE;
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
577 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
578
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
579 const struct imap_fetch_handler default_handlers[8] = {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
580 { "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
581 { "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
582 { "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
583 { "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
584 { "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
585 { "RFC822", fetch_rfc822_init },
4537
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
586 { "TEXTSIZE", fetch_textsize_init },
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
587 { "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
588 };