Skip to content

Commit

Permalink
v0.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Dec 30, 2023
1 parent 68114ec commit 33ba892
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mail-send 0.4.5
mail-send 0.4.6
================================
- Improved transparency procedure to also escape <CR>.
- Removed `skip-ehlo` feature.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mail-send"
description = "E-mail delivery library with SMTP and DKIM support"
version = "0.4.5"
version = "0.4.6"
edition = "2021"
authors = [ "Stalwart Labs <hello@stalw.art>"]
license = "Apache-2.0 OR MIT"
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub struct SmtpClientBuilder<T: AsRef<str> + PartialEq + Eq + Hash> {
pub credentials: Option<Credentials<T>>,
pub addr: String,
pub is_lmtp: bool,
pub say_ehlo: bool,
pub local_host: String,
}

Expand Down
46 changes: 17 additions & 29 deletions src/smtp/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl<T: AsRef<str> + PartialEq + Eq + Hash> SmtpClientBuilder<T> {
.unwrap_or("[127.0.0.1]")
.to_string(),
credentials: None,
say_ehlo: true,
}
}

Expand All @@ -56,6 +57,12 @@ impl<T: AsRef<str> + PartialEq + Eq + Hash> SmtpClientBuilder<T> {
self
}

// Say EHLO/LHLO
pub fn say_ehlo(mut self, say_ehlo: bool) -> Self {
self.say_ehlo = say_ehlo;
self
}

/// Set the EHLO/LHLO hostname
pub fn helo_host(mut self, host: impl Into<String>) -> Self {
self.local_host = host.into();
Expand All @@ -76,15 +83,6 @@ impl<T: AsRef<str> + PartialEq + Eq + Hash> SmtpClientBuilder<T> {

/// Connect over TLS
pub async fn connect(&self) -> crate::Result<SmtpClient<TlsStream<TcpStream>>> {
self.connect_opts(true).await
}

/// Connect over TLS specifying whether to say hello
#[allow(unused_mut)]
pub async fn connect_opts(
&self,
say_hello: bool,
) -> crate::Result<SmtpClient<TlsStream<TcpStream>>> {
tokio::time::timeout(self.timeout, async {
let mut client = SmtpClient {
stream: TcpStream::connect(&self.addr).await?,
Expand Down Expand Up @@ -117,13 +115,13 @@ impl<T: AsRef<str> + PartialEq + Eq + Hash> SmtpClientBuilder<T> {
}
};

// Authenticate
if let Some(credentials) = &self.credentials {
if self.say_ehlo {
// Obtain capabilities
let capabilities = client.capabilities(&self.local_host, self.is_lmtp).await?;
client.authenticate(&credentials, &capabilities).await?;
} else if say_hello {
client.capabilities(&self.local_host, self.is_lmtp).await?;
// Authenticate
if let Some(credentials) = &self.credentials {
client.authenticate(&credentials, &capabilities).await?;
}
}

Ok(client)
Expand All @@ -134,15 +132,6 @@ impl<T: AsRef<str> + PartialEq + Eq + Hash> SmtpClientBuilder<T> {

/// Connect over clear text (should not be used)
pub async fn connect_plain(&self) -> crate::Result<SmtpClient<TcpStream>> {
self.connect_plain_opts(true).await
}

/// Connect over clear text specifying whether to say hello
#[allow(unused_mut)]
pub async fn connect_plain_opts(
&self,
say_hello: bool,
) -> crate::Result<SmtpClient<TcpStream>> {
let mut client = SmtpClient {
stream: tokio::time::timeout(self.timeout, async {
TcpStream::connect(&self.addr).await
Expand All @@ -155,14 +144,13 @@ impl<T: AsRef<str> + PartialEq + Eq + Hash> SmtpClientBuilder<T> {
// Read greeting
client.read().await?.assert_positive_completion()?;

// Authenticate
if let Some(credentials) = &self.credentials {
if self.say_ehlo {
// Obtain capabilities
let capabilities = client.capabilities(&self.local_host, self.is_lmtp).await?;

client.authenticate(&credentials, &capabilities).await?;
} else if say_hello {
client.capabilities(&self.local_host, self.is_lmtp).await?;
// Authenticate
if let Some(credentials) = &self.credentials {
client.authenticate(&credentials, &capabilities).await?;
}
}

Ok(client)
Expand Down

0 comments on commit 33ba892

Please sign in to comment.