feat: do not use ConfiguredAddr when connecting to SMTP

This commit is contained in:
link2xt
2026-09-16 09:03:37 +00:00
committed by l
parent 8f39d7510f
commit 310dda494c
5 changed files with 47 additions and 29 deletions

View File

@@ -52,10 +52,9 @@ def test_add_second_address(acf) -> None:
def test_change_address(acf) -> None: def test_change_address(acf) -> None:
"""Test Alice configuring a second transport and setting it as a primary one.""" """Test Alice configuring a second transport and removing the first one."""
alice, bob = acf.get_online_accounts(2) alice, bob = acf.get_online_accounts(2)
bob_addr = bob.get_config("configured_addr")
bob.create_chat(alice) bob.create_chat(alice)
alice_chat_bob = alice.create_chat(bob) alice_chat_bob = alice.create_chat(bob)
@@ -65,22 +64,14 @@ def test_change_address(acf) -> None:
sender_addr1 = msg1.sender.get_snapshot().address sender_addr1 = msg1.sender.get_snapshot().address
alice.stop_io() alice.stop_io()
old_alice_addr = alice.get_config("configured_addr") old_alice_addr = alice.list_transports()[0]["addr"]
alice_vcard = alice.self_contact.make_vcard() alice_vcard = alice.self_contact.make_vcard()
assert old_alice_addr in alice_vcard assert old_alice_addr in alice_vcard
qr = acf.get_account_qr() qr = acf.get_account_qr()
alice.add_transport_from_qr(qr) alice.add_transport_from_qr(qr)
new_alice_addr = alice.list_transports()[1]["addr"] new_alice_addr = alice.list_transports()[1]["addr"]
with pytest.raises(JsonRpcError):
# Cannot use the address that is not
# configured for any transport.
alice.set_config("configured_addr", bob_addr)
# Load old address so it is cached. alice.delete_transport(old_alice_addr)
assert alice.get_config("configured_addr") == old_alice_addr
alice.set_config("configured_addr", new_alice_addr)
# Make sure that setting `configured_addr` invalidated the cache.
assert alice.get_config("configured_addr") == new_alice_addr
alice_vcard = alice.self_contact.make_vcard() alice_vcard = alice.self_contact.make_vcard()
assert old_alice_addr not in alice_vcard assert old_alice_addr not in alice_vcard

View File

@@ -42,10 +42,12 @@ use crate::{constants, stats};
#[strum(serialize_all = "snake_case")] #[strum(serialize_all = "snake_case")]
pub enum Config { pub enum Config {
/// Deprecated(2026-04). /// Deprecated(2026-04).
/// Use ConfiguredAddr, [`crate::login_param::EnteredLoginParam`],
/// or add_transport{from_qr}()/list_transports() instead.
/// ///
/// Email address, used in the `From:` field. /// Email address used by the deprecated configure() procedure.
///
/// Use add_transport{from_qr}() to configure new transports,
/// Use list_transports() to learn about configured transports,
/// including their addresses.
Addr, Addr,
/// Deprecated(2026-04). /// Deprecated(2026-04).
@@ -195,9 +197,9 @@ pub enum Config {
#[strum(props(default = "0"))] #[strum(props(default = "0"))]
DeleteDeviceAfter, DeleteDeviceAfter,
/// The address of the transport used for sending. /// Deprecated(2026-09).
/// ///
/// Device-local, other devices choose their own sending transport. /// Use ConfiguredLoginParam and list_transports() instead.
ConfiguredAddr, ConfiguredAddr,
/// Deprecated(2026-04). /// Deprecated(2026-04).

View File

@@ -684,6 +684,10 @@ async fn test_ephemeral_msg_offline() -> Result<()> {
check_msg_will_be_deleted(alice, msg.id, &chat, now, now + i64::from(duration) + 1).await?; check_msg_will_be_deleted(alice, msg.id, &chat, now, now + i64::from(duration) + 1).await?;
assert!(alice.sql.exists(stmt, (msg.id,)).await?); assert!(alice.sql.exists(stmt, (msg.id,)).await?);
alice
.assert_warn("No SMTP connection candidates provided")
.await;
Ok(()) Ok(())
} }

View File

@@ -631,6 +631,10 @@ async fn test_delete_msgs_offline() -> Result<()> {
delete_msgs(alice, &[msg.id]).await?; delete_msgs(alice, &[msg.id]).await?;
assert!(!alice.sql.exists(stmt, (msg.id,)).await?); assert!(!alice.sql.exists(stmt, (msg.id,)).await?);
alice
.assert_warn("No SMTP connection candidates provided")
.await;
Ok(()) Ok(())
} }

View File

@@ -98,19 +98,36 @@ impl Smtp {
} }
self.connectivity.set_connecting(context); self.connectivity.set_connecting(context);
let (_transport_id, lp) = ConfiguredLoginParam::load(context)
.await?
.context("Not configured")?;
let proxy_config = ProxyConfig::load(context).await?; let proxy_config = ProxyConfig::load(context).await?;
self.connect( let transports = ConfiguredLoginParam::load_all(context).await?;
context,
&lp.smtp, // Try to connect to the newest transport first. If sending is unreliable,
&lp.smtp_password, // user can configure a new transport and it will be the one used.
&proxy_config, // Conversely, if user just added a new transport and sending got less reliable,
&lp.addr, // user can restore old state by removing the just added transport.
lp.strict_tls(proxy_config.is_some())?, for (transport_id, lp) in transports.into_iter().rev() {
) info!(context, "Trying to connect to transport {transport_id}.");
.await match self
.connect(
context,
&lp.smtp,
&lp.smtp_password,
&proxy_config,
&lp.addr,
lp.strict_tls(proxy_config.is_some())?,
)
.await
{
Ok(()) => return Ok(()),
Err(err) => {
warn!(
context,
"Failed to connect to SMTP transport {transport_id}: {err:#}."
);
}
}
}
bail!("Failed to connect to any SMTP server");
} }
/// Connect using the provided login params. /// Connect using the provided login params.