From 33b0a9e27ddf27e0814894f3a20e54208b1507bc Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Fri, 8 May 2020 11:46:25 +0200 Subject: [PATCH] feat(transport-sendmail): Make the command parameter an OsStr --- src/lib.rs | 2 +- src/transport/sendmail/mod.rs | 9 ++++++--- src/transport/smtp/mod.rs | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 59ee1dc..2774525 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ //! * **native-tls**: TLS support with the `native-tls` crate //! * **r2d2**: Connection pool for SMTP transport //! * **log**: Logging using the `log` crate -//! * **serde**: Serilization/Deserialization of entities +//! * **serde**: Serialization/Deserialization of entities //! * **hostname**: Ability to try to use actual hostname in SMTP transaction #![doc(html_root_url = "https://docs.rs/lettre/0.10.0")] diff --git a/src/transport/sendmail/mod.rs b/src/transport/sendmail/mod.rs index 925f62b..b952857 100644 --- a/src/transport/sendmail/mod.rs +++ b/src/transport/sendmail/mod.rs @@ -26,29 +26,32 @@ use crate::{transport::sendmail::error::Error, Envelope, Transport}; use std::{ convert::AsRef, + ffi::OsString, io::prelude::*, process::{Command, Stdio}, }; pub mod error; +const DEFAUT_SENDMAIL: &str = "/usr/sbin/sendmail"; + /// Sends an email using the `sendmail` command #[derive(Debug, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct SendmailTransport { - command: String, + command: OsString, } impl SendmailTransport { /// Creates a new transport with the default `/usr/sbin/sendmail` command pub fn new() -> SendmailTransport { SendmailTransport { - command: "/usr/sbin/sendmail".to_string(), + command: DEFAUT_SENDMAIL.into(), } } /// Creates a new transport to the given sendmail command - pub fn new_with_command>(command: S) -> SendmailTransport { + pub fn new_with_command>(command: S) -> SendmailTransport { SendmailTransport { command: command.into(), } diff --git a/src/transport/smtp/mod.rs b/src/transport/smtp/mod.rs index a958a4d..7c971e6 100644 --- a/src/transport/smtp/mod.rs +++ b/src/transport/smtp/mod.rs @@ -221,6 +221,9 @@ pub const SUBMISSION_PORT: u16 = 587; /// Default submission over TLS port pub const SUBMISSIONS_PORT: u16 = 465; +/// Default timeout +pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); + /// Accepted protocols by default. /// This removes TLS 1.0 and 1.1 compared to tls-native defaults. // This is also rustls' default behavior @@ -286,7 +289,7 @@ impl SmtpTransport { hello_name: ClientId::hostname(), credentials: None, authentication: DEFAULT_MECHANISMS.into(), - timeout: Some(Duration::new(60, 0)), + timeout: Some(DEFAULT_TIMEOUT), tls: Tls::None, #[cfg(feature = "r2d2")] pool: None,