]> git.r.bdr.sh - rbdr/olden-mail/commitdiff
Address clippy issues
authorRuben Beltran del Rio <redacted>
Sat, 25 Jan 2025 10:00:29 +0000 (11:00 +0100)
committerRuben Beltran del Rio <redacted>
Sat, 25 Jan 2025 10:00:29 +0000 (11:00 +0100)
README.md
src/configuration.rs
src/main.rs
src/proxy.rs

index 6c580f76f70bef46da991ca892d807b90df44686..9e6e407cc6330daed90fecbdb67b20a640d80f54 100644 (file)
--- a/README.md
+++ b/README.md
@@ -35,22 +35,22 @@ The proxy requires you to set environment variables, but otherwise takes
 no options.
 
 * `LOCAL_IMAP_PORT` u16, the port in which the server will listen for
 no options.
 
 * `LOCAL_IMAP_PORT` u16, the port in which the server will listen for
-IMAP clients. Defaults to 143.
+  IMAP clients. Defaults to 143.
 * `LOCAL_IMAP_BIND_ADDRESS` String, the address on which to listen for
 * `LOCAL_IMAP_BIND_ADDRESS` String, the address on which to listen for
-IMAP clients. Defaults to 0.0.0.0.
+  IMAP clients. Defaults to 0.0.0.0.
 * `REMOTE_IMAP_PORT` u16, the port to which the server will forward the
 * `REMOTE_IMAP_PORT` u16, the port to which the server will forward the
-IMAP messages. Defaults to 993.
+  IMAP messages. Defaults to 993.
 * `REMOTE_IMAP_HOST` String, the host to which the server will forward the
 * `REMOTE_IMAP_HOST` String, the host to which the server will forward the
-IMAP messages. Required.
+  IMAP messages. Required.
 
 * `LOCAL_SMTP_PORT` u16, the port in which the server will listen for
 
 * `LOCAL_SMTP_PORT` u16, the port in which the server will listen for
-SMTP clients. Defaults to 25.
+  SMTP clients. Defaults to 25.
 * `LOCAL_SMTP_BIND_ADDRESS` String, the address on which to listen for
 * `LOCAL_SMTP_BIND_ADDRESS` String, the address on which to listen for
-SMTP clients. Defaults to 0.0.0.0.
+  SMTP clients. Defaults to 0.0.0.0.
 * `REMOTE_SMTP_PORT` u16, the port to which the server will forward the
 * `REMOTE_SMTP_PORT` u16, the port to which the server will forward the
-SMTP messages. Defaults to 465.
+  SMTP messages. Defaults to 465.
 * `REMOTE_SMTP_HOST` String, the host to which the server will forward the
 * `REMOTE_SMTP_HOST` String, the host to which the server will forward the
-SMTP messages. Required.
+  SMTP messages. Required.
 
 This means the minimum invocation is this (Shown here with inline
 environment variables)
 
 This means the minimum invocation is this (Shown here with inline
 environment variables)
