From e3c1656e05ecbdbb4360d1807293003850247d31 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 25 Jun 2024 20:26:52 +0300 Subject: [PATCH] melib/imap: fix LOGINDISABLED support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LOGINDISABLED disables the LOGIN command, not authenticating in general; doh! 🤦🤦🤦🤦 Signed-off-by: Manos Pitsidianakis --- melib/src/imap/connection.rs | 20 +++++++++++--------- melib/src/imap/mod.rs | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/melib/src/imap/connection.rs b/melib/src/imap/connection.rs index 9914b4ce..1e8c75a0 100644 --- a/melib/src/imap/connection.rs +++ b/melib/src/imap/connection.rs @@ -380,15 +380,6 @@ impl ImapStream { &server_conf.server_hostname )) .set_kind(ErrorKind::ProtocolNotSupported)); - } else if capabilities - .iter() - .any(|cap| cap.eq_ignore_ascii_case(b"LOGINDISABLED")) - { - return Err(Error::new(format!( - "Could not connect to {}: server does not accept logins [LOGINDISABLED]", - &server_conf.server_hostname - )) - .set_kind(ErrorKind::Authentication)); } (uid_store.event_consumer)( @@ -452,6 +443,17 @@ impl ImapStream { ret.send_literal(b"c2lyaGM=").await?; } _ => { + if capabilities + .iter() + .any(|cap| cap.eq_ignore_ascii_case(b"LOGINDISABLED")) + { + return Err(Error::new(format!( + "Could not connect to {}: server does not accept the LOGIN command \ + [LOGINDISABLED]", + &server_conf.server_hostname + )) + .set_kind(ErrorKind::Authentication)); + } let username = AString::try_from(server_conf.server_username.as_str()) .chain_err_kind(ErrorKind::Bug)?; let password = AString::try_from(server_conf.server_password.as_str()) diff --git a/melib/src/imap/mod.rs b/melib/src/imap/mod.rs index c96c48be..0e5fbcc2 100644 --- a/melib/src/imap/mod.rs +++ b/melib/src/imap/mod.rs @@ -309,6 +309,23 @@ impl MailBackend for ImapType { }; } } + "LOGINDISABLED" => { + if !(oauth2 || auth_anonymous) { + *status = MailBackendExtensionStatus::Enabled { + comment: Some( + "Use of LOGIN command is the default for given user \ + configuration, but server rejects its use", + ), + }; + } else { + *status = MailBackendExtensionStatus::Supported { + comment: Some( + "Current user authentication is not performed with the LOGIN \ + command", + ), + }; + } + } _ => { if SUPPORTED_CAPABILITIES .iter()