Commit
+32 -13 +/-4 browse
1 | diff --git a/cmd/maitred-debug/src/config.rs b/cmd/maitred-debug/src/config.rs |
2 | index 5abb83d..ed9bb84 100644 |
3 | --- a/cmd/maitred-debug/src/config.rs |
4 | +++ b/cmd/maitred-debug/src/config.rs |
5 | @@ -24,6 +24,7 @@ pub(crate) struct Tls { |
6 | |
7 | #[derive(serde::Deserialize)] |
8 | pub(crate) struct Config { |
9 | + pub address: String, |
10 | pub maildir: String, |
11 | pub spf: Spf, |
12 | pub dkim: Dkim, |
13 | diff --git a/cmd/maitred-debug/src/main.rs b/cmd/maitred-debug/src/main.rs |
14 | index 8bd1a76..0a12dc2 100644 |
15 | --- a/cmd/maitred-debug/src/main.rs |
16 | +++ b/cmd/maitred-debug/src/main.rs |
17 | @@ -63,7 +63,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { |
18 | }, |
19 | )); |
20 | let mut mail_server = Server::default() |
21 | - .address("127.0.0.1:2525") |
22 | + .address(&config.address) |
23 | .with_milter(MilterFunc(|message: &Message<'static>| { |
24 | let message = message.clone(); |
25 | async move { Ok(message.to_owned()) } |
26 | diff --git a/maitred.toml b/maitred.toml |
27 | index 664e4ec..8a60c01 100644 |
28 | --- a/maitred.toml |
29 | +++ b/maitred.toml |
30 | @@ -1,6 +1,9 @@ |
31 | # Path of the directory to deliver mail in the "maildir" format to |
32 | maildir = "mail" |
33 | |
34 | + # address to bind to |
35 | + address = "0.0.0.0:2525" |
36 | + |
37 | [dkim] |
38 | enabled = false |
39 | |
40 | diff --git a/maitred/src/server.rs b/maitred/src/server.rs |
41 | index a3931ed..fd943d1 100644 |
42 | --- a/maitred/src/server.rs |
43 | +++ b/maitred/src/server.rs |
44 | @@ -296,18 +296,18 @@ impl Server { |
45 | stream: BufStream<T>, |
46 | msg_queue: Arc<Injector<Envelope>>, |
47 | pipelining: bool, |
48 | + remote_addr: SocketAddr, |
49 | ) -> Result<(), ServerError> |
50 | where |
51 | T: tokio::io::AsyncRead + tokio::io::AsyncWrite + std::marker::Unpin, |
52 | { |
53 | - let mut session_opts = self.options.clone().unwrap_or_default(); |
54 | - |
55 | - if let Some(addr) = self.current_addr { |
56 | - session_opts = session_opts.ip_addr(addr.ip()); |
57 | - } |
58 | - |
59 | let mut session = Session::default() |
60 | - .with_options(session_opts) |
61 | + .with_options( |
62 | + self.options |
63 | + .clone() |
64 | + .unwrap_or_default() |
65 | + .ip_addr(remote_addr.ip()), |
66 | + ) |
67 | .resolver(self.resolver.clone()) |
68 | .spf_verification(self.spf_verification); |
69 | |
70 | @@ -465,16 +465,20 @@ impl Server { |
71 | self.spawn_workers(global_queue.clone()).await; |
72 | loop { |
73 | let (socket, addr) = listener.accept().await.unwrap(); |
74 | - self.current_addr = Some(addr); |
75 | let local_addr = socket.local_addr()?; |
76 | - tracing::info!("Accepted connection on: {:?}", local_addr); |
77 | + tracing::info!("Accepted connection on: {:?} from: {:?}", local_addr, addr); |
78 | let pipelining = self |
79 | .options |
80 | .as_ref() |
81 | .is_some_and(|opts| opts.capabilities & smtp_proto::EXT_PIPELINING != 0) |
82 | || self.options.is_none(); |
83 | match self |
84 | - .serve_plain(BufStream::new(socket), global_queue.clone(), pipelining) |
85 | + .serve_plain( |
86 | + BufStream::new(socket), |
87 | + global_queue.clone(), |
88 | + pipelining, |
89 | + addr, |
90 | + ) |
91 | .await |
92 | { |
93 | Ok(_) => { |
94 | @@ -496,6 +500,7 @@ mod test { |
95 | use super::*; |
96 | |
97 | use std::io; |
98 | + use std::net::{Ipv4Addr, SocketAddrV4}; |
99 | use std::pin::Pin; |
100 | use std::task::{Context, Poll}; |
101 | use tokio::io::{AsyncRead, AsyncWrite}; |
102 | @@ -567,7 +572,12 @@ mod test { |
103 | .with_session_opts(SessionOptions::default().capabilities(0)); |
104 | let global_queue = Arc::new(Injector::<Envelope>::new()); |
105 | server |
106 | - .serve_plain(BufStream::new(stream), global_queue.clone(), false) |
107 | + .serve_plain( |
108 | + BufStream::new(stream), |
109 | + global_queue.clone(), |
110 | + false, |
111 | + SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 25)), |
112 | + ) |
113 | .await |
114 | .unwrap(); |
115 | let packet = global_queue.steal().success().unwrap(); |
116 | @@ -594,7 +604,12 @@ mod test { |
117 | let server = Server::default(); |
118 | let global_queue = Arc::new(Injector::<Envelope>::new()); |
119 | server |
120 | - .serve_plain(BufStream::new(stream), global_queue.clone(), false) |
121 | + .serve_plain( |
122 | + BufStream::new(stream), |
123 | + global_queue.clone(), |
124 | + false, |
125 | + SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 25)), |
126 | + ) |
127 | .await |
128 | .unwrap(); |
129 | let packet = global_queue.steal().success().unwrap(); |