Mercurial > dovecot > core-2.2
annotate src/lmtp/lmtp-proxy.c @ 10398:a144e918938c HEAD
LMTP client API changes. Should be easier to use now.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 24 Nov 2009 14:17:06 -0500 |
parents | 9500cfbe5dbf |
children | 8f6995923fbd |
rev | line source |
---|---|
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (c) 2009 Dovecot authors, see the included COPYING file */ |
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 "istream-tee.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "ostream.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-client.h" |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #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
|
11 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #define LMTP_MAX_LINE_LEN 1024 |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
13 #define LMTP_PROXY_DATA_INPUT_TIMEOUT_MSECS (1000*60) |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 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
|
16 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
|
17 const char *address; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 const char *reply; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 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
|
21 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
|
22 }; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 |
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_connection { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 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
|
26 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
|
27 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 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
|
29 struct istream *data_input; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 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
|
31 }; |
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 struct lmtp_proxy { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 pool_t pool; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 const char *mail_from, *my_hostname; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 ARRAY_DEFINE(connections, 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
|
37 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
|
38 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
|
39 |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
40 struct timeout *to, *to_data_idle; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 struct io *io; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 struct istream *data_input; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 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
|
44 struct tee_istream *tee_data_input; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
46 unsigned int max_timeout_msecs; |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
47 |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 void (*finish_callback)(void *); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 void *finish_context; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 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
|
52 }; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
54 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
|
55 static void lmtp_proxy_data_input(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
|
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 * |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 lmtp_proxy_init(const char *my_hostname, 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
|
59 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 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
|
61 pool_t pool; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 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
|
64 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 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
|
66 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
|
67 proxy->pool = pool; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 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
|
69 proxy->client_output = client_output; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 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
|
71 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
|
72 return proxy; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 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
|
76 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 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
|
78 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
|
79 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 conns = array_get(&proxy->connections, &count); |
10397
9500cfbe5dbf
lmtp proxy: Error handling fix.
Timo Sirainen <tss@iki.fi>
parents:
10396
diff
changeset
|
81 for (i = 0; i < count; i++) { |
10396 | 82 lmtp_client_fail(conns[i]->client, "451 4.3.0 Aborting"); |
10397
9500cfbe5dbf
lmtp proxy: Error handling fix.
Timo Sirainen <tss@iki.fi>
parents:
10396
diff
changeset
|
83 lmtp_client_deinit(&conns[i]->client); |
9500cfbe5dbf
lmtp proxy: Error handling fix.
Timo Sirainen <tss@iki.fi>
parents:
10396
diff
changeset
|
84 } |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 } |
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 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
|
88 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 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
|
90 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 *_proxy = NULL; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 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
|
97 o_stream_unref(&proxy->client_output); |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
98 if (proxy->to_data_idle != NULL) |
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
99 timeout_remove(&proxy->to_data_idle); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 if (proxy->to != NULL) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 timeout_remove(&proxy->to); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 if (proxy->io != NULL) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 io_remove(&proxy->io); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 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
|
110 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 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
|
112 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 struct lmtp_proxy_connection *const *conns, *conn; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 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
|
120 |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
121 i_assert(set->timeout_msecs > 0); |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
122 |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 conns = array_get(&proxy->connections, &count); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 for (i = 0; i < count; i++) { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 if (conns[i]->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
|
126 strcmp(conns[i]->set.host, set->host) == 0) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 return conns[i]; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 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
|
131 conn->proxy = proxy; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 array_append(&proxy->connections, &conn, 1); |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
136 conn->client = lmtp_client_init(proxy->mail_from, proxy->my_hostname, |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
137 lmtp_conn_finish, conn); |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
138 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
|
139 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
|
140 conn->failed = TRUE; |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
141 |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
142 if (proxy->max_timeout_msecs < set->timeout_msecs) |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
143 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
|
144 return conn; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
147 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
|
148 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 const 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
|
150 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
|
151 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 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
|
153 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
|
154 for (i = proxy->next_data_reply_idx; i < count; i++) { |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 if (!(rcpt[i].rcpt_to_failed || rcpt[i].data_reply_received)) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 break; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 o_stream_send_str(proxy->client_output, |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 t_strconcat(rcpt[i].reply, "\r\n", NULL)); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 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
|
161 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
|
162 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 return i == count; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 } |
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 static void lmtp_proxy_finish(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
|
167 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 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
|
169 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 proxy->finished = TRUE; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 proxy->finish_callback(proxy->finish_context); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
174 static void lmtp_proxy_try_finish(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
|
175 { |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
176 if (lmtp_proxy_send_data_replies(proxy) && proxy->data_input->eof) |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 lmtp_proxy_finish(proxy); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
180 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
|
181 { |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
182 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
|
183 |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
184 i_stream_unref(&conn->data_input); |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
185 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
|
186 } |
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
187 |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
188 static void lmtp_proxy_fail_all(struct lmtp_proxy *proxy, const char *reason) |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
189 { |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
190 struct lmtp_proxy_connection *const *conns; |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
191 unsigned int i, count; |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
192 const char *line; |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
193 |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
194 pool_ref(proxy->pool); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
195 conns = array_get(&proxy->connections, &count); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
196 for (i = 0; i < count; i++) { |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
197 line = t_strdup_printf(ERRSTR_TEMP_REMOTE_FAILURE |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
198 " (%s while waiting for reply to %s)", reason, |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
199 lmtp_client_state_to_string(conns[i]->client)); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
200 lmtp_client_fail(conns[i]->client, line); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
201 |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
202 if (!array_is_created(&proxy->connections)) { |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
203 pool_unref(&proxy->pool); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
204 return; |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
205 } |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
206 } |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
207 i_unreached(); |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
208 } |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
209 |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
210 static void lmtp_proxy_data_input_timeout(struct lmtp_proxy *proxy) |
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
211 { |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
212 struct lmtp_proxy_connection *const *conns; |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
213 unsigned int i, count; |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
214 |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
215 pool_ref(proxy->pool); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
216 conns = array_get(&proxy->connections, &count); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
217 for (i = 0; i < count; i++) { |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
218 lmtp_client_fail(conns[i]->client, ERRSTR_TEMP_REMOTE_FAILURE |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
219 " (timeout in DATA input)"); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
220 if (!array_is_created(&proxy->connections)) { |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
221 pool_unref(&proxy->pool); |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
222 return; |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
223 } |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
224 } |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
225 i_unreached(); |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
226 } |
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
227 |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 static void |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 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
|
230 { |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
231 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
|
232 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
|
233 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
234 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
|
235 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
236 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
|
237 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
|
238 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 static void |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 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
|
242 { |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
243 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
|
244 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
|
245 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
246 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
|
247 i_assert(rcpt->reply != NULL); |
10396 | 248 |
10398
a144e918938c
LMTP client API changes. Should be easier to use now.
Timo Sirainen <tss@iki.fi>
parents:
10397
diff
changeset
|
249 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
|
250 rcpt->data_reply_received = TRUE; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 } |
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 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
|
254 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
|
255 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 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
|
257 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
|
258 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 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
|
260 if (conn->failed) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 return -1; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 rcpt = array_append_space(&proxy->rcpt_to); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 rcpt->conn = conn; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 rcpt->address = p_strdup(proxy->pool, address); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 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
|
268 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
|
269 return 0; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 |
10340
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
272 static size_t lmtp_proxy_find_max_data_input_size(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
|
273 { |
10340
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
274 struct lmtp_proxy_connection *const *conns; |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 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
|
276 size_t size, max_size = 0; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 |
10340
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
278 conns = array_get(&proxy->connections, &count); |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
279 for (i = 0; i < count; i++) { |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
280 (void)i_stream_get_data(conns[i]->data_input, &size); |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
281 if (max_size < size) |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
282 max_size = size; |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
283 } |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
284 return max_size; |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
285 } |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
286 |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
287 static bool lmtp_proxy_disconnect_hanging_output(struct lmtp_proxy *proxy) |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
288 { |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
289 struct lmtp_proxy_connection *const *conns; |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
290 unsigned int i, count; |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
291 size_t size, max_size; |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
292 |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
293 max_size = lmtp_proxy_find_max_data_input_size(proxy); |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
294 if (max_size == 0) |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
295 return FALSE; |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
296 |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
297 /* disconnect all connections that are keeping us from reading |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
298 more input. */ |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
299 conns = array_get(&proxy->connections, &count); |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
300 for (i = 0; i < count; i++) { |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
301 (void)i_stream_get_data(conns[i]->data_input, &size); |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
302 if (size == max_size) { |
10396 | 303 lmtp_client_fail(conns[i]->client, |
304 ERRSTR_TEMP_REMOTE_FAILURE | |
305 " (DATA output timeout)"); | |
10340
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
306 } |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
307 } |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
308 return TRUE; |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
309 } |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
310 |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
311 static void lmtp_proxy_output_timeout(struct lmtp_proxy *proxy) |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
312 { |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 timeout_remove(&proxy->to); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 /* drop the connection with the most unread data */ |
10340
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
316 if (lmtp_proxy_disconnect_hanging_output(proxy)) |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
317 lmtp_proxy_data_input(proxy); |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
318 else { |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
319 /* no such connection, so we've already sent everything but |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
320 some servers aren't replying to us. disconnect all of |
26eb1b52a23f
lmtp proxy: If remote hangs without replying to end-of-DATA dot, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
10334
diff
changeset
|
321 them. */ |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
322 lmtp_proxy_fail_all(proxy, "timeout"); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 static void lmtp_proxy_wait_for_output(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
|
327 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 i_assert(proxy->to == NULL); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 if (proxy->io != NULL) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 io_remove(&proxy->io); |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
332 proxy->to = timeout_add(proxy->max_timeout_msecs, |
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
333 lmtp_proxy_output_timeout, proxy); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
336 static bool lmtp_proxy_data_read(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
|
337 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
338 size_t size; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
340 timeout_reset(proxy->to_data_idle); |
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
341 |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 switch (i_stream_read(proxy->data_input)) { |
10393
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
343 case 0: |
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
344 if (!tee_i_stream_child_is_waiting(proxy->data_input)) { |
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
345 /* nothing new read */ |
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
346 if (proxy->io != NULL) |
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
347 return FALSE; |
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
348 proxy->io = io_add(i_stream_get_fd(proxy->data_input), |
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
349 IO_READ, |
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
350 lmtp_proxy_data_input, proxy); |
10394
c5c360a88067
lmtp proxy: Fix to handling "no new input" reads.
Timo Sirainen <tss@iki.fi>
parents:
10393
diff
changeset
|
351 return FALSE; |
10393
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
352 } |
4eadbf965d1f
lmtp proxy: Stalling remote servers weren't detected correctly.
Timo Sirainen <tss@iki.fi>
parents:
10341
diff
changeset
|
353 /* fall through */ |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 case -2: |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 /* buffer full. someone's stalling. */ |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 lmtp_proxy_wait_for_output(proxy); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 return FALSE; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 case -1: |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
359 if (proxy->data_input->stream_errno != 0) |
10341
d784be144b4d
lmtp proxy: Fixes to error handling.
Timo Sirainen <tss@iki.fi>
parents:
10340
diff
changeset
|
360 lmtp_proxy_fail_all(proxy, "disconnect"); |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
361 else { |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
362 /* finished reading data input. now we'll just have to |
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
363 wait for replies. */ |
10278
84a1776dd1c3
lmtp proxy: After all DATA input is read, stop trying to read more of it.
Timo Sirainen <tss@iki.fi>
parents:
10000
diff
changeset
|
364 lmtp_proxy_wait_for_output(proxy); |
10285
aa8729e340ba
lmtp, lmtp client: More fixes to handling failures.
Timo Sirainen <tss@iki.fi>
parents:
10284
diff
changeset
|
365 /* if all RCPT TOs failed, we can finish now */ |
aa8729e340ba
lmtp, lmtp client: More fixes to handling failures.
Timo Sirainen <tss@iki.fi>
parents:
10284
diff
changeset
|
366 lmtp_proxy_try_finish(proxy); |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
367 } |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 return FALSE; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
369 default: |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 /* something was read */ |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 (void)i_stream_get_data(proxy->data_input, &size); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 i_stream_skip(proxy->data_input, size); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 return TRUE; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
376 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 static void lmtp_proxy_data_input(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
|
378 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 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
|
380 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
|
381 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 do { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 conns = array_get(&proxy->connections, &count); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 for (i = 0; i < count; i++) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 lmtp_client_send_more(conns[i]->client); |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
386 } while (lmtp_proxy_data_read(proxy)); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
388 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 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
|
390 const char *header, |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 void (*finish_callback)(void *), void *context) |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 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
|
394 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
|
395 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
396 proxy->finish_callback = finish_callback; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 proxy->finish_context = context; |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 proxy->tee_data_input = tee_i_stream_create(data_input); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 proxy->data_input = tee_i_stream_create_child(proxy->tee_data_input); |
10284
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
400 proxy->to_data_idle = timeout_add(LMTP_PROXY_DATA_INPUT_TIMEOUT_MSECS, |
2ad1ad1e1083
lmtp proxy: Added data input timeout.
Timo Sirainen <tss@iki.fi>
parents:
10278
diff
changeset
|
401 lmtp_proxy_data_input_timeout, proxy); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 conns = array_get(&proxy->connections, &count); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
404 for (i = 0; i < count; i++) { |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 conns[i]->data_input = |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
406 tee_i_stream_create_child(proxy->tee_data_input); |
10288
c11324abe1a8
lmtp proxy: Add Received: header.
Timo Sirainen <tss@iki.fi>
parents:
10285
diff
changeset
|
407 lmtp_client_set_data_header(conns[i]->client, header); |
9900
22d27318bb18
lmtp client, proxy: Several bugfixes.
Timo Sirainen <tss@iki.fi>
parents:
9832
diff
changeset
|
408 lmtp_client_send(conns[i]->client, conns[i]->data_input); |
9832
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 } |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 lmtp_proxy_data_input(proxy); |
3a16bec9c961
lmtp: Added initial support for proxying mails to other LMTP/SMTP servers.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 } |