Author:
Hash:
Timestamp:
+17 -25 +/-2 browse
Kevin Schoon [me@kevinschoon.com]
2e243f90af4351c95acf7aed094c77e9ca5ee40c
Sat, 03 Aug 2024 10:46:55 +0000 (1.2 years ago)
| 1 | diff --git a/maitred/src/server.rs b/maitred/src/server.rs |
| 2 | index 677581f..c78f4f9 100644 |
| 3 | --- a/maitred/src/server.rs |
| 4 | +++ b/maitred/src/server.rs |
| 5 | @@ -1,7 +1,6 @@ |
| 6 | use std::time::Duration; |
| 7 | |
| 8 | use futures::SinkExt; |
| 9 | - use melib::uuid::Bytes; |
| 10 | use smtp_proto::Request; |
| 11 | use tokio::{net::TcpListener, time::timeout}; |
| 12 | use tokio_stream::StreamExt; |
| 13 | @@ -9,7 +8,7 @@ use tokio_util::codec::Framed; |
| 14 | |
| 15 | use crate::error::Error; |
| 16 | use crate::session::{Options as SessionOptions, Session}; |
| 17 | - use crate::transport::{Command, Transport}; |
| 18 | + use crate::transport::Transport; |
| 19 | |
| 20 | const DEFAULT_LISTEN_ADDR: &str = "127.0.0.1:2525"; |
| 21 | const DEFAULT_GREETING: &str = "Maitred ESMTP Server"; |
| 22 | @@ -282,21 +281,11 @@ mod test { |
| 23 | ) |
| 24 | .await |
| 25 | .unwrap(); |
| 26 | - assert!(session.history.len() == 6); |
| 27 | - assert!(matches!( |
| 28 | - session.history.first().unwrap(), |
| 29 | - Request::Helo { host: _ } |
| 30 | - )); |
| 31 | - assert!(matches!( |
| 32 | - session.history.get(1).unwrap(), |
| 33 | - Request::Mail { from: _ } |
| 34 | - )); |
| 35 | - assert!(matches!( |
| 36 | - session.history.get(2).unwrap(), |
| 37 | - Request::Rcpt { to: _ } |
| 38 | - )); |
| 39 | - assert!(matches!(session.history.get(3).unwrap(), Request::Data {})); |
| 40 | - assert!(matches!(session.history.get(4).unwrap(), Request::Data {})); |
| 41 | - assert!(matches!(session.history.get(5).unwrap(), Request::Quit {})); |
| 42 | + assert!(session |
| 43 | + .mail_from |
| 44 | + .is_some_and(|mail_from| mail_from.get_email() == "fuu@bar.com")); |
| 45 | + assert!(session.rcpt_to.is_some_and(|rcpts| rcpts |
| 46 | + .first() |
| 47 | + .is_some_and(|rcpt_to| rcpt_to.get_email() == "baz@qux.com"))); |
| 48 | } |
| 49 | } |
| 50 | diff --git a/maitred/src/session.rs b/maitred/src/session.rs |
| 51 | index 65ded28..dbaedfc 100644 |
| 52 | --- a/maitred/src/session.rs |
| 53 | +++ b/maitred/src/session.rs |
| 54 | @@ -43,8 +43,6 @@ pub(crate) struct Options { |
| 55 | /// Stateful connection that coresponds to a single SMTP session |
| 56 | #[derive(Default)] |
| 57 | pub(crate) struct Session { |
| 58 | - /// all previous commands excluding |
| 59 | - pub history: Vec<Request<String>>, |
| 60 | /// message body |
| 61 | pub body: Option<Vec<u8>>, |
| 62 | /// mailto address |
| 63 | @@ -58,7 +56,6 @@ pub(crate) struct Session { |
| 64 | |
| 65 | impl Session { |
| 66 | pub fn reset(&mut self) { |
| 67 | - self.history.clear(); |
| 68 | self.body = None; |
| 69 | self.mail_from = None; |
| 70 | self.rcpt_to = None; |
| 71 | @@ -81,7 +78,6 @@ impl Session { |
| 72 | req: &Request<String>, |
| 73 | data: Option<Bytes>, |
| 74 | ) -> Result { |
| 75 | - self.history.push(req.clone()); |
| 76 | match req { |
| 77 | Request::Ehlo { host } => { |
| 78 | self.hostname = Some(Host::parse(host).map_err(|e| { |
| 79 | @@ -315,7 +311,9 @@ mod test { |
| 80 | requests, |
| 81 | ); |
| 82 | // session should contain both requests |
| 83 | - assert!(session.history.len() == 2); |
| 84 | + assert!(session |
| 85 | + .hostname |
| 86 | + .is_some_and(|hostname| hostname.to_string() == EXAMPLE_HOSTNAME)); |
| 87 | } |
| 88 | |
| 89 | #[test] |
| 90 | @@ -341,7 +339,7 @@ mod test { |
| 91 | TestCase { |
| 92 | request: Request::Rcpt { |
| 93 | to: RcptTo { |
| 94 | - address: String::from("fuu@example.org"), |
| 95 | + address: String::from("bar@example.org"), |
| 96 | ..Default::default() |
| 97 | }, |
| 98 | }, |
| 99 | @@ -384,7 +382,12 @@ transport rather than the session. |
| 100 | }, |
| 101 | requests, |
| 102 | ); |
| 103 | - assert!(session.history.len() == 5); |
| 104 | + assert!(session |
| 105 | + .mail_from |
| 106 | + .is_some_and(|mail_from| mail_from.get_email() == "fuu@example.org")); |
| 107 | + assert!(session.rcpt_to.is_some_and(|rcpts| rcpts |
| 108 | + .first() |
| 109 | + .is_some_and(|rcpt_to| rcpt_to.get_email() == "bar@example.org"))); |
| 110 | assert!(session.body.is_some_and(|body| { |
| 111 | let message = MessageParser::new().parse(&body).unwrap(); |
| 112 | message |