diff --git a/src/message/header/mod.rs b/src/message/header/mod.rs index 5e0a025..687cdf7 100644 --- a/src/message/header/mod.rs +++ b/src/message/header/mod.rs @@ -26,6 +26,9 @@ mod mailbox; mod special; mod textual; +/// Represents an email header +/// +/// Email header as defined in [RFC5322](https://datatracker.ietf.org/doc/html/rfc5322) and extensions. pub trait Header: Clone { fn name() -> HeaderName; diff --git a/src/message/header/special.rs b/src/message/header/special.rs index 1929bac..4b5ea01 100644 --- a/src/message/header/special.rs +++ b/src/message/header/special.rs @@ -10,6 +10,9 @@ pub struct MimeVersion { minor: u8, } +/// MIME version 1.0 +/// +/// Should be used in all MIME messages. pub const MIME_VERSION_1_0: MimeVersion = MimeVersion::new(1, 0); impl MimeVersion { diff --git a/src/transport/smtp/authentication.rs b/src/transport/smtp/authentication.rs index 36b766b..0a3799b 100644 --- a/src/transport/smtp/authentication.rs +++ b/src/transport/smtp/authentication.rs @@ -4,6 +4,7 @@ use crate::transport::smtp::error::{self, Error}; use std::fmt::{self, Debug, Display, Formatter}; /// Accepted authentication mechanisms +/// /// Trying LOGIN last as it is deprecated. pub const DEFAULT_MECHANISMS: &[Mechanism] = &[Mechanism::Plain, Mechanism::Login]; diff --git a/src/transport/smtp/client/async_connection.rs b/src/transport/smtp/client/async_connection.rs index d3114d9..2d459bb 100644 --- a/src/transport/smtp/client/async_connection.rs +++ b/src/transport/smtp/client/async_connection.rs @@ -298,7 +298,7 @@ impl AsyncSmtpConnection { return if response.is_positive() { Ok(response) } else { - Err(error::code(response.code)) + Err(error::code(response.code())) } } Err(nom::Err::Failure(e)) => { diff --git a/src/transport/smtp/client/connection.rs b/src/transport/smtp/client/connection.rs index 25676de..e73b50c 100644 --- a/src/transport/smtp/client/connection.rs +++ b/src/transport/smtp/client/connection.rs @@ -276,7 +276,7 @@ impl SmtpConnection { return if response.is_positive() { Ok(response) } else { - Err(error::code(response.code)) + Err(error::code(response.code())) }; } Err(nom::Err::Failure(e)) => { diff --git a/src/transport/smtp/extension.rs b/src/transport/smtp/extension.rs index 3ea4195..2c88126 100644 --- a/src/transport/smtp/extension.rs +++ b/src/transport/smtp/extension.rs @@ -72,6 +72,7 @@ impl ClientId { /// Supported ESMTP keywords #[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[non_exhaustive] pub enum Extension { /// 8BITMIME keyword /// @@ -107,11 +108,11 @@ pub struct ServerInfo { /// Server name /// /// The name given in the server banner - pub name: String, + name: String, /// ESMTP features supported by the server /// /// It contains the features supported by the server and known by the `Extension` module. - pub features: HashSet, + features: HashSet, } impl Display for ServerInfo { @@ -135,7 +136,7 @@ impl ServerInfo { let mut features: HashSet = HashSet::new(); - for line in response.message.as_slice() { + for line in response.message() { if line.is_empty() { continue; } @@ -197,6 +198,11 @@ impl ServerInfo { } None } + + /// The name given in the server banner + pub fn name(&self) -> &str { + self.name.as_ref() + } } /// A `MAIL FROM` extension parameter diff --git a/src/transport/smtp/mod.rs b/src/transport/smtp/mod.rs index fb62409..7292f2e 100644 --- a/src/transport/smtp/mod.rs +++ b/src/transport/smtp/mod.rs @@ -148,7 +148,7 @@ pub mod extension; mod pool; pub mod response; mod transport; -pub mod util; +pub(super) mod util; // Registered port numbers: // https://www.iana. @@ -164,7 +164,7 @@ pub const SUBMISSION_PORT: u16 = 587; pub const SUBMISSIONS_PORT: u16 = 465; /// Default timeout -pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); +const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); #[derive(Debug, Clone)] struct SmtpInfo { diff --git a/src/transport/smtp/response.rs b/src/transport/smtp/response.rs index 7993803..a780aae 100644 --- a/src/transport/smtp/response.rs +++ b/src/transport/smtp/response.rs @@ -137,10 +137,10 @@ impl Code { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Response { /// Response code - pub code: Code, + code: Code, /// Server response string (optional) /// Handle multiline responses - pub message: Vec, + message: Vec, } impl FromStr for Response { @@ -180,6 +180,16 @@ impl Response { pub fn first_line(&self) -> Option<&str> { self.message.first().map(String::as_str) } + + /// Response code + pub fn code(&self) -> Code { + self.code + } + + /// Server response string (array of lines) + pub fn message(&self) -> impl Iterator { + self.message.iter().map(String::as_str) + } } // Parsers (originally from tokio-smtp) diff --git a/src/transport/smtp/util.rs b/src/transport/smtp/util.rs index 959a210..44bef0c 100644 --- a/src/transport/smtp/util.rs +++ b/src/transport/smtp/util.rs @@ -4,7 +4,6 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; /// Encode a string as xtext #[derive(Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct XText<'a>(pub &'a str); impl<'a> Display for XText<'a> {