annotate src/imap/imap-fetch.c @ 3209:923ff19873d4 HEAD

Major mail-storage API changes. It's now a bit cleaner and much more plugin friendly. Removed proxy_mailbox* stuff, they were difficult to use and there's now much easier way to replace them.
author Timo Sirainen <tss@iki.fi>
date Tue, 15 Mar 2005 21:01:50 +0200
parents 13dbff915a1a
children 8632ec8486c6
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"
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
4 #include "buffer.h"
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "istream.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "ostream.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "str.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "message-send.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "message-size.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "imap-date.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "commands.h"
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "imap-fetch.h"
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
13 #include "imap-util.h"
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
15 #include <stdlib.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 const struct imap_fetch_handler default_handlers[7];
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
18 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
19
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 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
21 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
22 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
23
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
24 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
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
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
27 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
28 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
29 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
30 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
31 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
32
2708
f1e9f3ec8135 Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents: 2680
diff changeset
33 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
34 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
35 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
36
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
37 data = buffer_get_modifyable_data(fetch_handlers, &size);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
38 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
39 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
40 }
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
41
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
42 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
43 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
44 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
45 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
46 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
47
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
48 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
49 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
50 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
51 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
52 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
53 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
54 }
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
55
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
56 return name[i] < '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
57 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
58
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
59 int imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name,
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
60 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
61 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
62 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
63
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
64 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
65 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
66 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
67 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
68 imap_fetch_handler_bsearch);
2497
5cab421f36be Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents: 2483
diff changeset
69 if (handler == NULL) {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
70 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
71 t_strconcat("Unknown command ", name, NULL));
2497
5cab421f36be Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents: 2483
diff changeset
72 return FALSE;
5cab421f36be Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents: 2483
diff changeset
73 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
74
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
75 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
76 }
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
77
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
78 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
79 {
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
80 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
81 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
82
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
83 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
84 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
85 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
86 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
87 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
88
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
89 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
90 ctx->client = client;
3141
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
91 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
92 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
93
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->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
95 ctx->all_headers_buf = buffer_create_dynamic(cmd->pool, 128);
61abed5f7864 Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents: 3108
diff changeset
96 ctx->handlers = buffer_create_dynamic(cmd->pool, 128);
2730
eef378c0c07d Don't send extra ")" line with bad FETCH parameters.
Timo Sirainen <tss@iki.fi>
parents: 2716
diff changeset
97 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
98 return ctx;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
101 void imap_fetch_add_handler(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
102 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
103 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
104 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
105 struct imap_fetch_context_handler h;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
106 size_t i, size;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
107
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
108 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
109 /* don't allow duplicate handlers */
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
110 handlers = buffer_get_data(ctx->handlers, &size);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
111 size /= 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
112
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
113 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
114 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
115 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
116 return;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
117 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
118 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
119
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 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
121 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
122 h.context = context;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
123
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
124 buffer_append(ctx->handlers, &h, 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
125 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
126
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
127 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
128 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
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 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
131 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
132
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
133 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
134 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
135 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
136 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
137 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
138 (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
139 }
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
140 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
142 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
143 ((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
144 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
145 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
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 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
148 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
149 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
150 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents: 1845
diff changeset
151
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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
161 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
162 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
163 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
164 size_t size;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
165 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
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 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
168 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
169 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
170 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
171
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
172 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
173 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
174 /* 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
175 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
176 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
177 } else {
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
178 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
179 }
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
180 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
181
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
182 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
183 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
184 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
185 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
186
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
187 handlers = buffer_get_data(ctx->handlers, &size);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
188 size /= 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
189
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
190 for (;;) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
191 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
192 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
193 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
194 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
195 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
196 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
197
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
198 if (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
199 if (ctx->cur_input != NULL) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
200 i_stream_unref(ctx->cur_input);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
201 ctx->cur_input = NULL;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
202 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
203
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
204 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
205 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
206 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
207 ctx->cur_mail = ctx->mail;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208
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 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
210 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
211 if (o_stream_send(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
212 str_data(ctx->cur_str),
2640
66cad846df36 cleanups
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
213 str_len(ctx->cur_str)) < 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
214 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
215
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
216 str_truncate(ctx->cur_str, 0);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
217 str_append_c(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
218 ctx->first = TRUE;
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
219 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
220 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
221
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
222 for (; ctx->cur_handler < size; 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
223 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
224 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
225 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
226 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
227 t_pop();
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228
3156
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
229 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
230 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
231
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
232 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
233 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
234 /* 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
235 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
236 } else {
13dbff915a1a If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents: 3141
diff changeset
237 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
238 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
239 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
240 }
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
241 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
242
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
243 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
244 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
245 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
246
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
247 if (str_len(ctx->cur_str) > 1) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
248 if (o_stream_send(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
249 str_data(ctx->cur_str) + ctx->first,
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
250 str_len(ctx->cur_str) - 1 -
2640
66cad846df36 cleanups
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
251 ctx->first) < 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
252 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
253 }
2742
192da9681e1b Don't insert extra space before "* n FETCH"
Timo Sirainen <tss@iki.fi>
parents: 2730
diff changeset
254 str_truncate(ctx->cur_str, 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
255
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
256 ctx->line_finished = TRUE;
2640
66cad846df36 cleanups
Timo Sirainen <tss@iki.fi>
parents: 2518
diff changeset
257 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
258 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
259
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
260 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
261 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
262 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
263
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
264 return 1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
267 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
268 {
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
269 str_free(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
270
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
271 if (!ctx->line_finished) {
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
272 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
273 ctx->failed = TRUE;
2680
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
274 }
48df7f95fa4a If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents: 2675
diff changeset
275
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
276 if (ctx->cur_input != NULL) {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
277 i_stream_unref(ctx->cur_input);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
278 ctx->cur_input = NULL;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
279 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280
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
281 if (ctx->mail != NULL)
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
282 mail_free(ctx->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
283
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
284 if (ctx->search_ctx != 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 if (mailbox_search_deinit(ctx->search_ctx) < 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 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
287 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
288 if (ctx->all_headers_ctx != NULL)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
289 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
290
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 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
292 if (ctx->failed)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
293 mailbox_transaction_rollback(ctx->trans);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
294 else {
2518
f8be7a5e273a Added sync flags parameter to mailbox_transaction_commit(), so EXPUNGE can
Timo Sirainen <tss@iki.fi>
parents: 2497
diff changeset
295 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
296 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
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 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
299 return ctx->failed ? -1 : 0;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
302 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
303 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305 const char *body;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306
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
307 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
308 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
309 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
311 if (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
312 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
313 else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
314 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
315 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
316 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
317
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
318 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
319 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
320 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
321 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
322 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
323 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
324
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
325 static int fetch_body_init(struct imap_fetch_context *ctx, const char *name,
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
326 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
327 {
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
328 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
329 ctx->fetch_data |= MAIL_FETCH_IMAP_BODY;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
330 imap_fetch_add_handler(ctx, fetch_body, NULL);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
331 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
332 }
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
333 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
334 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 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
337 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
338 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339 const char *bodystructure;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340
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
341 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
342 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
343 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
345 if (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
346 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
347 else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
348 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
349 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
350 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
351
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
352 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
353 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
354 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
355 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
356
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
357 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
358 }
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
359
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
360 static int fetch_bodystructure_init(struct imap_fetch_context *ctx,
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
361 const char *name __attr_unused__,
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
362 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
363 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
364 ctx->fetch_data |= MAIL_FETCH_IMAP_BODYSTRUCTURE;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
365 imap_fetch_add_handler(ctx, fetch_bodystructure, NULL);
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366 return TRUE;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
369 static int fetch_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
370 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 {
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 const char *envelope;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3156
diff changeset
374 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
375 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
376 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
378 if (ctx->first)
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
379 ctx->first = FALSE;
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
380 else {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
381 if (o_stream_send(ctx->client->output, " ", 1) < 0)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
382 return -1;
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
383 }
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
384
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
385 if (o_stream_send(ctx->client->output, "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
386 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
387 o_stream_send(ctx->client->output, ")", 1) < 0)
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
388 return -1;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
389 return 1;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
390 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
391
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 static int fetch_envelope_init(struct imap_fetch_context *ctx,
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
393 const char *name __attr_unused__,
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
394 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
395 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
396 ctx->fetch_data |= MAIL_FETCH_IMAP_ENVELOPE;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
397 imap_fetch_add_handler(ctx, fetch_envelope, NULL);
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
398 return TRUE;
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
401 static int fetch_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
402 void *context __attr_unused__)
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
403 {
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2742
diff changeset
404 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
405 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
406
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
407 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
408 keywords = mail_get_keywords(mail);
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
409
3016
61c8d205d887 Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents: 2742
diff changeset
410 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
411 /* 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
412 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
413 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
414 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
415 } 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
416 return 1;
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
417 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
418
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
419 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
420 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
421 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
422 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
423 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424
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 static int fetch_flags_init(struct imap_fetch_context *ctx,
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
426 const char *name __attr_unused__,
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
427 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
428 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
429 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
430 ctx->fetch_data |= MAIL_FETCH_FLAGS;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
431 imap_fetch_add_handler(ctx, fetch_flags, NULL);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
432 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
433 }
1764
fbb28b07c60f Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents: 1672
diff changeset
434
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
435 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
436 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
437 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
438 time_t time;
1926
982bd89b42fd BYE if trying to fetch body[] of expunged message.
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
439
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
440 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
441 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
442 return -1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
444 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
445 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
446 return 1;
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447 }
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448
1638
e95c0e462591 API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents: 1534
diff changeset
449
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
450 static int fetch_internaldate_init(struct imap_fetch_context *ctx,
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
451 const char *name __attr_unused__,
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
452 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
453 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
454 ctx->fetch_data |= MAIL_FETCH_RECEIVED_DATE;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
455 imap_fetch_add_handler(ctx, fetch_internaldate, NULL);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
456 return TRUE;
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
457 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458
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 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
460 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
461 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
462 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
463 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
464 }
988
8028c4dcf38f mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465
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 static int fetch_uid_init(struct imap_fetch_context *ctx __attr_unused__,
2675
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
467 const char *name __attr_unused__,
60d33cf81c8e BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents: 2640
diff changeset
468 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
469 {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
470 imap_fetch_add_handler(ctx, fetch_uid, NULL);
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
471 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
472 }
1672
8920600a8cfc Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents: 1642
diff changeset
473
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
474 const struct imap_fetch_handler default_handlers[7] = {
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
475 { "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
476 { "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
477 { "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
478 { "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
479 { "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
480 { "RFC822", fetch_rfc822_init },
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
481 { "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
482 };