Skip to content

Commit 7884882

Browse files
committed
feat: IMAP COMPRESS support
1 parent bfef129 commit 7884882

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

Cargo.lock

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ratelimit = { path = "./deltachat-ratelimit" }
4141
anyhow = { workspace = true }
4242
async-broadcast = "0.7.1"
4343
async-channel = { workspace = true }
44-
async-imap = { version = "0.10.1", default-features = false, features = ["runtime-tokio"] }
44+
async-imap = { git = "https://github.com/async-email/async-imap.git", default-features = false, features = ["runtime-tokio", "compress"], branch = "link2xt/imap-compress" }
4545
async-native-tls = { version = "0.5", default-features = false, features = ["runtime-tokio"] }
4646
async-smtp = { version = "0.9", default-features = false, features = ["runtime-tokio"] }
4747
async_zip = { version = "0.0.12", default-features = false, features = ["deflate", "fs"] }

src/imap/capabilities.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ pub(crate) struct Capabilities {
2525
/// <https://tools.ietf.org/html/rfc5464>
2626
pub can_metadata: bool,
2727

28+
/// True if the server has COMPRESS=DEFLATE capability as defined in
29+
/// <https://tools.ietf.org/html/rfc4978>
30+
pub can_compress: bool,
31+
2832
/// True if the server supports XDELTAPUSH capability.
2933
/// This capability means setting /private/devicetoken IMAP METADATA
3034
/// on the INBOX results in new mail notifications

src/imap/client.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ async fn determine_capabilities(
6969
can_check_quota: caps.has_str("QUOTA"),
7070
can_condstore: caps.has_str("CONDSTORE"),
7171
can_metadata: caps.has_str("METADATA"),
72+
can_compress: caps.has_str("COMPRESS=DEFLATE"),
7273
can_push: caps.has_str("XDELTAPUSH"),
7374
is_chatmail: caps.has_str("XCHATMAIL"),
7475
server_id,
@@ -90,7 +91,19 @@ impl Client {
9091
.await
9192
.map_err(|(err, _client)| err)?;
9293
let capabilities = determine_capabilities(&mut session).await?;
93-
Ok(Session::new(session, capabilities))
94+
95+
if capabilities.can_compress {
96+
let compressed_session = session
97+
.compress(|s| {
98+
let session_stream: Box<dyn SessionStream> = Box::new(s);
99+
session_stream
100+
})
101+
.await
102+
.context("Failed to enable IMAP compression")?;
103+
Ok(Session::new(compressed_session, capabilities))
104+
} else {
105+
Ok(Session::new(session, capabilities))
106+
}
94107
}
95108

96109
pub(crate) async fn authenticate(

src/net/session.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ impl<T: SessionStream> SessionStream for ShadowsocksStream<T> {
5050
self.stream.get_mut().set_read_timeout(timeout)
5151
}
5252
}
53+
impl<T: SessionStream> SessionStream for async_imap::deflate::DeflateStream<T> {
54+
fn set_read_timeout(&mut self, _timeout: Option<Duration>) {
55+
//self.stream.get_mut().set_read_timeout(timeout)
56+
}
57+
}
5358

5459
/// Session stream with a read buffer.
5560
pub(crate) trait SessionBufStream: SessionStream + AsyncBufRead {}

0 commit comments

Comments
 (0)