fix: Use fallback ICE servers if server can't IMAP METADATA (#7382)

This commit is contained in:
iequidoo
2025-11-22 06:11:38 -03:00
committed by link2xt
parent f6817131b8
commit 1ea8ed6442
2 changed files with 30 additions and 28 deletions

View File

@@ -123,7 +123,7 @@ struct OAuth2 {
access_token: String, access_token: String,
} }
#[derive(Debug)] #[derive(Debug, Default)]
pub(crate) struct ServerMetadata { pub(crate) struct ServerMetadata {
/// IMAP METADATA `/shared/comment` as defined in /// IMAP METADATA `/shared/comment` as defined in
/// <https://www.rfc-editor.org/rfc/rfc5464#section-6.2.1>. /// <https://www.rfc-editor.org/rfc/rfc5464#section-6.2.1>.
@@ -1546,17 +1546,17 @@ impl Session {
Ok(()) Ok(())
} }
/// Retrieves server metadata if it is supported. /// Retrieves server metadata if it is supported, otherwise uses fallback one.
/// ///
/// We get [`/shared/comment`](https://www.rfc-editor.org/rfc/rfc5464#section-6.2.1) /// We get [`/shared/comment`](https://www.rfc-editor.org/rfc/rfc5464#section-6.2.1)
/// and [`/shared/admin`](https://www.rfc-editor.org/rfc/rfc5464#section-6.2.2) /// and [`/shared/admin`](https://www.rfc-editor.org/rfc/rfc5464#section-6.2.2)
/// metadata. /// metadata.
pub(crate) async fn fetch_metadata(&mut self, context: &Context) -> Result<()> { pub(crate) async fn update_metadata(&mut self, context: &Context) -> Result<()> {
if !self.can_metadata() {
return Ok(());
}
let mut lock = context.metadata.write().await; let mut lock = context.metadata.write().await;
if !self.can_metadata() {
*lock = Some(Default::default());
}
if let Some(ref mut old_metadata) = *lock { if let Some(ref mut old_metadata) = *lock {
let now = time(); let now = time();
@@ -1565,13 +1565,14 @@ impl Session {
return Ok(()); return Ok(());
} }
let mut got_turn_server = false;
if self.can_metadata() {
info!(context, "ICE servers expired, requesting new credentials."); info!(context, "ICE servers expired, requesting new credentials.");
let mailbox = ""; let mailbox = "";
let options = ""; let options = "";
let metadata = self let metadata = self
.get_metadata(mailbox, options, "(/shared/vendor/deltachat/turn)") .get_metadata(mailbox, options, "(/shared/vendor/deltachat/turn)")
.await?; .await?;
let mut got_turn_server = false;
for m in metadata { for m in metadata {
if m.entry == "/shared/vendor/deltachat/turn" if m.entry == "/shared/vendor/deltachat/turn"
&& let Some(value) = m.value && let Some(value) = m.value
@@ -1588,8 +1589,9 @@ impl Session {
} }
} }
} }
}
if !got_turn_server { if !got_turn_server {
info!(context, "Will use fallback ICE servers.");
// Set expiration timestamp 7 days in the future so we don't request it again. // Set expiration timestamp 7 days in the future so we don't request it again.
old_metadata.ice_servers_expiration_timestamp = time() + 3600 * 24 * 7; old_metadata.ice_servers_expiration_timestamp = time() + 3600 * 24 * 7;
old_metadata.ice_servers = create_fallback_ice_servers(context).await?; old_metadata.ice_servers = create_fallback_ice_servers(context).await?;

View File

@@ -538,9 +538,9 @@ async fn inbox_fetch_idle(ctx: &Context, imap: &mut Imap, mut session: Session)
.await .await
.context("Failed to download messages")?; .context("Failed to download messages")?;
session session
.fetch_metadata(ctx) .update_metadata(ctx)
.await .await
.context("Failed to fetch metadata")?; .context("update_metadata")?;
session session
.register_token(ctx) .register_token(ctx)
.await .await