Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/imap-fetch.c @ 7817:ffaf1ea49704 HEAD
QRESYNC: Send HIGHESTMODSEQ automatically in all tagged replies whenever it
seems useful.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 11 Jun 2008 15:44:35 +0300 |
parents | 2d62129a709b |
children | c1bbdc2b262e |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
7057
diff
changeset
|
1 /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */ |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "common.h" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3216
diff
changeset
|
4 #include "array.h" |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
5 #include "buffer.h" |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "istream.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "ostream.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "str.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "message-send.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "message-size.h" |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "imap-date.h" |
7629 | 12 #include "mail-search-build.h" |
988
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 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
19 #define BODY_NIL_REPLY \ |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
20 "\"text\" \"plain\" NIL NIL NIL \"7bit\" 0 0 NIL NIL NIL" |
6887 | 21 #define ENVELOPE_NIL_REPLY \ |
22 "(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)" | |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
23 |
7620 | 24 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
|
25 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
|
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 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
|
28 { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
29 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
|
30 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
31 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
|
32 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
33 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
34 void 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
|
35 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
|
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 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
|
38 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
|
39 |
2708
f1e9f3ec8135
Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents:
2680
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 |
4451
1a35d53c18fc
Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 } |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
48 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
49 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
|
50 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
61 } |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
62 |
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 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
|
64 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
65 |
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
|
66 bool imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
67 const struct imap_arg **args) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
68 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
69 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
|
70 |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 imap_fetch_handler_bsearch); |
2497
5cab421f36be
Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents:
2483
diff
changeset
|
76 if (handler == NULL) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
77 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
|
78 t_strconcat("Unknown command ", name, NULL)); |
2497
5cab421f36be
Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents:
2483
diff
changeset
|
79 return FALSE; |
5cab421f36be
Don't crash with unknown FETCH commands.
Timo Sirainen <tss@iki.fi>
parents:
2483
diff
changeset
|
80 } |
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 |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
82 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
|
83 } |
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
84 |
7629 | 85 struct imap_fetch_context * |
86 imap_fetch_init(struct client_command_context *cmd, struct mailbox *box) | |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
88 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
|
89 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
|
90 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
91 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
|
92 imap_fetch_handlers_register(default_handlers, |
6494
59490181469e
Use N_ELEMENTS() macro instead of doing sizeof()/sizeof([0]) ourself.
Timo Sirainen <tss@iki.fi>
parents:
6454
diff
changeset
|
93 N_ELEMENTS(default_handlers)); |
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 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
95 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
96 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
|
97 ctx->client = client; |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
3108
diff
changeset
|
98 ctx->cmd = cmd; |
7629 | 99 ctx->box = box; |
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 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
101 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
|
102 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
|
103 p_array_init(&ctx->handlers, cmd->pool, 16); |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
7021
diff
changeset
|
104 p_array_init(&ctx->tmp_keywords, cmd->pool, |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
7021
diff
changeset
|
105 client->keywords.announce_count + 8); |
2730
eef378c0c07d
Don't send extra ")" line with bad FETCH parameters.
Timo Sirainen <tss@iki.fi>
parents:
2716
diff
changeset
|
106 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
|
107 return ctx; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 |
7629 | 110 bool imap_fetch_add_unchanged_since(struct imap_fetch_context *ctx, |
111 uint64_t modseq) | |
112 { | |
113 struct mail_search_arg *search_arg; | |
114 | |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
115 search_arg = p_new(ctx->search_args->pool, struct mail_search_arg, 1); |
7629 | 116 search_arg->type = SEARCH_MODSEQ; |
117 search_arg->value.modseq = | |
118 p_new(ctx->cmd->pool, struct mail_search_modseq, 1); | |
119 search_arg->value.modseq->modseq = modseq; | |
120 | |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
121 search_arg->next = ctx->search_args->args->next; |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
122 ctx->search_args->args->next = search_arg; |
7629 | 123 |
124 return imap_fetch_init_handler(ctx, "MODSEQ", NULL); | |
125 } | |
126 | |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4906
diff
changeset
|
127 #undef imap_fetch_add_handler |
4073 | 128 void imap_fetch_add_handler(struct imap_fetch_context *ctx, |
129 bool buffered, bool want_deinit, | |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
130 const char *name, const char *nil_reply, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
131 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
|
132 { |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
133 /* 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 */ |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
143 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
|
144 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
|
145 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
|
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 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
|
148 /* 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
|
149 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
|
150 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 return; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
155 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
156 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
157 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 h.buffered = buffered; |
4073 | 162 h.want_deinit = want_deinit; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
163 h.name = p_strdup(ctx->cmd->pool, name); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
164 h.nil_reply = p_strdup(ctx->cmd->pool, nil_reply); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
165 |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
166 if (!buffered) |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
167 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
|
168 else { |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
169 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
|
170 &h, 1); |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
171 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
|
172 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
173 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
174 |
7629 | 175 static void |
176 expunges_drop_known(struct imap_fetch_context *ctx, struct mail *mail, | |
177 ARRAY_TYPE(seq_range) *expunges) | |
178 { | |
179 const uint32_t *seqs, *uids; | |
180 unsigned int i, count; | |
181 | |
182 seqs = array_get(ctx->qresync_sample_seqset, &count); | |
183 uids = array_idx(ctx->qresync_sample_uidset, 0); | |
184 i_assert(array_count(ctx->qresync_sample_uidset) == count); | |
185 i_assert(count > 0); | |
186 | |
187 /* FIXME: we could do removals from the middle as well */ | |
188 for (i = 0; i < count; i++) { | |
189 mail_set_seq(mail, seqs[i]); | |
190 if (uids[i] != mail->uid) | |
191 break; | |
192 } | |
193 if (i > 0) | |
194 seq_range_array_remove_range(expunges, 1, uids[i-1]); | |
195 } | |
196 | |
197 static int get_expunges_fallback(struct imap_fetch_context *ctx, | |
198 const ARRAY_TYPE(seq_range) *uids, | |
199 ARRAY_TYPE(seq_range) *expunges) | |
200 { | |
201 struct mailbox_transaction_context *trans; | |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
202 struct mail_search_args *search_args; |
7629 | 203 struct mail_search_context *search_ctx; |
204 struct mail *mail; | |
205 const struct seq_range *uid_range; | |
206 struct mailbox_status status; | |
207 unsigned int i, count; | |
208 uint32_t next_uid; | |
209 int ret = 0; | |
210 | |
211 uid_range = array_get(uids, &count); | |
212 i_assert(count > 0); | |
213 i = 0; | |
214 next_uid = uid_range[0].seq1; | |
215 | |
216 /* search UIDs in given range */ | |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
217 search_args = mail_search_build_init(); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
218 search_args->args = p_new(search_args->pool, struct mail_search_arg, 1); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
219 search_args->args->type = SEARCH_UIDSET; |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
220 i_array_init(&search_args->args->value.seqset, array_count(uids)); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
221 array_append_array(&search_args->args->value.seqset, uids); |
7629 | 222 |
223 trans = mailbox_transaction_begin(ctx->box, 0); | |
224 mail = mail_alloc(trans, 0, NULL); | |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
225 search_ctx = mailbox_search_init(trans, search_args, NULL); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
226 mail_search_args_unref(&search_args); |
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
227 |
7629 | 228 while (mailbox_search_next(search_ctx, mail) > 0) { |
229 if (mail->uid == next_uid) { | |
230 if (next_uid < uid_range[i].seq2) | |
231 next_uid++; | |
232 else if (++i < count) | |
233 next_uid = uid_range[++i].seq1; | |
234 else | |
235 break; | |
236 } else { | |
237 /* next_uid .. mail->uid-1 are expunged */ | |
238 i_assert(mail->uid > next_uid); | |
239 while (mail->uid > uid_range[i].seq2) { | |
240 seq_range_array_add_range(expunges, next_uid, | |
241 uid_range[i].seq2); | |
242 i++; | |
243 i_assert(i < count); | |
244 next_uid = uid_range[i].seq1; | |
245 } | |
246 if (next_uid != mail->uid) { | |
247 seq_range_array_add_range(expunges, next_uid, | |
248 mail->uid - 1); | |
249 } | |
250 if (uid_range[i].seq2 == mail->uid) | |
251 next_uid = uid_range[++i].seq1; | |
252 else | |
253 next_uid = mail->uid + 1; | |
254 } | |
255 } | |
256 if (i < count) { | |
257 i_assert(next_uid <= uid_range[i].seq2); | |
258 seq_range_array_add_range(expunges, next_uid, | |
259 uid_range[i].seq2); | |
260 i++; | |
261 } | |
262 for (; i < count; i++) { | |
263 seq_range_array_add_range(expunges, uid_range[i].seq1, | |
264 uid_range[i].seq2); | |
265 } | |
266 | |
267 mailbox_get_status(ctx->box, STATUS_UIDNEXT, &status); | |
268 seq_range_array_remove_range(expunges, status.uidnext, (uint32_t)-1); | |
269 | |
270 if (mailbox_search_deinit(&search_ctx) < 0) | |
271 ret = -1; | |
272 | |
7813 | 273 if (ret == 0 && array_is_created(ctx->qresync_sample_seqset)) |
7629 | 274 expunges_drop_known(ctx, mail, expunges); |
275 | |
276 mail_free(&mail); | |
277 (void)mailbox_transaction_commit(&trans); | |
278 return ret; | |
279 } | |
280 | |
281 static int | |
282 imap_fetch_send_vanished(struct imap_fetch_context *ctx) | |
283 { | |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
284 const struct mail_search_arg *uidarg = ctx->search_args->args; |
7629 | 285 const struct mail_search_arg *modseqarg = uidarg->next; |
286 const ARRAY_TYPE(seq_range) *uids = &uidarg->value.seqset; | |
287 uint64_t modseq = modseqarg->value.modseq->modseq; | |
288 ARRAY_TYPE(seq_range) expunges; | |
289 string_t *str; | |
290 int ret = 0; | |
291 | |
292 i_array_init(&expunges, array_count(uids)); | |
293 if (!mailbox_get_expunged_uids(ctx->box, modseq, uids, &expunges)) { | |
294 /* return all expunged UIDs */ | |
295 if (get_expunges_fallback(ctx, uids, &expunges) < 0) { | |
296 array_clear(&expunges); | |
297 ret = -1; | |
298 } | |
299 } | |
300 if (array_count(&expunges) > 0) { | |
301 str = str_new(default_pool, 128); | |
302 str_append(str, "* VANISHED (EARLIER) "); | |
303 imap_write_seq_range(str, &expunges); | |
304 str_append(str, "\r\n"); | |
305 o_stream_send(ctx->client->output, str_data(str), str_len(str)); | |
306 str_free(&str); | |
307 } | |
308 array_free(&expunges); | |
309 return ret; | |
310 } | |
311 | |
312 int imap_fetch_begin(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
|
313 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
314 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
|
315 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
|
316 |
7629 | 317 if (ctx->send_vanished) { |
318 if (imap_fetch_send_vanished(ctx) < 0) { | |
319 ctx->failed = TRUE; | |
320 return -1; | |
321 } | |
322 } | |
323 | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 (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
|
330 } |
1638
e95c0e462591
API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents:
1534
diff
changeset
|
331 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 |
2421
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 (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
|
334 ((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
|
335 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
|
336 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
|
337 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
338 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
|
339 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
|
340 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
|
341 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1845
diff
changeset
|
342 |
5949
1a80f37a4a12
Added MAIL_FETCH_NUL_STATE. Don't try to fetch cached flags now unless it's
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
343 if ((ctx->fetch_data & |
1a80f37a4a12
Added MAIL_FETCH_NUL_STATE. Don't try to fetch cached flags now unless it's
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
344 (MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY)) != 0) |
1a80f37a4a12
Added MAIL_FETCH_NUL_STATE. Don't try to fetch cached flags now unless it's
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
345 ctx->fetch_data |= MAIL_FETCH_NUL_STATE; |
1a80f37a4a12
Added MAIL_FETCH_NUL_STATE. Don't try to fetch cached flags now unless it's
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
346 |
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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 ctx->all_headers_ctx); |
7629 | 352 |
353 /* Delayed uidset -> seqset conversion. VANISHED needs the uidset. */ | |
7639
03146f02403f
Implemented SEARCHRES extension.
Timo Sirainen <tss@iki.fi>
parents:
7629
diff
changeset
|
354 mail_search_args_init(ctx->search_args, ctx->box, TRUE, |
03146f02403f
Implemented SEARCHRES extension.
Timo Sirainen <tss@iki.fi>
parents:
7629
diff
changeset
|
355 &ctx->cmd->client->search_saved_uidset); |
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 ctx->search_ctx = |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7639
diff
changeset
|
357 mailbox_search_init(ctx->trans, ctx->search_args, NULL); |
7629 | 358 return 0; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
361 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
|
362 { |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
363 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
|
364 size_t len; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
365 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
366 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
|
367 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
|
368 |
6698 | 369 if (len == 0) |
370 return 0; | |
371 | |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
372 /* 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
|
373 to buffer */ |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
374 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
|
375 len--; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
376 ctx->first = FALSE; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
377 } |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
378 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
379 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
|
380 return -1; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
381 |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
382 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
|
383 return 0; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
384 } |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
385 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
386 static int imap_fetch_send_nil_reply(struct imap_fetch_context *ctx) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
387 { |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
388 const struct imap_fetch_context_handler *handler; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
389 |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
390 if (!ctx->first) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
391 str_append_c(ctx->cur_str, ' '); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
392 |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
393 handler = array_idx(&ctx->handlers, ctx->cur_handler); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
394 str_printfa(ctx->cur_str, "%s %s ", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
395 handler->name, handler->nil_reply); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
396 |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
397 if (!handler->buffered) { |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
398 if (imap_fetch_flush_buffer(ctx) < 0) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
399 return -1; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
400 } |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
401 return 0; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
402 } |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
403 |
7629 | 404 static int imap_fetch_more_int(struct imap_fetch_context *ctx) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
406 struct client *client = ctx->client; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
407 const struct imap_fetch_context_handler *handlers; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
408 unsigned int count; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
409 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
|
410 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
411 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
|
412 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
|
413 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
|
414 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
|
415 |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
416 if (ret < 0) { |
7017
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
417 if (client->output->closed) |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
418 return -1; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
419 |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
420 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
|
421 /* 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
|
422 ctx->partial_fetch = TRUE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
423 if (imap_fetch_send_nil_reply(ctx) < 0) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
424 return -1; |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
425 } else { |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
426 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
|
427 } |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
428 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
429 |
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->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
|
431 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
|
432 ctx->cur_handler++; |
6979
1029b2ffad2d
Fixed memory leak when FETCH command used multiple streams.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
433 if (ctx->cur_input != NULL) |
1029b2ffad2d
Fixed memory leak when FETCH command used multiple streams.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
434 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
|
435 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
436 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
437 handlers = array_get(&ctx->handlers, &count); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
438 for (;;) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
439 if (o_stream_get_buffer_used_size(client->output) >= |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
440 CLIENT_OUTPUT_OPTIMAL_SIZE) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
441 ret = o_stream_flush(client->output); |
7017
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
442 if (ret <= 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
|
443 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
|
444 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
445 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
446 if (ctx->cur_mail == NULL) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
447 if (ctx->cmd->cancel) |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
448 return 1; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
449 |
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
|
450 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
|
451 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
|
452 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
|
453 ctx->cur_mail = ctx->mail; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
455 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
|
456 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
|
457 ctx->first = TRUE; |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
458 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
|
459 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
460 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
461 for (; ctx->cur_handler < count; ctx->cur_handler++) { |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
462 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
|
463 !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
|
464 /* 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
|
465 flush the buffer. */ |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
466 ctx->line_partial = TRUE; |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
467 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
|
468 return -1; |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
469 } |
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
470 |
7021 | 471 i_assert(ctx->cur_input == NULL); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
472 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6888
diff
changeset
|
473 const struct imap_fetch_context_handler *h = |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6888
diff
changeset
|
474 &handlers[ctx->cur_handler]; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6888
diff
changeset
|
475 |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6888
diff
changeset
|
476 ret = h->handler(ctx, ctx->cur_mail, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6888
diff
changeset
|
477 h->context); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
478 } T_END; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 |
7017
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
480 if (ret == 0) |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
481 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
|
482 |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
483 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
|
484 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
|
485 /* 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
|
486 ctx->partial_fetch = TRUE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
487 if (imap_fetch_send_nil_reply(ctx) < 0) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
488 return -1; |
3156
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
489 } else { |
13dbff915a1a
If UID FETCH notices in the middle of fetching that message is expunged,
Timo Sirainen <tss@iki.fi>
parents:
3141
diff
changeset
|
490 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
|
491 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
|
492 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
|
493 } |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
494 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
495 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
496 ctx->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
|
497 ctx->cur_offset = 0; |
6979
1029b2ffad2d
Fixed memory leak when FETCH command used multiple streams.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
498 if (ctx->cur_input != NULL) |
1029b2ffad2d
Fixed memory leak when FETCH command used multiple streams.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
499 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
|
500 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
501 |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
502 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
|
503 /* 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
|
504 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
|
505 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
|
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 |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
508 ctx->line_finished = TRUE; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
509 ctx->line_partial = FALSE; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
510 if (o_stream_send(client->output, ")\r\n", 3) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
511 return -1; |
7017
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
512 client->last_output = ioloop_time; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
513 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
514 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
|
515 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
|
516 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
517 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
518 return 1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
520 |
7629 | 521 int imap_fetch_more(struct imap_fetch_context *ctx) |
7017
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
522 { |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
523 int ret; |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
524 |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
525 i_assert(ctx->client->output_lock == NULL || |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
526 ctx->client->output_lock == ctx->cmd); |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
527 |
7629 | 528 ret = imap_fetch_more_int(ctx); |
529 if (ret < 0) | |
530 ctx->failed = TRUE; | |
7017
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
531 if (ctx->line_partial) { |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
532 /* nothing can be sent until FETCH is finished */ |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
533 ctx->client->output_lock = ctx->cmd; |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
534 } |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
535 return ret; |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
536 } |
80d3b8fcec09
When pipelining commands another command could have written output in the
Timo Sirainen <tss@iki.fi>
parents:
6979
diff
changeset
|
537 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
538 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
|
539 { |
4073 | 540 const struct imap_fetch_context_handler *handlers; |
541 unsigned int i, count; | |
542 | |
543 handlers = array_get(&ctx->handlers, &count); | |
544 for (i = 0; i < count; i++) { | |
545 if (handlers[i].want_deinit) | |
546 handlers[i].handler(ctx, NULL, handlers[i].context); | |
547 } | |
548 | |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
549 if (!ctx->line_finished) { |
6257
2618805b3d94
If FETCH failed internally, we could have sent broken output (")" lines).
Timo Sirainen <tss@iki.fi>
parents:
5949
diff
changeset
|
550 if (imap_fetch_flush_buffer(ctx) < 0) |
6261 | 551 ctx->failed = TRUE; |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
552 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
|
553 ctx->failed = TRUE; |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
554 } |
6257
2618805b3d94
If FETCH failed internally, we could have sent broken output (")" lines).
Timo Sirainen <tss@iki.fi>
parents:
5949
diff
changeset
|
555 str_free(&ctx->cur_str); |
2680
48df7f95fa4a
If fetching fails, finish sending the untagged FETCH reply correctly.
Timo Sirainen <tss@iki.fi>
parents:
2675
diff
changeset
|
556 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
557 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
|
558 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
|
559 |
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
|
560 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
|
561 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
|
562 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
567 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
|
568 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
|
569 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
570 if (ctx->trans != NULL) { |
5760
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
571 /* even if something failed, we want to commit changes to |
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
572 cache, as well as possible \Seen flag changes for FETCH |
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
573 replies we returned so far. */ |
6512
1a3604c8ee05
mailbox_transaction_commit*() doesn't sync the mailbox anymore, so it
Timo Sirainen <tss@iki.fi>
parents:
6494
diff
changeset
|
574 if (mailbox_transaction_commit(&ctx->trans) < 0) |
5760
7851879631ea
Always commit FETCH transaction to make sure cached data is committed.
Timo Sirainen <tss@iki.fi>
parents:
5759
diff
changeset
|
575 ctx->failed = TRUE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
576 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
577 return ctx->failed ? -1 : 0; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
578 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
579 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
580 static int fetch_body(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
581 void *context ATTR_UNUSED) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
582 { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
583 const char *body; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
584 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
585 if (mail_get_special(mail, MAIL_FETCH_IMAP_BODY, &body) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
586 return -1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
587 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
588 if (ctx->first) |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
589 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
|
590 else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
591 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
|
592 return -1; |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
593 } |
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
594 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
595 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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 } |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
601 |
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
|
602 static bool fetch_body_init(struct imap_fetch_context *ctx, const char *name, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
603 const struct imap_arg **args) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
604 { |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
605 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
|
606 ctx->fetch_data |= MAIL_FETCH_IMAP_BODY; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
607 imap_fetch_add_handler(ctx, FALSE, FALSE, name, |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
608 "("BODY_NIL_REPLY")", fetch_body, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
609 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
|
610 } |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2640
diff
changeset
|
611 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
|
612 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
613 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
614 static int fetch_bodystructure(struct imap_fetch_context *ctx, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
615 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
|
616 { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
617 const char *bodystructure; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
618 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
619 if (mail_get_special(mail, MAIL_FETCH_IMAP_BODYSTRUCTURE, |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
620 &bodystructure) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
621 return -1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
622 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
623 if (ctx->first) |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
624 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
|
625 else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
626 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
|
627 return -1; |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
628 } |
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
629 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
630 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
|
631 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
|
632 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
|
633 return -1; |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
634 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
635 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
|
636 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
637 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
638 static bool |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
639 fetch_bodystructure_init(struct imap_fetch_context *ctx, const char *name, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
640 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
641 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
642 ctx->fetch_data |= MAIL_FETCH_IMAP_BODYSTRUCTURE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
643 imap_fetch_add_handler(ctx, FALSE, FALSE, name, |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
644 "("BODY_NIL_REPLY" NIL NIL NIL NIL)", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
645 fetch_bodystructure, NULL); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
646 return TRUE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
647 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
648 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
649 static int fetch_envelope(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
650 void *context ATTR_UNUSED) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
651 { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
652 const char *envelope; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
653 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
654 if (mail_get_special(mail, MAIL_FETCH_IMAP_ENVELOPE, &envelope) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
655 return -1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
656 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
657 if (ctx->first) |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
658 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
|
659 else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
660 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
|
661 return -1; |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
662 } |
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
663 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
664 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
|
665 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
|
666 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
|
667 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
|
668 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
|
669 } |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
670 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
671 static bool |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
672 fetch_envelope_init(struct imap_fetch_context *ctx, const char *name, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
673 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
674 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
675 ctx->fetch_data |= MAIL_FETCH_IMAP_ENVELOPE; |
6887 | 676 imap_fetch_add_handler(ctx, FALSE, FALSE, name, ENVELOPE_NIL_REPLY, |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
677 fetch_envelope, NULL); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
678 return TRUE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
679 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
680 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
681 static int fetch_flags(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
682 void *context ATTR_UNUSED) |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
683 { |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2742
diff
changeset
|
684 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
|
685 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
|
686 |
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
|
687 flags = mail_get_flags(mail); |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2742
diff
changeset
|
688 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
|
689 /* Add \Seen flag */ |
6454
b5e6543b4385
Make sure we do a mailbox sync after flag updates (STORE, FETCH). Also added
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
690 ctx->seen_flags_changed = TRUE; |
3016
61c8d205d887
Initial support for keywords. Syncing to mbox/maildir doesn't work yet.
Timo Sirainen <tss@iki.fi>
parents:
2742
diff
changeset
|
691 flags |= MAIL_SEEN; |
6277
5f66277bbe40
mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents:
6261
diff
changeset
|
692 mail_update_flags(mail, MODIFY_ADD, MAIL_SEEN); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
693 } 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
|
694 return 1; |
1638
e95c0e462591
API change for updating message flags.
Timo Sirainen <tss@iki.fi>
parents:
1534
diff
changeset
|
695 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
696 |
7057
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
7021
diff
changeset
|
697 keywords = client_get_keyword_names(ctx->client, &ctx->tmp_keywords, |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
7021
diff
changeset
|
698 mail_get_keyword_indexes(mail)); |
81f4c9689c18
FLAGS/PERMENENTFLAGS weren't always sent to client early enough. Also
Timo Sirainen <tss@iki.fi>
parents:
7021
diff
changeset
|
699 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
700 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
|
701 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
|
702 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
|
703 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
|
704 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
705 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
706 static bool |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
707 fetch_flags_init(struct imap_fetch_context *ctx, const char *name, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
708 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
709 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
710 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
|
711 ctx->fetch_data |= MAIL_FETCH_FLAGS; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
712 imap_fetch_add_handler(ctx, TRUE, FALSE, name, "()", fetch_flags, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
713 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
|
714 } |
1764
fbb28b07c60f
Write envelope, body and bodystructure directly into output stream.
Timo Sirainen <tss@iki.fi>
parents:
1672
diff
changeset
|
715 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
716 static int fetch_internaldate(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
717 void *context ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
718 { |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
719 time_t date; |
1926
982bd89b42fd
BYE if trying to fetch body[] of expunged message.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
720 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
721 if (mail_get_received_date(mail, &date) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
722 return -1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
723 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
724 str_printfa(ctx->cur_str, "INTERNALDATE \"%s\" ", |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6277
diff
changeset
|
725 imap_to_datetime(date)); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
726 return 1; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
727 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
728 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
729 static bool |
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
730 fetch_internaldate_init(struct imap_fetch_context *ctx, const char *name, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
731 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
732 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
733 ctx->fetch_data |= MAIL_FETCH_RECEIVED_DATE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
734 imap_fetch_add_handler(ctx, TRUE, FALSE, name, |
6888
51bf40995f0f
When client tried to fetch INTERNALDATE for an expunged message, we sent a
Timo Sirainen <tss@iki.fi>
parents:
6887
diff
changeset
|
735 "\"01-Jan-1970 00:00:00 +0000\"", |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
736 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
|
737 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
|
738 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
739 |
7620 | 740 static int fetch_modseq(struct imap_fetch_context *ctx, struct mail *mail, |
741 void *context ATTR_UNUSED) | |
742 { | |
7817
ffaf1ea49704
QRESYNC: Send HIGHESTMODSEQ automatically in all tagged replies whenever it
Timo Sirainen <tss@iki.fi>
parents:
7815
diff
changeset
|
743 uint64_t modseq; |
ffaf1ea49704
QRESYNC: Send HIGHESTMODSEQ automatically in all tagged replies whenever it
Timo Sirainen <tss@iki.fi>
parents:
7815
diff
changeset
|
744 |
ffaf1ea49704
QRESYNC: Send HIGHESTMODSEQ automatically in all tagged replies whenever it
Timo Sirainen <tss@iki.fi>
parents:
7815
diff
changeset
|
745 modseq = mail_get_modseq(mail); |
ffaf1ea49704
QRESYNC: Send HIGHESTMODSEQ automatically in all tagged replies whenever it
Timo Sirainen <tss@iki.fi>
parents:
7815
diff
changeset
|
746 if (ctx->client->highest_fetch_modseq < modseq) |
ffaf1ea49704
QRESYNC: Send HIGHESTMODSEQ automatically in all tagged replies whenever it
Timo Sirainen <tss@iki.fi>
parents:
7815
diff
changeset
|
747 ctx->client->highest_fetch_modseq = modseq; |
7620 | 748 str_printfa(ctx->cur_str, "MODSEQ %llu ", |
7817
ffaf1ea49704
QRESYNC: Send HIGHESTMODSEQ automatically in all tagged replies whenever it
Timo Sirainen <tss@iki.fi>
parents:
7815
diff
changeset
|
749 (unsigned long long)modseq); |
7620 | 750 return 1; |
751 } | |
752 | |
753 static bool | |
754 fetch_modseq_init(struct imap_fetch_context *ctx, const char *name, | |
755 const struct imap_arg **args ATTR_UNUSED) | |
756 { | |
757 client_enable(ctx->client, MAILBOX_FEATURE_CONDSTORE); | |
758 imap_fetch_add_handler(ctx, TRUE, FALSE, name, NULL, | |
759 fetch_modseq, NULL); | |
760 return TRUE; | |
761 } | |
762 | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
763 static int fetch_uid(struct imap_fetch_context *ctx, struct mail *mail, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
764 void *context ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
765 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
766 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
|
767 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
|
768 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
769 |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5760
diff
changeset
|
770 static bool |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
771 fetch_uid_init(struct imap_fetch_context *ctx ATTR_UNUSED, const char *name, |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6280
diff
changeset
|
772 const struct imap_arg **args ATTR_UNUSED) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
773 { |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4972
diff
changeset
|
774 imap_fetch_add_handler(ctx, TRUE, FALSE, name, NULL, fetch_uid, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
775 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
|
776 } |
1672
8920600a8cfc
Index cache file rewrite. It's not finished yet and mbox support is
Timo Sirainen <tss@iki.fi>
parents:
1642
diff
changeset
|
777 |
7620 | 778 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
|
779 { "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
|
780 { "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
|
781 { "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
|
782 { "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
|
783 { "INTERNALDATE", fetch_internaldate_init }, |
7620 | 784 { "MODSEQ", fetch_modseq_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
|
785 { "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
|
786 { "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
|
787 }; |