From 6eff9d3beecbdb493d022718f1a6bb01f2ca3f7f Mon Sep 17 00:00:00 2001 From: Daniel Hauser Date: Wed, 18 Sep 2019 20:28:14 +0200 Subject: [PATCH] [Fix] Timeout bug causing infinite hang (#350) --- lettre/src/smtp/client/mod.rs | 7 +++---- lettre/src/smtp/mod.rs | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lettre/src/smtp/client/mod.rs b/lettre/src/smtp/client/mod.rs index 5fd5901..b75e73b 100644 --- a/lettre/src/smtp/client/mod.rs +++ b/lettre/src/smtp/client/mod.rs @@ -144,7 +144,7 @@ impl InnerClient { addr: &A, timeout: Option, tls_parameters: Option<&ClientTlsParameters>, - ) -> SmtpResult { + ) -> Result<(), Error> { // Connect should not be called when the client is already connected if self.stream.is_some() { return_err!("The connection is already established", self); @@ -161,8 +161,7 @@ impl InnerClient { // Try to connect self.set_stream(Connector::connect(&server_addr, timeout, tls_parameters)?); - - self.read_response() + Ok(()) } /// Checks if the server is connected using the NOOP SMTP command @@ -246,7 +245,7 @@ impl InnerClient { } /// Gets the SMTP response - fn read_response(&mut self) -> SmtpResult { + pub fn read_response(&mut self) -> SmtpResult { let mut raw_response = String::new(); let mut response = raw_response.parse::(); diff --git a/lettre/src/smtp/mod.rs b/lettre/src/smtp/mod.rs index 882b90c..58c8d1f 100644 --- a/lettre/src/smtp/mod.rs +++ b/lettre/src/smtp/mod.rs @@ -276,6 +276,7 @@ impl<'a> SmtpTransport { )?; self.client.set_timeout(self.client_info.timeout)?; + let _response = self.client.read_response()?; // Log the connection info!("connection established to {}", self.client_info.server_addr);