From e551e094fd80bf28495e885920d2b88c82e96026 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Wed, 25 Oct 2023 15:57:00 +0200 Subject: [PATCH] Support for IMAP multiline responses in directories --- Cargo.lock | 2 +- UPGRADING.md | 9 +++++---- crates/directory/src/imap/client.rs | 11 +++++++---- crates/managesieve/Cargo.toml | 2 +- tests/src/directory/imap.rs | 6 +++++- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2d471f0..d525badb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2841,7 +2841,7 @@ dependencies = [ [[package]] name = "managesieve" -version = "0.1.0" +version = "0.4.0" dependencies = [ "ahash 0.8.3", "bincode", diff --git a/UPGRADING.md b/UPGRADING.md index c82a02b5..bb8dff5c 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -28,10 +28,11 @@ Upgrading from `v0.3.x` to `v0.4.0` - `etc/jmap/oauth.toml` - `etc/smtp/signature.toml` - `etc/common/tls.toml` -4. **Configure the SPAM Filter Database:** Set up and configure the SPAM filter database. More details can be found [here](https://stalw.art/docs/spamfilter/settings/database). -5. **Review All TOML Files:** Navigate to every TOML file under the `etc/` directory and make necessary changes. -6. **Update Binary:** Download and substitute the v0.4.0 binary suitable for your platform from [here](https://github.com/stalwartlabs/mail-server/releases/tag/v0.4.0). -7. **Restart Service:** Conclude by restarting the Stalwart Mail Server service. +4. **Adjust included files:** If you are using an LDAP directory for authentication, edit `etc/config.toml` and replace the `etc/directory/sql.toml` include with `etc/directory/ldap.toml`. +5. **Configure the SPAM Filter Database:** Set up and configure the SPAM filter database. More details can be found [here](https://stalw.art/docs/spamfilter/settings/database). +6. **Review All TOML Files:** Navigate to every TOML file under the `etc/` directory and make necessary changes. +7. **Update Binary:** Download and substitute the v0.4.0 binary suitable for your platform from [here](https://github.com/stalwartlabs/mail-server/releases/tag/v0.4.0). +8. **Restart Service:** Conclude by restarting the Stalwart Mail Server service. ### Alternative Method: diff --git a/crates/directory/src/imap/client.rs b/crates/directory/src/imap/client.rs index c7fb5683..a2daedc6 100644 --- a/crates/directory/src/imap/client.rs +++ b/crates/directory/src/imap/client.rs @@ -90,12 +90,15 @@ impl ImapClient { tokio::time::timeout(self.timeout, async { self.write(b"C0 CAPABILITY\r\n").await?; - let line = self.read_line().await?; - if !matches!(line.get(..12), Some(b"* CAPABILITY")) { - return Err(ImapError::InvalidResponse(line.into_string())); + let mut line = self.read_line().await?.into_string(); + if !line.starts_with("* CAPABILITY") { + return Err(ImapError::InvalidResponse(line)); + } + while !line.contains("C0 ") { + line.push_str(&self.read_line().await?.into_string()); } - let mut line_iter = line.iter(); + let mut line_iter = line.as_bytes().iter(); let mut parser = Rfc5321Parser::new(&mut line_iter); let mut mechanisms = 0; diff --git a/crates/managesieve/Cargo.toml b/crates/managesieve/Cargo.toml index d76cedce..5500ff67 100644 --- a/crates/managesieve/Cargo.toml +++ b/crates/managesieve/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "managesieve" -version = "0.1.0" +version = "0.4.0" edition = "2021" resolver = "2" diff --git a/tests/src/directory/imap.rs b/tests/src/directory/imap.rs index 453ecab2..933ea975 100644 --- a/tests/src/directory/imap.rs +++ b/tests/src/directory/imap.rs @@ -198,7 +198,11 @@ async fn accept_imap(stream: TcpStream, acceptor: Arc, in_flight: O panic!("Unknown command: {}", buf.trim()); }; //print!("<- {}", response); - stream.write_all(response.as_bytes()).await.unwrap(); + for line in response.split_inclusive('\n') { + stream.write_all(line.as_bytes()).await.unwrap(); + stream.flush().await.unwrap(); + tokio::time::sleep(std::time::Duration::from_millis(100)).await; + } if buf.contains("bye") || buf.starts_with("LOGOUT") { return;