index af5c46d815fd54c1bf413a7c74a4aec487cc50e2..49cd991ab8b3a6cd05647c10cddb37eb8ab6d7e0 100644 (file)
@@ -18,7 +18,7 @@ pub enum ConfigurationError {
 
 /// Configuration for any proxy
 #[derive(Debug)]
 
 /// Configuration for any proxy
 #[derive(Debug)]
-pub struct ProxyConfiguration {
+pub struct Proxy {
     pub local_port: u16,
     pub bind_address: String,
     pub remote_host: String,
     pub local_port: u16,
     pub bind_address: String,
     pub remote_host: String,
@@ -28,8 +28,8 @@ pub struct ProxyConfiguration {
 
 /// Aggregated configuration for both proxies, already in a reference counter.
 pub struct Configuration {
 
 /// Aggregated configuration for both proxies, already in a reference counter.
 pub struct Configuration {
-    pub imap_configuration: Arc<ProxyConfiguration>,
-    pub smtp_configuration: Arc<ProxyConfiguration>,
+    pub imap_configuration: Arc<Proxy>,
+    pub smtp_configuration: Arc<Proxy>,
 }
 
 impl Configuration {
 }
 
 impl Configuration {
@@ -37,14 +37,14 @@ impl Configuration {
     /// variables. Exits if the right ones aren't found.
     pub fn new() -> Result<Self, ConfigurationError> {
         Ok(Configuration {
     /// variables. Exits if the right ones aren't found.
     pub fn new() -> Result<Self, ConfigurationError> {
         Ok(Configuration {
-            imap_configuration: Arc::new(ProxyConfiguration {
+            imap_configuration: Arc::new(Proxy {
                 local_port: get_env_number("LOCAL_IMAP_PORT", 143)?,
                 bind_address: get_env_var("LOCAL_IMAP_BIND_ADDRESS", Some("0.0.0.0".to_string()))?,
                 remote_host: get_env_var("REMOTE_IMAP_DOMAIN", None)?,
                 remote_port: get_env_number("REMOTE_IMAP_PORT", 993)?,
                 protocol: "IMAP",
             }),
                 local_port: get_env_number("LOCAL_IMAP_PORT", 143)?,
                 bind_address: get_env_var("LOCAL_IMAP_BIND_ADDRESS", Some("0.0.0.0".to_string()))?,
                 remote_host: get_env_var("REMOTE_IMAP_DOMAIN", None)?,
                 remote_port: get_env_number("REMOTE_IMAP_PORT", 993)?,
                 protocol: "IMAP",
             }),
-            smtp_configuration: Arc::new(ProxyConfiguration {
+            smtp_configuration: Arc::new(Proxy {
                 local_port: get_env_number("LOCAL_SMTP_PORT", 25)?,
                 bind_address: get_env_var("LOCAL_SMTP_BIND_ADDRESS", Some("0.0.0.0".to_string()))?,
                 remote_host: get_env_var("REMOTE_SMTP_DOMAIN", None)?,
                 local_port: get_env_number("LOCAL_SMTP_PORT", 25)?,
                 bind_address: get_env_var("LOCAL_SMTP_BIND_ADDRESS", Some("0.0.0.0".to_string()))?,
                 remote_host: get_env_var("REMOTE_SMTP_DOMAIN", None)?,
index 863b2eef928240c9ba809f8ea8f1967af6d6d635..87ae7382922a14e5ddc1e5e7a0fb6ef35d1d066c 100644 (file)
@@ -11,8 +11,8 @@
 //!
 //! ### Pre-built binaries and packages
 //!
 //!
 //! ### Pre-built binaries and packages
 //!
-//! Binaries are available for macos and linux, for both aarch64 and x86_64
-//! from https://build.r.bdr.sh/olden-mail, including `.deb` and `.rpm`
+//! Binaries are available for macos and linux, for both aarch64 and `x86_64`
+//! from <https://build.r.bdr.sh/olden-mail>, including `.deb` and `.rpm`
 //! packages.
 //!
 //! ### Homebrew
 //! packages.
 //!
 //! ### Homebrew
 //! no options.
 //!
 //! * `LOCAL_IMAP_PORT` u16, the port in which the server will listen for
 //! no options.
 //!
 //! * `LOCAL_IMAP_PORT` u16, the port in which the server will listen for
-//! IMAP clients. Defaults to 143.
+//!   IMAP clients. Defaults to 143.
 //! * `LOCAL_IMAP_BIND_ADDRESS` String, the address on which to listen for
 //! * `LOCAL_IMAP_BIND_ADDRESS` String, the address on which to listen for
-//! IMAP clients. Defaults to 0.0.0.0.
+//!   IMAP clients. Defaults to 0.0.0.0.
 //! * `REMOTE_IMAP_PORT` u16, the port to which the server will forward the
 //! * `REMOTE_IMAP_PORT` u16, the port to which the server will forward the
-//! IMAP messages. Defaults to 993.
+//!   IMAP messages. Defaults to 993.
 //! * `REMOTE_IMAP_HOST` String, the host to which the server will forward the
 //! * `REMOTE_IMAP_HOST` String, the host to which the server will forward the
-//! IMAP messages. Required.
+//!   IMAP messages. Required.
 //!
 //! * `LOCAL_SMTP_PORT` u16, the port in which the server will listen for
 //!
 //! * `LOCAL_SMTP_PORT` u16, the port in which the server will listen for
-//! SMTP clients. Defaults to 25.
+//!   SMTP clients. Defaults to 25.
 //! * `LOCAL_SMTP_BIND_ADDRESS` String, the address on which to listen for
 //! * `LOCAL_SMTP_BIND_ADDRESS` String, the address on which to listen for
-//! SMTP clients. Defaults to 0.0.0.0.
+//!   SMTP clients. Defaults to 0.0.0.0.
 //! * `REMOTE_SMTP_PORT` u16, the port to which the server will forward the
 //! * `REMOTE_SMTP_PORT` u16, the port to which the server will forward the
-//! SMTP messages. Defaults to 465.
+//!   SMTP messages. Defaults to 465.
 //! * `REMOTE_SMTP_HOST` String, the host to which the server will forward the
 //! * `REMOTE_SMTP_HOST` String, the host to which the server will forward the
-//! SMTP messages. Required.
+//!   SMTP messages. Required.
 //!
 //! This means the minimum invocation is this (Shown here with inline
 //! environment variables)
 //!
 //! This means the minimum invocation is this (Shown here with inline
 //! environment variables)
@@ -74,7 +74,7 @@ mod configuration;
 mod proxy;
 
 use configuration::Configuration;
 mod proxy;
 
 use configuration::Configuration;
-use proxy::ProxyServer;
+use proxy::Server;
 
 fn main() {
     Builder::from_env(Env::default().default_filter_or("info"))
 
 fn main() {
     Builder::from_env(Env::default().default_filter_or("info"))
@@ -88,8 +88,8 @@ fn main() {
 
     let (tx, rx) = mpsc::channel();
 
 
     let (tx, rx) = mpsc::channel();
 
-    let mut imap_proxy = ProxyServer::new(configuration.imap_configuration);
-    let mut smtp_proxy = ProxyServer::new(configuration.smtp_configuration);
+    let mut imap_proxy = Server::new(configuration.imap_configuration);
+    let mut smtp_proxy = Server::new(configuration.smtp_configuration);
 
     ctrlc::set_handler(move || {
         info!("Shutting down...");
 
     ctrlc::set_handler(move || {
         info!("Shutting down...");
index c6954a06c11e5867aab8f831c6e8f7868135a7ba..a2f62e4bac4a8697a17e26a4bd41c6b3b023f818 100644 (file)
@@ -1,7 +1,7 @@
 //! # Proxy Module
 //!
 //! This module has the actual proxy functionality, exposed through
 //! # Proxy Module
 //!
 //! This module has the actual proxy functionality, exposed through
-//! `ProxyServer`. The proxy consists of a local unencrypted TCP stream
+//! `Server`. The proxy consists of a local unencrypted TCP stream
 //! and a remote TLS stream. Messages are passed between them via two
 //! threads.
 //!
 //! and a remote TLS stream. Messages are passed between them via two
 //! threads.
 //!
@@ -9,24 +9,24 @@
 //! - **Client to Server Thread**: Forwards data from client -> TLS server
 //! - **Serveer to Client Thread**: Forwards data from TLS server -> client
 //!
 //! - **Client to Server Thread**: Forwards data from client -> TLS server
 //! - **Serveer to Client Thread**: Forwards data from TLS server -> client
 //!
-//! Finally, the ProxyServer may be shutdown by calling `.shutdown()`,
+//! Finally, the `Server` may be shutdown by calling `.shutdown()`,
 //! this will stop new connections and wait for it to finish.
 //!
 //! # Example
 //!
 //! ```
 //! use std::sync::Arc;
 //! this will stop new connections and wait for it to finish.
 //!
 //! # Example
 //!
 //! ```
 //! use std::sync::Arc;
-//! use crate::configuration::ProxyConfiguration;
-//! use crate::proxy::ProxyServer;
+//! use crate::configuration::Proxy;
+//! use crate::proxy::Server;
 //!
 //!
-//! let config = Arc::new(ProxyConfiguration {
+//! let config = Arc::new(Proxy {
 //!     protocol: "IMAP".to_string(),
 //!     local_port: 143,
 //!     remote_domain: "imap.example.com".to_string(),
 //!     remote_port: 993,
 //! });
 //!
 //!     protocol: "IMAP".to_string(),
 //!     local_port: 143,
 //!     remote_domain: "imap.example.com".to_string(),
 //!     remote_port: 993,
 //! });
 //!
-//! let mut server = ProxyServer::new(config);
+//! let mut server = Server::new(config);
 //! // The server runs in a background thread. To shut down gracefully:
 //! server.shutdown();
 //! ```
 //! // The server runs in a background thread. To shut down gracefully:
 //! server.shutdown();
 //! ```
@@ -41,33 +41,33 @@ use std::sync::{
 use std::thread::{sleep, spawn, JoinHandle};
 use std::time::Duration;
 
 use std::thread::{sleep, spawn, JoinHandle};
 use std::time::Duration;
 
-use crate::configuration::ProxyConfiguration;
+use crate::configuration::Proxy;
 
 /// A proxy server that listens for plaintext connections and forwards them
 /// via TLS.
 ///
 
 /// A proxy server that listens for plaintext connections and forwards them
 /// via TLS.
 ///
-/// Creating a new `ProxyServer` spawns a dedicated thread that:
+/// Creating a new `Server` spawns a dedicated thread that:
 /// - Binds to a local port (non-blocking mode).
 /// - Spawns additional threads for each incoming client connection.
 /// - Manages connection-lifetime until it receives a shutdown signal.
 /// - Binds to a local port (non-blocking mode).
 /// - Spawns additional threads for each incoming client connection.
 /// - Manages connection-lifetime until it receives a shutdown signal.
-pub struct ProxyServer {
+pub struct Server {
     running: Arc<AtomicBool>,
     thread_handle: Option<JoinHandle<()>>,
 }
 
     running: Arc<AtomicBool>,
     thread_handle: Option<JoinHandle<()>>,
 }
 
-impl ProxyServer {
-    /// Creates a new `ProxyServer` for the given `ProxyConfiguration` and
+impl Server {
+    /// Creates a new `Server` for the given `Proxy` configuration and
     /// immediately starts it.
     ///
     /// # Arguments
     ///
     /// immediately starts it.
     ///
     /// # Arguments
     ///
-    /// * `configuration` - Shared (Arc) `ProxyConfiguration`
+    /// * `configuration` - Shared (Arc) `Proxy`
     ///
     /// # Returns
     ///
     ///
     /// # Returns
     ///
-    /// A `ProxyServer` instance that will keep running until its `.shutdown()`
+    /// A `Server` instance that will keep running until its `.shutdown()`
     /// method is called, or an error occurs.
     /// method is called, or an error occurs.
-    pub fn new(configuration: Arc<ProxyConfiguration>) -> Self {
+    pub fn new(configuration: Arc<Proxy>) -> Self {
         let running = Arc::new(AtomicBool::new(true));
         let running_clone = Arc::clone(&running);
 
         let running = Arc::new(AtomicBool::new(true));
         let running_clone = Arc::clone(&running);
 
@@ -75,7 +75,7 @@ impl ProxyServer {
             run_proxy(configuration, running_clone);
         });
 
             run_proxy(configuration, running_clone);
         });
 
-        ProxyServer {
+        Server {
             running,
             thread_handle: Some(thread_handle),
         }
             running,
             thread_handle: Some(thread_handle),
         }
@@ -93,7 +93,7 @@ impl ProxyServer {
 
 /// The main loop that listens for incoming (plaintext) connections on
 /// `configuration.bind_address:configuration.local_port`.
 
 /// The main loop that listens for incoming (plaintext) connections on
 /// `configuration.bind_address:configuration.local_port`.
-fn run_proxy(configuration: Arc<ProxyConfiguration>, running: Arc<AtomicBool>) {
+fn run_proxy(configuration: Arc<Proxy>, running: Arc<AtomicBool>) {
     let listener = match TcpListener::bind(format!(
         "{}:{}",
         configuration.bind_address, configuration.local_port
     let listener = match TcpListener::bind(format!(
         "{}:{}",
         configuration.bind_address, configuration.local_port
@@ -152,7 +152,7 @@ fn run_proxy(configuration: Arc<ProxyConfiguration>, running: Arc<AtomicBool>) {
 }
 
 /// Handles a single client connection by bridging it (plaintext) to a TLS connection.
 }
 
 /// Handles a single client connection by bridging it (plaintext) to a TLS connection.
-fn handle_client(client_stream: TcpStream, configuration: Arc<ProxyConfiguration>) {
+fn handle_client(client_stream: TcpStream, configuration: Arc<Proxy>) {
     if let Err(e) = client_stream.set_nonblocking(true) {
         error!("Failed to set client stream to nonblocking: {}", e);
         return;
     if let Err(e) = client_stream.set_nonblocking(true) {
         error!("Failed to set client stream to nonblocking: {}", e);
         return;