Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Sep 23, 2024
1 parent 823b791 commit 50c8cb2
Showing 1 changed file with 14 additions and 31 deletions.
45 changes: 14 additions & 31 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Session<T> {
}

/// Runs `COMPRESS DEFLATE` command.
///
/// Returns `Result` which is `Ok` if the stream is now compressed
/// and `Err` if compression was not enabled.
pub async fn compress<F, S>(self, f: F) -> Result<std::result::Result<Session<S>, Session<T>>>
pub async fn compress<F, S>(self, f: F) -> Result<Session<S>>
where
S: Read + Write + Unpin + fmt::Debug,
F: FnOnce(DeflateStream<T>) -> S,
Expand All @@ -1341,34 +1338,20 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Session<T> {
} = self;
conn.run_command_and_check_ok("COMPRESS DEFLATE", Some(unsolicited_responses_tx.clone()))
.await?;
let stream = conn.into_inner();

if true {
let deflate_stream = DeflateStream::new(stream);
let stream = ImapStream::new(f(deflate_stream));
let conn = Connection {
stream,
request_ids: IdGenerator::new(),
};
let session = Session {
conn,
unsolicited_responses_tx,
unsolicited_responses,
};
Ok(Ok(session))
} else {
let stream = ImapStream::new(stream);
let conn = Connection {
stream,
request_ids: IdGenerator::new(),
};
let session = Self {
conn,
unsolicited_responses_tx,
unsolicited_responses,
};
Ok(Err(session))
}
let stream = conn.into_inner();
let deflate_stream = DeflateStream::new(stream);
let stream = ImapStream::new(f(deflate_stream));
let conn = Connection {
stream,
request_ids: IdGenerator::new(),
};
let session = Session {
conn,
unsolicited_responses_tx,
unsolicited_responses,
};
Ok(session)
}

// these are only here because they are public interface, the rest is in `Connection`
Expand Down

0 comments on commit 50c8cb2

Please sign in to comment.