]> git.r.bdr.sh - rbdr/olden-mail/blobdiff - src/proxy.rs
Bump version
[rbdr/olden-mail] / src / proxy.rs
index 15a2e7d19736e52330e01661971fb2d907179cd7..2798df372642f4abf497706ab8ad9cbe8624489a 100644 (file)
@@ -42,6 +42,7 @@ use std::thread::{sleep, spawn, JoinHandle};
 use std::time::Duration;
 
 use crate::configuration::Proxy;
+use crate::middleware::MIDDLEWARE;
 
 /// A proxy server that listens for plaintext connections and forwards them
 /// via TLS.
@@ -213,7 +214,6 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
         let mut buffer = [0u8; 8192];
         let mut client_reader = client_stream;
         loop {
-            debug!(">");
             let bytes_read = match client_reader.read(&mut buffer) {
                 Ok(0) => break,
                 Ok(n) => n,
@@ -227,7 +227,13 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
                 }
             };
 
-            let debug_str = String::from_utf8_lossy(&buffer[..bytes_read])
+            let mut command = buffer[..bytes_read].to_vec();
+
+            for middleware in MIDDLEWARE {
+                command = middleware(&command);
+            }
+
+            let debug_str = String::from_utf8_lossy(&command)
                 .replace('\n', "\\n")
                 .replace('\r', "\\r")
                 .replace('\t', "\\t");
@@ -260,7 +266,6 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
         let mut buffer = [0u8; 8192];
         let mut client_writer = client_stream_clone;
         loop {
-            debug!("<");
             // Lock the TLS stream and read from the server
             let bytes_read = match tls_stream_clone.lock() {
                 Ok(mut tls_guard) => match tls_guard.read(&mut buffer) {