annotate src/imap/imap-fetch.c @ 4596:bf4e98a0de3f HEAD

Replaced ARRAY_CREATE() macro with [ipt]_array_init() macros. The macro has no side effects so it might as well be lowercased.
author Timo Sirainen <tss@iki.fi>
date Sun, 10 Sep 2006 15:48:12 +0300
parents e92ae6d532f9
children 204d7edc7cdc
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
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
103 void imap_fetch_add_handler(struct imap_fetch_context *ctx,
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
104 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
105 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
106 {
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
107 /* 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
108 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
109 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
110 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
111 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
112
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
113 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
114 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
115 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
116 */
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
117 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
118 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
119 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
120
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
121 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
122 /* 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
123 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
124
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
125 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
126 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
127 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
128 return;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
129 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
130 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
131
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
132 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
133 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
134 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
135 h.buffered = buffered;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
136 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
137
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
138 if (!buffered)
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
139 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
140 else {
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
141 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
142 &h, 1);
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
143 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
144 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
145 }
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 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
148 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
149 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
150 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
151 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
152
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
153 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
154 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
155 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
156 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
157 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
158 (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
159 }
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
160 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
162 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
163 ((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
164 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
165 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
166
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
167 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
168 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
169 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
170 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
171
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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
181 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
182 {
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
183 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
184 size_t len;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
185
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
186 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
187
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
188 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
189 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
190
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
191 /* 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
192 to buffer */
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
193 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
194 len--;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
195 ctx->first = FALSE;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
196 }
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 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
199 return -1;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
200
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
201 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
202 return 0;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
203 }
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
204
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
205 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
206 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
207 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
208 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
209 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
210
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
211 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
212 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
213 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
214 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
215
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
216 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
217 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
218 /* 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
219 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
220 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
221 } else {
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
222 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
223 }
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
224 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
225
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
226 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
227 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
228 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
229 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
230
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
231 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
232 for (;;) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
233 if (o_stream_get_buffer_used_size(ctx->client->output) >=
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
234 CLIENT_OUTPUT_OPTIMAL_SIZE) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
235 ret = o_stream_flush(ctx->client->output);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
236 if (ret <= 0)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
237 return ret;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
238 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
239
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
240 if (ctx->cur_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
241 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
242 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
243
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
244 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
245 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
246 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
247 ctx->cur_mail = ctx->mail;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
249 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
250 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
251 ctx->first = TRUE;
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
252 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
253 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
254
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
255 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
256 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
257 !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
258 /* 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
259 flush the buffer. */
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
260 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
261 return -1;
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
262 }
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
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 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
265 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
266 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
267 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
268 t_pop();
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269
3156
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
270 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
271 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
272
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
273 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
274 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
275 /* 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
276 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
277 } else {
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
278 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
279 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
280 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
281 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
282 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
283
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
284 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
285 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
286 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
287
3216
8632ec8486c6 Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents: 3209
diff changeset
288 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
289 /* 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
290 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
291 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
292 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
293
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
294 ctx->line_finished = TRUE;
2640
66cad846df36 cleanups
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
295 if (o_stream_send(ctx->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
296 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
297
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
298 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
299 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
300 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
301
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
302 return 1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
305 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
306 {
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
307 const struct imap_fetch_context_handler *handlers;
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
308 unsigned int i, count;
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
309
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
310 handlers = array_get(&ctx->handlers, &count);
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
311 for (i = 0; i < count; i++) {
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
312 if (handlers[i].want_deinit)
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
313 handlers[i].handler(ctx, NULL, handlers[i].context);
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
314 }
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
315
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
316 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
317
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
318 if (!ctx->line_finished) {
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
319 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
320 ctx->failed = TRUE;
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
321 }
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
322
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
323 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
324 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
325
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
326 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
327 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
328
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
329 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
330 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
331 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
332 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
333 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
334 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
335
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
336 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
337 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
338 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
339 else {
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
340 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
341 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
342 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
343 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
344 return ctx->failed ? -1 : 0;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
347 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
348 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 const char *body;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351
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
352 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
353 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
354 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
355
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
356 if (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
357 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
358 else {
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 (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
360 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
361 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
362
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 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
364 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
365 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
366 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
367 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
368 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
369
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
370 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
371 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
372 {
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
373 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
374 ctx->fetch_data |= MAIL_FETCH_IMAP_BODY;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
375 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
376 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
377 }
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
378 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
379 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381 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
382 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
383 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
384 const char *bodystructure;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
385
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
386 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
387 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
388 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
390 if (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
391 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
392 else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
393 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
394 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
395 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
396
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
397 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
398 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
399 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
400 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
401
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
402 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
403 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
404
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
405 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
406 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
407 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
408 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
409 ctx->fetch_data |= MAIL_FETCH_IMAP_BODYSTRUCTURE;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
410 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
411 return TRUE;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413
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 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
415 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417 const char *envelope;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
418
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
419 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
420 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
421 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
422
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
423 if (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
424 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
425 else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
426 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
427 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
428 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
429
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 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
431 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
432 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
433 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
434 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
435 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
436
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
437 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
438 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
439 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
440 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
441 ctx->fetch_data |= MAIL_FETCH_IMAP_ENVELOPE;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
442 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
443 return TRUE;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
446 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
447 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448 {
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2742
diff changeset
449 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
450 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
451
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
452 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
453 keywords = mail_get_keywords(mail);
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
454
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2742
diff changeset
455 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
456 /* 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
457 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
458 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
459 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
460 } 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
461 return 1;
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
462 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
463
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
464 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
465 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
466 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
467 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
468 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469
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
470 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
471 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
472 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
473 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
474 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
475 ctx->fetch_data |= MAIL_FETCH_FLAGS;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
476 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
477 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
478 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
479
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
480 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
481 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
482 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
483 time_t time;
1926
982bd89b42fd BYE if trying to fetch body[] of expunged message.
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
484
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
485 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
486 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
487 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
488
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
489 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
490 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
491 return 1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
492 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
493
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
494
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
495 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
496 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
497 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
498 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
499 ctx->fetch_data |= MAIL_FETCH_RECEIVED_DATE;
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
500 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
501 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
502 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
504 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
505 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
506 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
507 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
508 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
509 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
510
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
511 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
512 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
513 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
514 {
4073
cd701884900c Memory leak fixes
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
515 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
516 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
517 }
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
518
4537
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
519 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
520 {
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
521 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
522
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
523 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
524 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
525 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
526 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
527 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
528 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
529 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
530 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
531 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
532 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
533 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
534
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
535 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
536 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
537 {
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
538 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
539
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
540 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
541 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
542 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
543
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
544 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
545 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
546 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
547 }
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
548
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
549 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
550 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
551 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
552 {
555c27e58cb1 When mailbox changes are noticed and they're sent to client, cork before
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
553 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
554 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
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 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
558 { "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
559 { "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
560 { "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
561 { "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
562 { "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
563 { "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
564 { "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
565 { "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
566 };