melib/imap: impl AUTH=ANONYMOUS (RFC4505)

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/425/head
Manos Pitsidianakis 4 months ago
parent 1cce8c1162
commit 9fb5bc41b4
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -803,6 +803,14 @@ Mailcap entries are searched for in the following files, in this order:
.Re .Re
.It .It
.Rs .Rs
.%B RFC4505 Anonymous Simple Authentication and Security Layer (SASL) Mechanism
.%I IETF
.%D June 12, 2006
.%A Kurt Zeilenga
.%U https://datatracker.ietf.org/doc/rfc4505/
.Re
.It
.Rs
.%B RFC4549 Synchronization Operations for Disconnected IMAP4 Clients .%B RFC4549 Synchronization Operations for Disconnected IMAP4 Clients
.%I IETF .%I IETF
.%D June 16, 2006 .%D June 16, 2006

@ -455,6 +455,12 @@ For help on setup with
.Tn Gmail .Tn Gmail
section below. section below.
.Pq Em false \" default value .Pq Em false \" default value
.It Ic use_auth_anonymous Ar boolean
.Pq Em optional
Use
.Em AUTH=ANONYMOUS
extension for authentication.
.Pq Em false \" default value
.It Ic timeout Ar integer .It Ic timeout Ar integer
.Pq Em optional .Pq Em optional
Timeout to use for server connections in seconds. Timeout to use for server connections in seconds.

@ -94,7 +94,9 @@ pub enum ImapProtocol {
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct ImapExtensionUse { pub struct ImapExtensionUse {
pub auth_anonymous: bool,
pub condstore: bool, pub condstore: bool,
pub idle: bool, pub idle: bool,
pub deflate: bool, pub deflate: bool,
@ -104,6 +106,7 @@ pub struct ImapExtensionUse {
impl Default for ImapExtensionUse { impl Default for ImapExtensionUse {
fn default() -> Self { fn default() -> Self {
Self { Self {
auth_anonymous: false,
condstore: true, condstore: true,
idle: true, idle: true,
deflate: true, deflate: true,
@ -425,6 +428,29 @@ impl ImapStream {
)) ))
.await?; .await?;
} }
ImapProtocol::IMAP {
extension_use: ImapExtensionUse { auth_anonymous, .. },
} if auth_anonymous => {
if !capabilities
.iter()
.any(|cap| cap.eq_ignore_ascii_case(b"AUTH=ANONYMOUS"))
{
return Err(Error::new(format!(
"Could not connect to {}: AUTH=ANONYMOUS is enabled but server did not \
return AUTH=ANONYMOUS capability. Returned capabilities were: {}",
&server_conf.server_hostname,
capabilities
.iter()
.map(|capability| String::from_utf8_lossy(capability).to_string())
.collect::<Vec<String>>()
.join(" ")
))
.set_kind(ErrorKind::Authentication));
}
ret.send_command_raw(b"AUTHENTICATE ANONYMOUS").await?;
ret.wait_for_continuation_request().await?;
ret.send_literal(b"c2lyaGM=").await?;
}
_ => { _ => {
let username = AString::try_from(server_conf.server_username.as_str()) let username = AString::try_from(server_conf.server_username.as_str())
.chain_err_kind(ErrorKind::Bug)?; .chain_err_kind(ErrorKind::Bug)?;
@ -724,6 +750,7 @@ impl ImapConnection {
deflate, deflate,
idle: _idle, idle: _idle,
oauth2: _, oauth2: _,
auth_anonymous: _,
}, },
} => { } => {
if capabilities.contains(&b"CONDSTORE"[..]) && condstore { if capabilities.contains(&b"CONDSTORE"[..]) && condstore {

@ -79,6 +79,7 @@ pub type UIDVALIDITY = UID;
pub type MessageSequenceNumber = ImapNum; pub type MessageSequenceNumber = ImapNum;
pub static SUPPORTED_CAPABILITIES: &[&str] = &[ pub static SUPPORTED_CAPABILITIES: &[&str] = &[
"AUTH=ANONYMOUS",
"AUTH=OAUTH2", "AUTH=OAUTH2",
"COMPRESS=DEFLATE", "COMPRESS=DEFLATE",
"CONDSTORE", "CONDSTORE",
@ -257,6 +258,7 @@ impl MailBackend for ImapType {
deflate, deflate,
condstore, condstore,
oauth2, oauth2,
auth_anonymous,
}, },
} = self.server_conf.protocol } = self.server_conf.protocol
{ {
@ -298,6 +300,15 @@ impl MailBackend for ImapType {
}; };
} }
} }
"AUTH=ANONYMOUS" => {
if auth_anonymous {
*status = MailBackendExtensionStatus::Enabled { comment: None };
} else {
*status = MailBackendExtensionStatus::Supported {
comment: Some("Disabled by user configuration"),
};
}
}
_ => { _ => {
if SUPPORTED_CAPABILITIES if SUPPORTED_CAPABILITIES
.iter() .iter()
@ -1339,6 +1350,7 @@ impl ImapType {
condstore: get_conf_val!(s["use_condstore"], true)?, condstore: get_conf_val!(s["use_condstore"], true)?,
deflate: get_conf_val!(s["use_deflate"], true)?, deflate: get_conf_val!(s["use_deflate"], true)?,
oauth2: use_oauth2, oauth2: use_oauth2,
auth_anonymous: get_conf_val!(s["use_auth_anonymous"], false)?,
}, },
}, },
timeout, timeout,
@ -1608,6 +1620,7 @@ impl ImapType {
get_conf_val!(s["use_idle"], true)?; get_conf_val!(s["use_idle"], true)?;
get_conf_val!(s["use_condstore"], true)?; get_conf_val!(s["use_condstore"], true)?;
get_conf_val!(s["use_deflate"], true)?; get_conf_val!(s["use_deflate"], true)?;
get_conf_val!(s["use_auth_anonymous"], false)?;
let _timeout = get_conf_val!(s["timeout"], 16_u64)?; let _timeout = get_conf_val!(s["timeout"], 16_u64)?;
let extra_keys = s let extra_keys = s
.extra .extra

Loading…
Cancel
Save