mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 14:56:33 +03:00
Set read/write timeouts for IMAP sockets
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
- refactor peerstate handling to ensure no duplicate peerstates #3776
|
- refactor peerstate handling to ensure no duplicate peerstates #3776
|
||||||
- Fetch messages in order of their INTERNALDATE (fixes reactions for Gmail f.e.) #3789
|
- 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
|
- python: do not pass NULL to ffi.gc if the context can't be created #3818
|
||||||
|
- Add read/write timeouts to IMAP sockets #3820
|
||||||
|
|
||||||
|
|
||||||
## 1.102.0
|
## 1.102.0
|
||||||
|
|||||||
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -929,6 +929,7 @@ dependencies = [
|
|||||||
"textwrap",
|
"textwrap",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-io-timeout",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tokio-tar",
|
"tokio-tar",
|
||||||
"toml",
|
"toml",
|
||||||
@@ -3550,6 +3551,16 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-io-timeout"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf"
|
||||||
|
dependencies = [
|
||||||
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-macros"
|
name = "tokio-macros"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ textwrap = "0.16.0"
|
|||||||
async-channel = "1.8.0"
|
async-channel = "1.8.0"
|
||||||
futures-lite = "1.12.0"
|
futures-lite = "1.12.0"
|
||||||
tokio-stream = { version = "0.1.11", features = ["fs"] }
|
tokio-stream = { version = "0.1.11", features = ["fs"] }
|
||||||
|
tokio-io-timeout = "1.2.0"
|
||||||
reqwest = { version = "0.11.13", features = ["json"] }
|
reqwest = { version = "0.11.13", features = ["json"] }
|
||||||
async_zip = { version = "0.0.9", default-features = false, features = ["deflate"] }
|
async_zip = { version = "0.0.9", default-features = false, features = ["deflate"] }
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use async_imap::Session as ImapSession;
|
|||||||
|
|
||||||
use async_smtp::ServerAddress;
|
use async_smtp::ServerAddress;
|
||||||
use tokio::net::{self, TcpStream};
|
use tokio::net::{self, TcpStream};
|
||||||
|
use tokio_io_timeout::TimeoutStream;
|
||||||
|
|
||||||
use super::capabilities::Capabilities;
|
use super::capabilities::Capabilities;
|
||||||
use super::session::Session;
|
use super::session::Session;
|
||||||
@@ -95,9 +96,15 @@ impl Client {
|
|||||||
domain: &str,
|
domain: &str,
|
||||||
strict_tls: bool,
|
strict_tls: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let stream = TcpStream::connect(addr).await?;
|
let tcp_stream = TcpStream::connect(addr).await?;
|
||||||
|
let mut timeout_stream = TimeoutStream::new(tcp_stream);
|
||||||
|
timeout_stream.set_write_timeout(Some(Duration::new(IMAP_TIMEOUT, 0)));
|
||||||
|
timeout_stream.set_read_timeout(Some(Duration::new(IMAP_TIMEOUT, 0)));
|
||||||
|
let timeout_stream = Box::pin(timeout_stream);
|
||||||
|
|
||||||
let tls = build_tls(strict_tls);
|
let tls = build_tls(strict_tls);
|
||||||
let tls_stream: Box<dyn SessionStream> = Box::new(tls.connect(domain, stream).await?);
|
let tls_stream: Box<dyn SessionStream> =
|
||||||
|
Box::new(tls.connect(domain, timeout_stream).await?);
|
||||||
let mut client = ImapClient::new(tls_stream);
|
let mut client = ImapClient::new(tls_stream);
|
||||||
|
|
||||||
let _greeting = client
|
let _greeting = client
|
||||||
@@ -112,7 +119,12 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect_insecure(addr: impl net::ToSocketAddrs) -> Result<Self> {
|
pub async fn connect_insecure(addr: impl net::ToSocketAddrs) -> Result<Self> {
|
||||||
let stream: Box<dyn SessionStream> = Box::new(TcpStream::connect(addr).await?);
|
let tcp_stream = TcpStream::connect(addr).await?;
|
||||||
|
let mut timeout_stream = TimeoutStream::new(tcp_stream);
|
||||||
|
timeout_stream.set_write_timeout(Some(Duration::new(IMAP_TIMEOUT, 0)));
|
||||||
|
timeout_stream.set_read_timeout(Some(Duration::new(IMAP_TIMEOUT, 0)));
|
||||||
|
let timeout_stream = Box::pin(timeout_stream);
|
||||||
|
let stream: Box<dyn SessionStream> = Box::new(timeout_stream);
|
||||||
|
|
||||||
let mut client = ImapClient::new(stream);
|
let mut client = ImapClient::new(stream);
|
||||||
let _greeting = client
|
let _greeting = client
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
use std::pin::Pin;
|
||||||
|
|
||||||
use async_imap::types::Mailbox;
|
use async_imap::types::Mailbox;
|
||||||
use async_imap::Session as ImapSession;
|
use async_imap::Session as ImapSession;
|
||||||
use async_native_tls::TlsStream;
|
use async_native_tls::TlsStream;
|
||||||
use fast_socks5::client::Socks5Stream;
|
use fast_socks5::client::Socks5Stream;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
|
use tokio_io_timeout::TimeoutStream;
|
||||||
|
|
||||||
use super::capabilities::Capabilities;
|
use super::capabilities::Capabilities;
|
||||||
|
|
||||||
@@ -29,8 +31,10 @@ pub(crate) trait SessionStream:
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SessionStream for TlsStream<Box<dyn SessionStream>> {}
|
impl SessionStream for TlsStream<Box<dyn SessionStream>> {}
|
||||||
|
impl SessionStream for TlsStream<Pin<Box<TimeoutStream<TcpStream>>>> {}
|
||||||
impl SessionStream for TlsStream<TcpStream> {}
|
impl SessionStream for TlsStream<TcpStream> {}
|
||||||
impl SessionStream for TcpStream {}
|
impl SessionStream for TcpStream {}
|
||||||
|
impl SessionStream for Pin<Box<TimeoutStream<TcpStream>>> {}
|
||||||
impl SessionStream for Socks5Stream<TcpStream> {}
|
impl SessionStream for Socks5Stream<TcpStream> {}
|
||||||
|
|
||||||
impl Deref for Session {
|
impl Deref for Session {
|
||||||
|
|||||||
Reference in New Issue
Block a user