Mercurial > dovecot > core-2.2
annotate src/imap/imap-fetch-body.c @ 6280:eb7c9d8ece54 HEAD
mail_*() APIs changed to return int and return the actual data as pointer.
Changed some code to do error handling a bit better.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 12 Aug 2007 19:40:54 +0300 |
parents | 6c0bfc35af03 |
children | 6a64e64fa3a3 |
rev | line source |
---|---|
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2002-2004 Timo Sirainen */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "common.h" |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "buffer.h" |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "str.h" |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
6 #include "strescape.h" |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "istream.h" |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "ostream.h" |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "istream-header-filter.h" |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "message-parser.h" |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "message-send.h" |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "mail-storage.h" |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
13 #include "imap-parser.h" |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "imap-fetch.h" |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include <stdlib.h> |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #include <ctype.h> |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #include <unistd.h> |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 struct imap_fetch_body_data { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 struct imap_fetch_body_data *next; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 struct mailbox_header_lookup_ctx *header_ctx; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 const char *section; /* NOTE: always uppercased */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 uoff_t skip, max_size; /* if you don't want max_size, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 set it to (uoff_t)-1 */ |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
27 |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
28 const char *const *fields; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
29 size_t fields_count; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
30 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 unsigned int skip_set:1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 unsigned int peek:1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 struct partial_cache { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 unsigned int select_counter; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 unsigned int uid; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 uoff_t physical_start; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
40 bool cr_skipped; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 struct message_size pos; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 static struct partial_cache partial = { 0, 0, 0, 0, { 0, 0, 0 } }; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
46 static bool seek_partial(unsigned int select_counter, unsigned int uid, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
47 struct partial_cache *partial, struct istream *stream, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
48 uoff_t virtual_skip) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 { |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
50 bool cr_skipped; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 if (select_counter == partial->select_counter && uid == partial->uid && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 stream->v_offset == partial->physical_start && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 virtual_skip >= partial->pos.virtual_size) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 /* we can use the cache */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 virtual_skip -= partial->pos.virtual_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 partial->select_counter = select_counter; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 partial->uid = uid; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 partial->physical_start = stream->v_offset; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 partial->cr_skipped = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 memset(&partial->pos, 0, sizeof(partial->pos)); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 i_stream_seek(stream, partial->physical_start + |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 partial->pos.physical_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 message_skip_virtual(stream, virtual_skip, &partial->pos, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 partial->cr_skipped, &cr_skipped); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 partial->cr_skipped = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 return cr_skipped; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 static uoff_t get_send_size(const struct imap_fetch_body_data *body, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 uoff_t max_size) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 uoff_t size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 if (body->skip >= max_size) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 return 0; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 size = max_size - body->skip; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 return size <= body->max_size ? size : body->max_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
86 static const char *get_body_name(const struct imap_fetch_body_data *body) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
87 { |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
88 string_t *str; |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
89 |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
90 str = t_str_new(128); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
91 str_printfa(str, "BODY[%s]", body->section); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
92 if (body->skip_set) |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
93 str_printfa(str, "<%"PRIuUOFF_T">", body->skip); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
94 return str_c(str); |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
95 } |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
96 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 static string_t *get_prefix(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:
diff
changeset
|
98 const struct imap_fetch_body_data *body, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 uoff_t size) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 string_t *str; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 str = t_str_new(128); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 if (ctx->first) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 ctx->first = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 else |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 str_append_c(str, ' '); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
109 str_append(str, get_body_name(body)); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 if (size != (uoff_t)-1) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 str_printfa(str, " {%"PRIuUOFF_T"}\r\n", size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 else |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 str_append(str, " NIL"); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 return str; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 |
5079
e3e8f01b4899
If we disconnect the client because message ended unexpectedly, log an
Timo Sirainen <tss@iki.fi>
parents:
4973
diff
changeset
|
118 static off_t imap_fetch_send(struct imap_fetch_context *ctx, |
e3e8f01b4899
If we disconnect the client because message ended unexpectedly, log an
Timo Sirainen <tss@iki.fi>
parents:
4973
diff
changeset
|
119 struct ostream *output, struct istream *input, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
120 bool cr_skipped, uoff_t virtual_size, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
121 bool add_missing_eoh, bool *last_cr) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 const unsigned char *msg; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 size_t i, size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 uoff_t vsize_left, sent; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 off_t ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 unsigned char add; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
128 bool blocks = FALSE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 /* go through the message data and insert CRs where needed. */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 sent = 0; vsize_left = virtual_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 while (vsize_left > 0 && !blocks && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 i_stream_read_data(input, &msg, &size, 0) > 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 add = '\0'; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 for (i = 0; i < size && vsize_left > 0; i++) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 vsize_left--; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 if (msg[i] == '\n') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 if ((i > 0 && msg[i-1] != '\r') || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 (i == 0 && !cr_skipped)) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 /* missing CR */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 add = '\r'; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 } else if (msg[i] == '\0') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 add = 128; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 if ((ret = o_stream_send(output, msg, i)) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 return -1; |
2646
64e22d5c2829
signed vs. unsigned warning fix
Timo Sirainen <tss@iki.fi>
parents:
2638
diff
changeset
|
153 if ((uoff_t)ret < i) { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 add = '\0'; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 blocks = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 } |
2485 | 157 |
158 if (ret > 0) | |
159 cr_skipped = msg[ret-1] == '\r'; | |
160 | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 i_stream_skip(input, ret); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 sent += ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 if (add != '\0') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 if ((ret = o_stream_send(output, &add, 1)) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 if (ret == 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 blocks = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 sent++; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 cr_skipped = add == '\r'; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 if (add == 128) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 i_stream_skip(input, 1); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 |
2448 | 178 if (add_missing_eoh && sent + 2 == virtual_size) { |
179 /* Netscape missing EOH workaround. */ | |
180 o_stream_set_max_buffer_size(output, (size_t)-1); | |
181 if (o_stream_send(output, "\r\n", 2) < 0) | |
182 return -1; | |
183 sent += 2; | |
184 } | |
185 | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 if ((uoff_t)sent != virtual_size && !blocks) { |
3336
a3a72d5bdfce
o_stream_uncork() was previously always setting IO_WRITE handler even if
Timo Sirainen <tss@iki.fi>
parents:
3299
diff
changeset
|
187 /* Input stream gave less data than we expected. Two choices |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 here: either we fill the missing data with spaces or we |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 disconnect the client. |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 We shouldn't really ever get here. One reason is if mail |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 was deleted from NFS server while we were reading it. |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 Another is some temporary disk error. |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 If we filled the missing data the client could cache it, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 and if it was just a temporary error the message would be |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 permanently left corrupted in client's local cache. So, we |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 disconnect the client and hope that next try works. */ |
5079
e3e8f01b4899
If we disconnect the client because message ended unexpectedly, log an
Timo Sirainen <tss@iki.fi>
parents:
4973
diff
changeset
|
199 i_error("FETCH for mailbox %s UID %u got too little data: " |
e3e8f01b4899
If we disconnect the client because message ended unexpectedly, log an
Timo Sirainen <tss@iki.fi>
parents:
4973
diff
changeset
|
200 "%"PRIuUOFF_T" vs %"PRIuUOFF_T, |
e3e8f01b4899
If we disconnect the client because message ended unexpectedly, log an
Timo Sirainen <tss@iki.fi>
parents:
4973
diff
changeset
|
201 mailbox_get_name(ctx->mail->box), ctx->mail->uid, |
e3e8f01b4899
If we disconnect the client because message ended unexpectedly, log an
Timo Sirainen <tss@iki.fi>
parents:
4973
diff
changeset
|
202 (uoff_t)sent, virtual_size); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 o_stream_close(output); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 *last_cr = cr_skipped; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 return sent; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 static int fetch_stream_send(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:
diff
changeset
|
212 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 off_t ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 |
2638
f7bad0650b25
Allow buffering of output stream when sending message body, to avoid tons of
Timo Sirainen <tss@iki.fi>
parents:
2635
diff
changeset
|
215 o_stream_set_max_buffer_size(ctx->client->output, 4096); |
5079
e3e8f01b4899
If we disconnect the client because message ended unexpectedly, log an
Timo Sirainen <tss@iki.fi>
parents:
4973
diff
changeset
|
216 ret = imap_fetch_send(ctx, ctx->client->output, ctx->cur_input, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 ctx->skip_cr, ctx->cur_size - ctx->cur_offset, |
2448 | 218 ctx->cur_append_eoh, &ctx->skip_cr); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 o_stream_set_max_buffer_size(ctx->client->output, (size_t)-1); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 if (ret < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 ctx->cur_offset += ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 if (ctx->update_partial) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 partial.cr_skipped = ctx->skip_cr != 0; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 partial.pos.physical_size = |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 ctx->cur_input->v_offset - partial.physical_start; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 partial.pos.virtual_size += ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 return ctx->cur_offset == ctx->cur_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 static int fetch_stream_send_direct(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:
diff
changeset
|
236 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 off_t ret; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 o_stream_set_max_buffer_size(ctx->client->output, 0); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 ret = o_stream_send_istream(ctx->client->output, ctx->cur_input); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 o_stream_set_max_buffer_size(ctx->client->output, (size_t)-1); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 if (ret < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 ctx->cur_offset += ret; |
2448 | 247 |
248 if (ctx->cur_append_eoh && ctx->cur_offset + 2 == ctx->cur_size) { | |
249 /* Netscape missing EOH workaround. */ | |
250 if (o_stream_send(ctx->client->output, "\r\n", 2) < 0) | |
251 return -1; | |
252 ctx->cur_offset += 2; | |
253 ctx->cur_append_eoh = FALSE; | |
254 } | |
255 | |
5276
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
256 if (ctx->cur_offset != ctx->cur_size) { |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
257 /* unfinished */ |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
258 if (!i_stream_have_bytes_left(ctx->cur_input)) { |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
259 /* Input stream gave less data than expected */ |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
260 i_error("FETCH for mailbox %s UID %u " |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
261 "got too little data: " |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
262 "%"PRIuUOFF_T" vs %"PRIuUOFF_T, |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
263 mailbox_get_name(ctx->mail->box), |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
264 ctx->mail->uid, ctx->cur_offset, ctx->cur_size); |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
265 o_stream_close(ctx->client->output); |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
266 return -1; |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
267 } |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
268 |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
269 o_stream_set_flush_pending(ctx->client->output, TRUE); |
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
270 return 0; |
2635
e69519ea4682
Make sure we disconnect if mail input is finished unexpectedly.
Timo Sirainen <tss@iki.fi>
parents:
2557
diff
changeset
|
271 } |
5276
56535cb50a09
If mail was in CR+LF format in the disk and we used sendfile() call, but the
Timo Sirainen <tss@iki.fi>
parents:
5079
diff
changeset
|
272 return 1; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 static int fetch_stream(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:
diff
changeset
|
276 const struct message_size *size) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 struct istream *input; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 if (size->physical_size == size->virtual_size && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 ctx->cur_mail->has_no_nuls) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 /* no need to kludge with CRs, we can use sendfile() */ |
6142
6c0bfc35af03
Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents:
5836
diff
changeset
|
283 input = i_stream_create_limit(ctx->cur_input, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 ctx->cur_input->v_offset, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 ctx->cur_size); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
286 i_stream_unref(&ctx->cur_input); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 ctx->cur_input = input; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 ctx->cont_handler = fetch_stream_send_direct; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 ctx->cont_handler = fetch_stream_send; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 return ctx->cont_handler(ctx); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
295 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 static int fetch_data(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:
diff
changeset
|
298 const struct imap_fetch_body_data *body, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 const struct message_size *size) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 string_t *str; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 ctx->cur_size = get_send_size(body, size->virtual_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 str = get_prefix(ctx, body, ctx->cur_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 if (o_stream_send(ctx->client->output, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 str_data(str), str_len(str)) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 if (!ctx->update_partial) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 message_skip_virtual(ctx->cur_input, body->skip, NULL, FALSE, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 &ctx->skip_cr); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 ctx->skip_cr = |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 seek_partial(ctx->select_counter, ctx->cur_mail->uid, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 &partial, ctx->cur_input, body->skip); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 return fetch_stream(ctx, size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 static int fetch_body(struct imap_fetch_context *ctx, struct mail *mail, |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
323 const struct imap_fetch_body_data *body) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 const struct message_size *fetch_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 struct message_size hdr_size, body_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
328 if (mail_get_stream(mail, &hdr_size, |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
329 body->section[0] == 'H' ? NULL : &body_size, |
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
330 &ctx->cur_input) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 i_stream_ref(ctx->cur_input); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 ctx->update_partial = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 switch (body->section[0]) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
337 case '\0': |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
338 /* BODY[] - fetch everything */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 message_size_add(&body_size, &hdr_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
340 fetch_size = &body_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 case 'H': |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
343 /* BODY[HEADER] - fetch only header */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 fetch_size = &hdr_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
345 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 case 'T': |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
347 /* BODY[TEXT] - skip header */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
348 i_stream_skip(ctx->cur_input, hdr_size.physical_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 fetch_size = &body_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
350 break; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 default: |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 i_unreached(); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
353 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 return fetch_data(ctx, body, fetch_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 |
2448 | 358 static void header_filter_eoh(struct message_header_line *hdr, |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
359 bool *matched __attr_unused__, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
360 struct imap_fetch_context *ctx) |
2448 | 361 { |
362 if (hdr != NULL && hdr->eoh) | |
363 ctx->cur_have_eoh = TRUE; | |
364 } | |
365 | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 static int fetch_header_partial_from(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:
diff
changeset
|
367 const struct imap_fetch_body_data *body, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 const char *header_section) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
369 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 struct message_size msg_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 struct istream *input; |
2991
ca4341dbde8a
MIME part header fetches weren't working correctly.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
372 uoff_t old_offset; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 /* MIME, HEADER.FIELDS (list), HEADER.FIELDS.NOT (list) */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 |
2448 | 376 ctx->cur_have_eoh = FALSE; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 if (strncmp(header_section, "HEADER.FIELDS ", 14) == 0) { |
2436
f8c4ad92092c
header filter can now optionally use either LF or CRLF linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
2429
diff
changeset
|
378 input = i_stream_create_header_filter(ctx->cur_input, |
2451
f6fef42f01b9
Changed istream-header-filter API a bit. Added HIDE_BODY option. Fixed
Timo Sirainen <tss@iki.fi>
parents:
2448
diff
changeset
|
379 HEADER_FILTER_INCLUDE, |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
380 body->fields, |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
381 body->fields_count, |
2448 | 382 header_filter_eoh, ctx); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 } else if (strncmp(header_section, "HEADER.FIELDS.NOT ", 18) == 0) { |
2436
f8c4ad92092c
header filter can now optionally use either LF or CRLF linefeeds.
Timo Sirainen <tss@iki.fi>
parents:
2429
diff
changeset
|
384 input = i_stream_create_header_filter(ctx->cur_input, |
2451
f6fef42f01b9
Changed istream-header-filter API a bit. Added HIDE_BODY option. Fixed
Timo Sirainen <tss@iki.fi>
parents:
2448
diff
changeset
|
385 HEADER_FILTER_EXCLUDE, |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
386 body->fields, |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
387 body->fields_count, |
2448 | 388 header_filter_eoh, ctx); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 i_error("BUG: Accepted invalid section from user: '%s'", |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 header_section); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
395 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:
diff
changeset
|
396 ctx->cur_input = input; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 ctx->update_partial = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 |
2991
ca4341dbde8a
MIME part header fetches weren't working correctly.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
399 old_offset = ctx->cur_input->v_offset; |
2429
92f92b3c447b
istream-header-filter now parses the headers incrementally while read()ing,
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
400 message_get_header_size(ctx->cur_input, &msg_size, NULL); |
2991
ca4341dbde8a
MIME part header fetches weren't working correctly.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
401 i_stream_seek(ctx->cur_input, old_offset); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 |
2448 | 403 if (!ctx->cur_have_eoh && |
404 (client_workarounds & WORKAROUND_NETSCAPE_EOH) != 0) { | |
405 /* Netscape 4.x doesn't like if end of headers line is | |
406 missing. */ | |
407 msg_size.virtual_size += 2; | |
408 ctx->cur_append_eoh = TRUE; | |
409 } | |
410 | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 return fetch_data(ctx, body, &msg_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
414 static int |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
415 fetch_body_header_partial(struct imap_fetch_context *ctx, struct mail *mail, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
416 const struct imap_fetch_body_data *body) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
417 { |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
418 if (mail_get_stream(mail, NULL, NULL, &ctx->cur_input) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 i_stream_ref(ctx->cur_input); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 ctx->update_partial = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
423 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 return fetch_header_partial_from(ctx, body, body->section); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
425 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
427 static int |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
428 fetch_body_header_fields(struct imap_fetch_context *ctx, struct mail *mail, |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
429 struct imap_fetch_body_data *body) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 struct message_size size; |
2991
ca4341dbde8a
MIME part header fetches weren't working correctly.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
432 uoff_t old_offset; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 |
4073 | 434 if (mail == NULL) { |
435 /* deinit */ | |
436 mailbox_header_lookup_deinit(&body->header_ctx); | |
437 return 0; | |
438 } | |
439 | |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
440 if (mail_get_header_stream(mail, body->header_ctx, &ctx->cur_input) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 i_stream_ref(ctx->cur_input); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 ctx->update_partial = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 |
2991
ca4341dbde8a
MIME part header fetches weren't working correctly.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
446 old_offset = ctx->cur_input->v_offset; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 message_get_body_size(ctx->cur_input, &size, NULL); |
2991
ca4341dbde8a
MIME part header fetches weren't working correctly.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
448 i_stream_seek(ctx->cur_input, old_offset); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 |
2448 | 450 /* FIXME: We'll just always add the end of headers line now. |
451 ideally mail-storage would have a way to tell us if it exists. */ | |
452 size.virtual_size += 2; | |
453 ctx->cur_append_eoh = TRUE; | |
454 | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 return fetch_data(ctx, body, &size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
457 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
458 /* Find message_part for section (eg. 1.3.4) */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
459 static int part_find(struct mail *mail, const struct imap_fetch_body_data *body, |
3592 | 460 const struct message_part **part_r, const char **section_r) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
461 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 const struct message_part *part; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 const char *path; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 unsigned int num; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
466 if (mail_get_parts(mail, &part) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 path = body->section; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 while (*path >= '0' && *path <= '9' && part != NULL) { |
3592 | 471 /* get part number, we have already verified its validity */ |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 num = 0; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 while (*path != '\0' && *path != '.') { |
3592 | 474 i_assert(*path >= '0' && *path <= '9'); |
475 | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 num = num*10 + (*path - '0'); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 path++; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 if (*path == '.') |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 path++; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 if (part->flags & MESSAGE_PART_FLAG_MULTIPART) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 /* find the part */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 part = part->children; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
486 for (; num > 1 && part != NULL; num--) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 part = part->next; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
488 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
489 /* only 1 allowed with non-multipart messages */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
490 if (num != 1) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
491 part = NULL; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
492 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
493 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
494 if (part != NULL && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) && |
3491
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
496 (*path >= '0' && *path <= '9')) { |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
497 /* if we continue inside the message/rfc822, skip this |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
498 body part */ |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
499 part = part->children; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 *part_r = part; |
3592 | 504 *section_r = path; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 return 0; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
506 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 static int fetch_body_mime(struct imap_fetch_context *ctx, struct mail *mail, |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4073
diff
changeset
|
509 const struct imap_fetch_body_data *body) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 const struct message_part *part; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 const char *section; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 if (part_find(mail, body, &part, §ion) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
515 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
516 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
517 if (part == NULL) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
518 /* part doesn't exist */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 string_t *str = get_prefix(ctx, body, (uoff_t)-1); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
520 if (o_stream_send(ctx->client->output, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
521 str_data(str), str_len(str)) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
523 return 1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
524 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
526 if (mail_get_stream(mail, NULL, NULL, &ctx->cur_input) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
528 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
529 i_stream_ref(ctx->cur_input); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
530 ctx->update_partial = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
531 |
3491
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
532 if (*section == '\0') { |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
533 /* fetch the whole section */ |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
534 i_stream_seek(ctx->cur_input, part->physical_pos + |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
535 part->header_size.physical_size); |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
536 return fetch_data(ctx, body, &part->body_size); |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
537 } |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
538 |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
539 if (strcmp(section, "MIME") == 0) { |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
540 /* fetch section's MIME header */ |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
541 i_stream_seek(ctx->cur_input, part->physical_pos); |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
542 return fetch_data(ctx, body, &part->header_size); |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
543 } |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
544 |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
545 /* TEXT and HEADER are only for message/rfc822 parts */ |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
546 if ((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) == 0) { |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
547 string_t *str = get_prefix(ctx, body, 0); |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
548 if (o_stream_send(ctx->client->output, |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
549 str_data(str), str_len(str)) < 0) |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
550 return -1; |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
551 return 1; |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
552 } |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
553 |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
554 i_assert(part->children != NULL && part->children->next == NULL); |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
555 part = part->children; |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
556 |
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
557 if (strcmp(section, "TEXT") == 0) { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
558 i_stream_seek(ctx->cur_input, part->physical_pos + |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
559 part->header_size.physical_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
560 return fetch_data(ctx, body, &part->body_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
561 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
562 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
563 if (strcmp(section, "HEADER") == 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
564 /* all headers */ |
2991
ca4341dbde8a
MIME part header fetches weren't working correctly.
Timo Sirainen <tss@iki.fi>
parents:
2792
diff
changeset
|
565 i_stream_seek(ctx->cur_input, part->physical_pos); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
566 return fetch_data(ctx, body, &part->header_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
567 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
568 |
3491
2dbd7232d7df
Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
Timo Sirainen <tss@iki.fi>
parents:
3336
diff
changeset
|
569 if (strncmp(section, "HEADER", 6) == 0) { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
570 i_stream_seek(ctx->cur_input, part->physical_pos); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
571 return fetch_header_partial_from(ctx, body, section); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
572 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
573 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
574 i_error("BUG: Accepted invalid section from user: '%s'", body->section); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
575 return 1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
576 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
577 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
578 static bool fetch_body_header_fields_check(const char *section) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
579 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
580 if (*section++ != '(') |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
581 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
582 |
3299
361ce931354e
Don't allow FETCH BODY[HEADER.FIELDS ()], ie. empty list.
Timo Sirainen <tss@iki.fi>
parents:
3259
diff
changeset
|
583 if (*section == ')') |
361ce931354e
Don't allow FETCH BODY[HEADER.FIELDS ()], ie. empty list.
Timo Sirainen <tss@iki.fi>
parents:
3259
diff
changeset
|
584 return FALSE; /* has to be at least one field */ |
361ce931354e
Don't allow FETCH BODY[HEADER.FIELDS ()], ie. empty list.
Timo Sirainen <tss@iki.fi>
parents:
3259
diff
changeset
|
585 |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
586 while (*section != '\0' && *section != ')') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
587 if (*section == '(') |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
588 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
589 section++; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
590 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
591 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
592 if (*section++ != ')') |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
593 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
594 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
595 if (*section != '\0') |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
596 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
597 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
598 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
599 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
600 static bool fetch_body_header_fields_init(struct imap_fetch_context *ctx, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
601 struct imap_fetch_body_data *body, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
602 const char *section) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
603 { |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
604 const char *const *arr, *name; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
605 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
606 if (!fetch_body_header_fields_check(section)) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
607 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
608 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
609 name = get_body_name(body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
610 if ((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:
diff
changeset
|
611 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:
diff
changeset
|
612 /* we'll need to open the file anyway, don't try to get the |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
613 headers from cache. */ |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
614 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
615 fetch_body_header_partial, body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
616 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
617 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
618 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
619 t_push(); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
620 |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
621 for (arr = body->fields; *arr != NULL; arr++) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
622 char *hdr = p_strdup(ctx->cmd->pool, *arr); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
623 buffer_append(ctx->all_headers_buf, &hdr, sizeof(hdr)); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
624 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
625 |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
626 body->header_ctx = mailbox_header_lookup_init(ctx->box, body->fields); |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
627 imap_fetch_add_handler(ctx, FALSE, TRUE, name, "NIL", |
4073 | 628 fetch_body_header_fields, body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
629 t_pop(); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
630 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
631 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
632 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
633 static bool fetch_body_section_name_init(struct imap_fetch_context *ctx, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
634 struct imap_fetch_body_data *body) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
635 { |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
636 const char *name, *section = body->section; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
637 |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
638 name = get_body_name(body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
639 if (*section == '\0') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
640 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:
diff
changeset
|
641 MAIL_FETCH_STREAM_BODY; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
642 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
643 fetch_body, body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
644 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
645 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
646 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
647 if (strcmp(section, "TEXT") == 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
648 ctx->fetch_data |= MAIL_FETCH_STREAM_BODY; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
649 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
650 fetch_body, body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
651 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
652 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
653 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
654 if (strncmp(section, "HEADER", 6) == 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
655 /* exact header matches could be cached */ |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
656 if (section[6] == '\0') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
657 ctx->fetch_data |= MAIL_FETCH_STREAM_HEADER; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
658 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
4073 | 659 fetch_body, body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
660 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
661 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
662 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
663 if (strncmp(section, "HEADER.FIELDS ", 14) == 0 && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
664 fetch_body_header_fields_init(ctx, body, section+14)) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
665 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
666 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
667 if (strncmp(section, "HEADER.FIELDS.NOT ", 18) == 0 && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
668 fetch_body_header_fields_check(section+18)) { |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
669 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
670 fetch_body_header_partial, body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
671 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
672 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
673 } else if (*section >= '0' && *section <= '9') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
674 ctx->fetch_data |= MAIL_FETCH_STREAM_BODY | |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
675 MAIL_FETCH_MESSAGE_PARTS; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
676 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
677 while ((*section >= '0' && *section <= '9') || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
678 *section == '.') section++; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
679 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
680 if (*section == '\0' || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
681 strcmp(section, "MIME") == 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
682 strcmp(section, "TEXT") == 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
683 strcmp(section, "HEADER") == 0 || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
684 (strncmp(section, "HEADER.FIELDS ", 14) == 0 && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
685 fetch_body_header_fields_check(section+14)) || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
686 (strncmp(section, "HEADER.FIELDS.NOT ", 18) == 0 && |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
687 fetch_body_header_fields_check(section+18))) { |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
688 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
3216
8632ec8486c6
Send buffered fetch items to client first. Fixes kmail and Thunderbird
Timo Sirainen <tss@iki.fi>
parents:
3209
diff
changeset
|
689 fetch_body_mime, body); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
690 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
691 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
692 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
693 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
694 client_send_command_error(ctx->cmd, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
695 "Invalid BODY[..] parameter: Unknown or broken section"); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
696 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
697 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
698 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
699 /* Parse next digits in string into integer. Returns FALSE if the integer |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
700 becomes too big and wraps. */ |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
701 static bool read_uoff_t(const char **p, uoff_t *value) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
702 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
703 uoff_t prev; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
704 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
705 *value = 0; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
706 while (**p >= '0' && **p <= '9') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
707 prev = *value; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
708 *value = *value * 10 + (**p - '0'); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
709 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
710 if (*value < prev) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
711 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
712 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
713 (*p)++; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
714 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
715 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
716 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
717 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
718 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
719 static bool body_section_build(struct imap_fetch_context *ctx, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
720 struct imap_fetch_body_data *body, |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
721 const char *prefix, |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
722 const struct imap_arg *args, |
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
723 unsigned int args_count) |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
724 { |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
725 string_t *str; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
726 const char **arr; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
727 size_t i; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
728 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
729 str = str_new(ctx->cmd->pool, 128); |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
730 str_append(str, prefix); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
731 str_append(str, " ("); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
732 |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
733 /* @UNSAFE: NULL-terminated list of headers */ |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
734 arr = p_new(ctx->cmd->pool, const char *, args_count + 1); |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
735 |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
736 for (i = 0; i < args_count; i++) { |
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
737 if (args[i].type != IMAP_ARG_ATOM && |
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
738 args[i].type != IMAP_ARG_STRING) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
739 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:
2655
diff
changeset
|
740 "Invalid BODY[..] parameter: " |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
741 "Header list contains non-strings"); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
742 return FALSE; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
743 } |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
744 |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
745 if (i != 0) |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
746 str_append_c(str, ' '); |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
747 arr[i] = t_str_ucase(IMAP_ARG_STR(&args[i])); |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
748 |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
749 if (args[i].type == IMAP_ARG_ATOM) |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
750 str_append(str, arr[i]); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
751 else { |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
752 str_append_c(str, '"'); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
753 str_append(str, str_escape(arr[i])); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
754 str_append_c(str, '"'); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
755 } |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
756 } |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
757 str_append_c(str, ')'); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
758 |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
759 qsort(arr, args_count, sizeof(*arr), strcasecmp_p); |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
760 body->fields = arr; |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
761 body->fields_count = args_count; |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
762 body->section = str_c(str); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
763 return TRUE; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
764 } |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
765 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
766 bool fetch_body_section_init(struct imap_fetch_context *ctx, const char *name, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5276
diff
changeset
|
767 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:
diff
changeset
|
768 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
769 struct imap_fetch_body_data *body; |
2655 | 770 const char *partial; |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
771 const char *p = name + 4; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
772 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
773 body = p_new(ctx->cmd->pool, struct imap_fetch_body_data, 1); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
774 body->max_size = (uoff_t)-1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
775 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
776 if (strncmp(p, ".PEEK", 5) == 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
777 body->peek = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
778 p += 5; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
779 } else { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
780 ctx->flags_update_seen = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
781 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
782 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
783 if (*p != '[') { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
784 client_send_command_error(ctx->cmd, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
785 "Invalid BODY[..] parameter: Missing '['"); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
786 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
787 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
788 |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
789 if ((*args)[0].type == IMAP_ARG_LIST) { |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
790 /* BODY[HEADER.FIELDS.. (headers list)] */ |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
791 if ((*args)[1].type != IMAP_ARG_ATOM || |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
792 IMAP_ARG_STR(&(*args)[1])[0] != ']') { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
793 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:
2655
diff
changeset
|
794 "Invalid BODY[..] parameter: Missing ']'"); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
795 return FALSE; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
796 } |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
797 if (!body_section_build(ctx, body, p+1, |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
798 IMAP_ARG_LIST_ARGS(&(*args)[0]), |
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
799 IMAP_ARG_LIST_COUNT(&(*args)[0]))) |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
800 return FALSE; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
801 p = IMAP_ARG_STR(&(*args)[1]); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
802 *args += 2; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
803 } else { |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
804 /* no headers list */ |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
805 body->section = p+1; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
806 p = strchr(body->section, ']'); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
807 if (p == NULL) { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
808 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:
2655
diff
changeset
|
809 "Invalid BODY[..] parameter: Missing ']'"); |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
810 return FALSE; |
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
811 } |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
812 body->section = p_strdup_until(ctx->cmd->pool, |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
813 body->section, p); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
814 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
815 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
816 if (*++p == '<') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
817 /* <start.end> */ |
2655 | 818 partial = p; |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
819 p++; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
820 body->skip_set = TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
821 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
822 if (!read_uoff_t(&p, &body->skip) || body->skip > OFF_T_MAX) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
823 /* wrapped */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
824 client_send_command_error(ctx->cmd, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
825 "Invalid BODY[..] parameter: " |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
826 "Too big partial start"); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
827 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
828 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
829 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
830 if (*p == '.') { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
831 p++; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
832 if (!read_uoff_t(&p, &body->max_size) || |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
833 body->max_size > OFF_T_MAX) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
834 /* wrapped */ |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
835 client_send_command_error(ctx->cmd, |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
836 "Invalid BODY[..] parameter: " |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
837 "Too big partial end"); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
838 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
839 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
840 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
841 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
842 if (*p != '>') { |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
843 client_send_command_error(ctx->cmd, |
2655 | 844 t_strdup_printf("Invalid BODY[..] parameter: " |
845 "Missing '>' in '%s'", | |
846 partial)); | |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
847 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
848 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
849 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
850 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
851 return fetch_body_section_name_init(ctx, body); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
852 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
853 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
854 static int fetch_rfc822_size(struct imap_fetch_context *ctx, struct mail *mail, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
855 void *context __attr_unused__) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
856 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
857 uoff_t size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
858 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
859 if (mail_get_virtual_size(mail, &size) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
860 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
861 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
862 str_printfa(ctx->cur_str, "RFC822.SIZE %"PRIuUOFF_T" ", size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
863 return 1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
864 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
865 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
866 static int fetch_rfc822(struct imap_fetch_context *ctx, struct mail *mail, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
867 void *context __attr_unused__) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
868 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
869 struct message_size hdr_size, body_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
870 const char *str; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
871 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
872 if (mail_get_stream(mail, &hdr_size, &body_size, &ctx->cur_input) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
873 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
874 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
875 i_stream_ref(ctx->cur_input); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
876 ctx->update_partial = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
877 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
878 message_size_add(&body_size, &hdr_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
879 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
880 if (ctx->cur_offset == 0) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
881 str = t_strdup_printf(" RFC822 {%"PRIuUOFF_T"}\r\n", |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
882 body_size.virtual_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
883 if (ctx->first) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
884 str++; ctx->first = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
885 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
886 if (o_stream_send_str(ctx->client->output, str) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
887 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
888 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
889 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
890 ctx->cur_size = body_size.virtual_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
891 return fetch_stream(ctx, &body_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
892 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
893 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
894 static int fetch_rfc822_header(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:
diff
changeset
|
895 struct mail *mail, void *context __attr_unused__) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
896 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
897 struct message_size hdr_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
898 const char *str; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
899 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
900 if (mail_get_stream(mail, &hdr_size, NULL, &ctx->cur_input) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
901 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
902 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
903 i_stream_ref(ctx->cur_input); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
904 ctx->update_partial = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
905 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
906 str = t_strdup_printf(" RFC822.HEADER {%"PRIuUOFF_T"}\r\n", |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
907 hdr_size.virtual_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
908 if (ctx->first) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
909 str++; ctx->first = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
910 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
911 if (o_stream_send_str(ctx->client->output, str) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
912 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
913 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
914 ctx->cur_size = hdr_size.virtual_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
915 return fetch_stream(ctx, &hdr_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
916 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
917 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
918 static int fetch_rfc822_text(struct imap_fetch_context *ctx, struct mail *mail, |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
919 void *context __attr_unused__) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
920 { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
921 struct message_size hdr_size, body_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
922 const char *str; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
923 |
6280
eb7c9d8ece54
mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents:
6142
diff
changeset
|
924 if (mail_get_stream(mail, &hdr_size, &body_size, &ctx->cur_input) < 0) |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
925 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
926 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
927 i_stream_ref(ctx->cur_input); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
928 ctx->update_partial = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
929 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
930 str = t_strdup_printf(" RFC822.TEXT {%"PRIuUOFF_T"}\r\n", |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
931 body_size.virtual_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
932 if (ctx->first) { |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
933 str++; ctx->first = FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
934 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
935 if (o_stream_send_str(ctx->client->output, str) < 0) |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
936 return -1; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
937 |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
938 i_stream_seek(ctx->cur_input, hdr_size.physical_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
939 ctx->cur_size = body_size.virtual_size; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
940 return fetch_stream(ctx, &body_size); |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
941 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
942 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3592
diff
changeset
|
943 bool fetch_rfc822_init(struct imap_fetch_context *ctx, const char *name, |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5276
diff
changeset
|
944 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:
diff
changeset
|
945 { |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
946 if (name[6] == '\0') { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
947 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:
diff
changeset
|
948 MAIL_FETCH_STREAM_BODY; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
949 ctx->flags_update_seen = TRUE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
950 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
951 fetch_rfc822, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
952 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
953 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
954 |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
955 if (strcmp(name+6, ".SIZE") == 0) { |
2504
98f6057f27a1
Added mail.get_physical_size().
Timo Sirainen <tss@iki.fi>
parents:
2485
diff
changeset
|
956 ctx->fetch_data |= MAIL_FETCH_VIRTUAL_SIZE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
957 imap_fetch_add_handler(ctx, TRUE, FALSE, name, "0", |
4073 | 958 fetch_rfc822_size, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
959 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
960 } |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
961 if (strcmp(name+6, ".HEADER") == 0) { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
962 ctx->fetch_data |= MAIL_FETCH_STREAM_HEADER; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
963 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
4073 | 964 fetch_rfc822_header, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
965 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
966 } |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
967 if (strcmp(name+6, ".TEXT") == 0) { |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
968 ctx->fetch_data |= MAIL_FETCH_STREAM_BODY; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
969 ctx->flags_update_seen = TRUE; |
4973
ec41129cd0ef
When client fetches message data that has already been expunged, reply with
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
970 imap_fetch_add_handler(ctx, FALSE, FALSE, name, "NIL", |
4073 | 971 fetch_rfc822_text, NULL); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
972 return TRUE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
973 } |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
974 |
3141
61abed5f7864
Moved command-specific variables from struct client to struct
Timo Sirainen <tss@iki.fi>
parents:
2991
diff
changeset
|
975 client_send_command_error(ctx->cmd, t_strconcat( |
2675
60d33cf81c8e
BODY.PEEK[HEADER.FIELDS (...)] list is allowed to contain strings and
Timo Sirainen <tss@iki.fi>
parents:
2655
diff
changeset
|
976 "Unknown parameter ", name, NULL)); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
977 return FALSE; |
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
978 } |