From a4b024ec39a77ca2c57deee6f5727b55676d8b0e Mon Sep 17 00:00:00 2001 From: Christopher Angelo Date: Fri, 2 May 2025 12:50:16 +0700 Subject: [PATCH] fix(examples/gmail): forcefully wait for server greeting before auth --- examples/src/bin/gmail_oauth2.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/src/bin/gmail_oauth2.rs b/examples/src/bin/gmail_oauth2.rs index 7e52298..0bece23 100644 --- a/examples/src/bin/gmail_oauth2.rs +++ b/examples/src/bin/gmail_oauth2.rs @@ -37,6 +37,15 @@ async fn main() -> Result<()> { let tls_stream = tls.connect(domain, tcp_stream).await?; let client = async_imap::Client::new(tls_stream); + // Gmail's IMAP server will send a server greeting before taking in any message + // Here, we forcefully wait and read a line before sending authentication data + // + // See #84 + let _greeting = client + .read_response() + .await? + .expect("unexpected end of stream, expected greeting"); + let mut imap_session = match client.authenticate("XOAUTH2", &gmail_auth).await { Ok(c) => c, Err((e, _unauth_client)) => {