diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e85963f..10f42a08d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Fetch messages in order of their INTERNALDATE (fixes reactions for Gmail f.e.) #3789 - python: do not pass NULL to ffi.gc if the context can't be created #3818 - Add read/write timeouts to IMAP sockets #3820 +- Add connection timeout to IMAP sockets #3828 ## 1.102.0 diff --git a/src/imap/client.rs b/src/imap/client.rs index badf178d7..70e7b02a4 100644 --- a/src/imap/client.rs +++ b/src/imap/client.rs @@ -10,6 +10,7 @@ use async_imap::Session as ImapSession; use async_smtp::ServerAddress; use tokio::net::{self, TcpStream}; +use tokio::time::timeout; use tokio_io_timeout::TimeoutStream; use super::capabilities::Capabilities; @@ -96,7 +97,7 @@ impl Client { domain: &str, strict_tls: bool, ) -> Result { - let tcp_stream = TcpStream::connect(addr).await?; + let tcp_stream = timeout(IMAP_TIMEOUT, TcpStream::connect(addr)).await??; let mut timeout_stream = TimeoutStream::new(tcp_stream); timeout_stream.set_write_timeout(Some(IMAP_TIMEOUT)); timeout_stream.set_read_timeout(Some(IMAP_TIMEOUT)); @@ -119,7 +120,7 @@ impl Client { } pub async fn connect_insecure(addr: impl net::ToSocketAddrs) -> Result { - let tcp_stream = TcpStream::connect(addr).await?; + let tcp_stream = timeout(IMAP_TIMEOUT, TcpStream::connect(addr)).await??; let mut timeout_stream = TimeoutStream::new(tcp_stream); timeout_stream.set_write_timeout(Some(IMAP_TIMEOUT)); timeout_stream.set_read_timeout(Some(IMAP_TIMEOUT));