Author: Kevin Schoon [me@kevinschoon.com]
Hash: ba4ff053d4402c488289a822033bef70a2535d86
Timestamp: Sat, 03 Aug 2024 15:58:34 +0000 (2 months ago)

+9 -15 +/-3 browse
change request payload to be a ref
1diff --git a/maitred/src/pipeline.rs b/maitred/src/pipeline.rs
2index b791b4c..e07791f 100644
3--- a/maitred/src/pipeline.rs
4+++ b/maitred/src/pipeline.rs
5 @@ -1,7 +1,7 @@
6 use std::result::Result as StdResult;
7
8- use crate::session::{Result as SessionResult, Session};
9- use crate::{smtp_err, smtp_ok, Request, SmtpResponse};
10+ use crate::session::Result as SessionResult;
11+ use crate::Request;
12
13 pub type Result = StdResult<Option<Vec<SessionResult>>, Vec<SessionResult>>;
14 pub type Transaction = (Request<String>, SessionResult);
15 @@ -11,16 +11,9 @@ pub type Transaction = (Request<String>, SessionResult);
16 #[derive(Default)]
17 pub struct Pipeline {
18 history: Vec<Transaction>,
19- disable: bool,
20 }
21
22 impl Pipeline {
23- /// disable pipelining and return each each transaction transparently
24- pub fn disable(mut self) -> Self {
25- self.disable = true;
26- self
27- }
28-
29 /// Checks if the pipeline is within a data transaction (if the previous
30 /// command was DATA/BDAT).
31 fn within_tx(&self) -> bool {
32 @@ -155,7 +148,7 @@ impl Pipeline {
33 mod test {
34
35 use super::*;
36- use crate::{smtp_err, smtp_ok, Request, Response, SmtpResponse};
37+ use crate::{smtp_ok, Request, Response, SmtpResponse};
38
39 #[test]
40 pub fn test_pipeline_basic() {
41 diff --git a/maitred/src/server.rs b/maitred/src/server.rs
42index c78f4f9..0afa22d 100644
43--- a/maitred/src/server.rs
44+++ b/maitred/src/server.rs
45 @@ -7,6 +7,7 @@ use tokio_stream::StreamExt;
46 use tokio_util::codec::Framed;
47
48 use crate::error::Error;
49+ use crate::pipeline::Pipeline;
50 use crate::session::{Options as SessionOptions, Session};
51 use crate::transport::Transport;
52
53 @@ -143,7 +144,7 @@ impl Server {
54 if matches!(command.0, Request::Quit) {
55 finished = true;
56 }
57- match session.process(&opts, &command.0, command.1) {
58+ match session.process(&opts, &command.0, &command.1) {
59 Ok(resp) => {
60 tracing::debug!("Returning response: {:?}", resp);
61 framed.send(resp).await?;
62 diff --git a/maitred/src/session.rs b/maitred/src/session.rs
63index dbaedfc..5498515 100644
64--- a/maitred/src/session.rs
65+++ b/maitred/src/session.rs
66 @@ -76,7 +76,7 @@ impl Session {
67 &mut self,
68 opts: &Options,
69 req: &Request<String>,
70- data: Option<Bytes>,
71+ data: &Option<Bytes>,
72 ) -> Result {
73 match req {
74 Request::Ehlo { host } => {
75 @@ -134,7 +134,7 @@ impl Session {
76 }
77 DataTransfer::Bdat => {
78 let message_payload =
79- data.expect("data returned without a payload").to_vec();
80+ data.as_ref().expect("data returned without a payload").to_vec();
81 let parser = MessageParser::new();
82 let response = match parser.parse(&message_payload) {
83 Some(_) => smtp_ok!(250, 0, 0, 0, "OK"),
84 @@ -189,7 +189,7 @@ impl Session {
85 }
86 DataTransfer::Data => {
87 let message_payload =
88- data.expect("data returned without a payload").to_vec();
89+ data.as_ref().expect("data returned without a payload").to_vec();
90 let parser = MessageParser::new();
91 let response = match parser.parse(&message_payload) {
92 Some(_) => smtp_ok!(250, 0, 0, 0, "OK".to_string()),
93 @@ -245,7 +245,7 @@ mod test {
94 fn process_all(session: &mut Session, opts: &Options, commands: &[TestCase]) {
95 commands.iter().enumerate().for_each(|(i, command)| {
96 println!("Running command {}/{}", i, commands.len());
97- let response = session.process(opts, &command.request, command.payload.clone());
98+ let response = session.process(opts, &command.request, &command.payload);
99 println!("Response: {:?}", response);
100 match response {
101 Ok(actual_response) => {