Mercurial > dovecot > core-2.2
annotate src/lmtp/lmtp-proxy.c @ 13846:51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
This hopefully fixes problems related to LMTP proxying, at the cost of
having to write large mails to temp directory.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 10 Dec 2011 10:59:30 +0200 |
parents | 8de8752b2e94 |
children | bb848036f1b4 |
rev | line source |
---|---|
12782
447bce266022
Updated copyright notices to include year 2011.
Timo Sirainen <tss@iki.fi>
parents:
12398
diff
changeset
|
1 /* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */ |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "array.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "ioloop.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "istream.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "ostream.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "lmtp-client.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "lmtp-proxy.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #define LMTP_MAX_LINE_LEN 1024 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 struct lmtp_proxy_recipient { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 struct lmtp_proxy_connection *conn; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 const char *address; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 const char *reply; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 unsigned int rcpt_to_failed:1; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 unsigned int data_reply_received:1; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 }; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 struct lmtp_proxy_connection { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 struct lmtp_proxy *proxy; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 struct lmtp_proxy_settings set; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 struct lmtp_client *client; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 struct istream *data_input; |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
28 struct timeout *to; |
10415 | 29 |
30 unsigned int finished:1; | |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 unsigned int failed:1; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 }; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 struct lmtp_proxy { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 pool_t pool; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 const char *mail_from, *my_hostname; |
10825
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
37 const char *dns_client_socket_path; |
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
38 |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 ARRAY_DEFINE(connections, struct lmtp_proxy_connection *); |
10415 | 40 ARRAY_DEFINE(rcpt_to, struct lmtp_proxy_recipient *); |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
41 unsigned int next_data_reply_idx; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
43 struct timeout *to_finish; |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
44 struct istream *data_input; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 struct ostream *client_output; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
47 unsigned int max_timeout_msecs; |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
48 |
10400
96152031f5d9
lmtp proxy: More error handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
10399
diff
changeset
|
49 lmtp_proxy_finish_callback_t *finish_callback; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 void *finish_context; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 unsigned int finished:1; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 }; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
55 static void lmtp_conn_finish(void *context); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 struct lmtp_proxy * |
10825
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
58 lmtp_proxy_init(const char *my_hostname, const char *dns_client_socket_path, |
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
59 struct ostream *client_output) |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 struct lmtp_proxy *proxy; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 pool_t pool; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 o_stream_ref(client_output); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 pool = pool_alloconly_create("lmtp proxy", 1024); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 proxy = p_new(pool, struct lmtp_proxy, 1); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 proxy->pool = pool; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 proxy->my_hostname = p_strdup(pool, my_hostname); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 proxy->client_output = client_output; |
10825
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
71 proxy->dns_client_socket_path = p_strdup(pool, dns_client_socket_path); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 i_array_init(&proxy->rcpt_to, 32); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 i_array_init(&proxy->connections, 32); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 return proxy; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 static void lmtp_proxy_connections_deinit(struct lmtp_proxy *proxy) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 struct lmtp_proxy_connection *const *conns; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 |
10406 | 81 array_foreach(&proxy->connections, conns) { |
82 struct lmtp_proxy_connection *conn = *conns; | |
83 | |
84 lmtp_client_deinit(&conn->client); | |
10397
9500cfbe5dbf
lmtp proxy: Error handling fix.
Timo Sirainen <tss@iki.fi>
parents:
10396
diff
changeset
|
85 } |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 void lmtp_proxy_deinit(struct lmtp_proxy **_proxy) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 struct lmtp_proxy *proxy = *_proxy; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 *_proxy = NULL; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 lmtp_proxy_connections_deinit(proxy); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 if (proxy->data_input != NULL) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 i_stream_unref(&proxy->data_input); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 if (proxy->client_output != NULL) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 o_stream_unref(&proxy->client_output); |
10824 | 99 if (proxy->to_finish != NULL) |
100 timeout_remove(&proxy->to_finish); | |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 array_free(&proxy->rcpt_to); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 array_free(&proxy->connections); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 pool_unref(&proxy->pool); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 void lmtp_proxy_mail_from(struct lmtp_proxy *proxy, const char *value) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 proxy->mail_from = p_strdup(proxy->pool, value); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 static struct lmtp_proxy_connection * |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 lmtp_proxy_get_connection(struct lmtp_proxy *proxy, |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 const struct lmtp_proxy_settings *set) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 struct lmtp_proxy_connection *const *conns, *conn; |
10825
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
116 struct lmtp_client_settings client_set; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
118 i_assert(set->timeout_msecs > 0); |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
119 |
10406 | 120 array_foreach(&proxy->connections, conns) { |
121 conn = *conns; | |
122 | |
123 if (conn->set.port == set->port && | |
124 strcmp(conn->set.host, set->host) == 0) | |
125 return conn; | |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 |
10825
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
128 memset(&client_set, 0, sizeof(client_set)); |
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
129 client_set.mail_from = proxy->mail_from; |
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
130 client_set.my_hostname = proxy->my_hostname; |
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
131 client_set.dns_client_socket_path = proxy->dns_client_socket_path; |
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
132 |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 conn = p_new(proxy->pool, struct lmtp_proxy_connection, 1); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 conn->proxy = proxy; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 conn->set.host = p_strdup(proxy->pool, set->host); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 conn->set.port = set->port; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 conn->set.timeout_msecs = set->timeout_msecs; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 array_append(&proxy->connections, &conn, 1); |
10825
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
139 |
cc3f6adc1e0b
lmtp proxy: Added support for DNS lookups.
Timo Sirainen <tss@iki.fi>
parents:
10824
diff
changeset
|
140 conn->client = lmtp_client_init(&client_set, lmtp_conn_finish, conn); |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
141 if (lmtp_client_connect_tcp(conn->client, set->protocol, |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 conn->set.host, conn->set.port) < 0) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 conn->failed = TRUE; |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
144 |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
145 if (proxy->max_timeout_msecs < set->timeout_msecs) |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
146 proxy->max_timeout_msecs = set->timeout_msecs; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 return conn; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
150 static bool lmtp_proxy_send_data_replies(struct lmtp_proxy *proxy) |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 { |
10415 | 152 struct lmtp_proxy_recipient *const *rcpt; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 unsigned int i, count; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 o_stream_cork(proxy->client_output); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 rcpt = array_get(&proxy->rcpt_to, &count); |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
157 for (i = proxy->next_data_reply_idx; i < count; i++) { |
10415 | 158 if (!(rcpt[i]->rcpt_to_failed || rcpt[i]->data_reply_received)) |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 break; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 o_stream_send_str(proxy->client_output, |
10415 | 161 t_strconcat(rcpt[i]->reply, "\r\n", NULL)); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 o_stream_uncork(proxy->client_output); |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
164 proxy->next_data_reply_idx = i; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 return i == count; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 |
10415 | 169 static void lmtp_proxy_finish_timeout(struct lmtp_proxy *proxy) |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 i_assert(!proxy->finished); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 |
10415 | 173 timeout_remove(&proxy->to_finish); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 proxy->finished = TRUE; |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
175 proxy->finish_callback(proxy->finish_context); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
178 static void lmtp_proxy_try_finish(struct lmtp_proxy *proxy) |
10415 | 179 { |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
180 if (proxy->finish_callback == NULL) { |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
181 /* DATA command hasn't been sent yet */ |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
182 return; |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
183 } |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
184 if (!lmtp_proxy_send_data_replies(proxy)) { |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
185 /* we can't received reply from all clients yet */ |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
186 return; |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
187 } |
10415 | 188 /* do the actual finishing in a timeout handler, since the finish |
189 callback causes the proxy to be destroyed and the code leading up | |
190 to this function can be called from many different places. it's | |
191 easier this way rather than having all the callers check if the | |
192 proxy was already destroyed. */ | |
193 if (proxy->to_finish == NULL) { | |
194 proxy->to_finish = timeout_add(0, lmtp_proxy_finish_timeout, | |
195 proxy); | |
196 } | |
197 } | |
198 | |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
199 static void lmtp_conn_finish(void *context) |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
200 { |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
201 struct lmtp_proxy_connection *conn = context; |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
202 |
10415 | 203 conn->finished = TRUE; |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
204 if (conn->to != NULL) |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
205 timeout_remove(&conn->to); |
10399
8f6995923fbd
lmtp proxy: Don't crash if all RCPT TOs fail to a remote.
Timo Sirainen <tss@iki.fi>
parents:
10398
diff
changeset
|
206 if (conn->data_input != NULL) |
8f6995923fbd
lmtp proxy: Don't crash if all RCPT TOs fail to a remote.
Timo Sirainen <tss@iki.fi>
parents:
10398
diff
changeset
|
207 i_stream_unref(&conn->data_input); |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
208 lmtp_proxy_try_finish(conn->proxy); |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
209 } |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
210 |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 static void |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 lmtp_proxy_conn_rcpt_to(bool success, const char *reply, void *context) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 { |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
214 struct lmtp_proxy_recipient *rcpt = context; |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
215 struct lmtp_proxy_connection *conn = rcpt->conn; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
217 i_assert(rcpt->reply == NULL); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
219 rcpt->reply = p_strdup(conn->proxy->pool, reply); |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
220 rcpt->rcpt_to_failed = !success; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 static void |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 lmtp_proxy_conn_data(bool success ATTR_UNUSED, const char *reply, void *context) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 { |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
226 struct lmtp_proxy_recipient *rcpt = context; |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
227 struct lmtp_proxy_connection *conn = rcpt->conn; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
229 i_assert(!rcpt->rcpt_to_failed); |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
230 i_assert(rcpt->reply != NULL); |
10396 | 231 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
232 rcpt->reply = p_strdup(conn->proxy->pool, reply); |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
233 rcpt->data_reply_received = TRUE; |
11496
2d6cf78982dc
lmtp proxy: Fixed 30 second delay after finishing DATA.
Timo Sirainen <tss@iki.fi>
parents:
10825
diff
changeset
|
234 |
2d6cf78982dc
lmtp proxy: Fixed 30 second delay after finishing DATA.
Timo Sirainen <tss@iki.fi>
parents:
10825
diff
changeset
|
235 lmtp_proxy_try_finish(conn->proxy); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 int lmtp_proxy_add_rcpt(struct lmtp_proxy *proxy, const char *address, |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 const struct lmtp_proxy_settings *set) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 struct lmtp_proxy_connection *conn; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 struct lmtp_proxy_recipient *rcpt; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 conn = lmtp_proxy_get_connection(proxy, set); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 if (conn->failed) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 return -1; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 |
10415 | 248 rcpt = p_new(proxy->pool, struct lmtp_proxy_recipient, 1); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 rcpt->conn = conn; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 rcpt->address = p_strdup(proxy->pool, address); |
10415 | 251 array_append(&proxy->rcpt_to, &rcpt, 1); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 lmtp_client_add_rcpt(conn->client, address, lmtp_proxy_conn_rcpt_to, |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
254 lmtp_proxy_conn_data, rcpt); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 return 0; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
258 static void lmtp_proxy_more_data_sent(void *context) |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 { |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
260 struct lmtp_proxy_connection *conn = context; |
10415 | 261 |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
262 lmtp_client_send_more(conn->client); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
265 static void lmtp_proxy_conn_timeout(struct lmtp_proxy_connection *conn) |
12240
1f784904111b
lmtp proxy: Avoid hanging at the end of message input.
Timo Sirainen <tss@iki.fi>
parents:
11496
diff
changeset
|
266 { |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
267 const char *line; |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
268 |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
269 line = t_strdup_printf(ERRSTR_TEMP_REMOTE_FAILURE |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
270 " (timeout while waiting for reply to %s)", |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
271 lmtp_client_state_to_string(conn->client)); |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
272 lmtp_client_fail(conn->client, line); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 void lmtp_proxy_start(struct lmtp_proxy *proxy, struct istream *data_input, |
10288
c11324abe1a8
lmtp proxy: Add Received: header.
Timo Sirainen <tss@iki.fi>
parents:
10285
diff
changeset
|
276 const char *header, |
10400
96152031f5d9
lmtp proxy: More error handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
10399
diff
changeset
|
277 lmtp_proxy_finish_callback_t *callback, void *context) |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 struct lmtp_proxy_connection *const *conns; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
281 i_assert(data_input->seekable); |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
282 |
10400
96152031f5d9
lmtp proxy: More error handling fixes.
Timo Sirainen <tss@iki.fi>
parents:
10399
diff
changeset
|
283 proxy->finish_callback = callback; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 proxy->finish_context = context; |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
285 proxy->data_input = data_input; |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
286 i_stream_ref(proxy->data_input); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 |
10406 | 288 array_foreach(&proxy->connections, conns) { |
289 struct lmtp_proxy_connection *conn = *conns; | |
290 | |
10415 | 291 if (conn->finished) { |
292 /* this connection had already failed */ | |
293 continue; | |
294 } | |
295 | |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
296 conn->to = timeout_add(proxy->max_timeout_msecs, |
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
297 lmtp_proxy_conn_timeout, conn); |
10415 | 298 lmtp_client_set_data_output_callback(conn->client, |
299 lmtp_proxy_more_data_sent, | |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
300 conn); |
10415 | 301 |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
302 conn->data_input = i_stream_create_limit(data_input, (uoff_t)-1); |
10406 | 303 lmtp_client_set_data_header(conn->client, header); |
304 lmtp_client_send(conn->client, conn->data_input); | |
13846
51d87deb5c26
lmtp: Simplify LMTP proxying by first reading the whole input to memory/disk.
Timo Sirainen <tss@iki.fi>
parents:
13477
diff
changeset
|
305 lmtp_client_send_more(conn->client); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 } |