api: Rename add_transport() -> add_or_update_transport() (#6800)

cc @nicodh
This commit is contained in:
Hocuri
2025-04-15 10:19:25 +02:00
committed by GitHub
parent 1379821b03
commit 7e8e4d2f39
6 changed files with 28 additions and 19 deletions

View File

@@ -439,7 +439,7 @@ impl CommandApi {
/// Setup the credential config before calling this. /// Setup the credential config before calling this.
/// ///
/// Deprecated as of 2025-02; use `add_transport_from_qr()` /// Deprecated as of 2025-02; use `add_transport_from_qr()`
/// or `add_transport()` instead. /// or `add_or_update_transport()` instead.
async fn configure(&self, account_id: u32) -> Result<()> { async fn configure(&self, account_id: u32) -> Result<()> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
ctx.stop_io().await; ctx.stop_io().await;
@@ -483,21 +483,30 @@ impl CommandApi {
/// from a server encoded in a QR code. /// from a server encoded in a QR code.
/// - [Self::list_transports()] to get a list of all configured transports. /// - [Self::list_transports()] to get a list of all configured transports.
/// - [Self::delete_transport()] to remove a transport. /// - [Self::delete_transport()] to remove a transport.
async fn add_transport(&self, account_id: u32, param: EnteredLoginParam) -> Result<()> { async fn add_or_update_transport(
&self,
account_id: u32,
param: EnteredLoginParam,
) -> Result<()> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
ctx.add_transport(&param.try_into()?).await ctx.add_or_update_transport(&param.try_into()?).await
}
/// Deprecated 2025-04. Alias for [Self::add_or_update_transport()].
async fn add_transport(&self, account_id: u32, param: EnteredLoginParam) -> Result<()> {
self.add_or_update_transport(account_id, param).await
} }
/// Adds a new email account as a transport /// Adds a new email account as a transport
/// using the server encoded in the QR code. /// using the server encoded in the QR code.
/// See [Self::add_transport]. /// See [Self::add_or_update_transport].
async fn add_transport_from_qr(&self, account_id: u32, qr: String) -> Result<()> { async fn add_transport_from_qr(&self, account_id: u32, qr: String) -> Result<()> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
ctx.add_transport_from_qr(&qr).await ctx.add_transport_from_qr(&qr).await
} }
/// Returns the list of all email accounts that are used as a transport in the current profile. /// Returns the list of all email accounts that are used as a transport in the current profile.
/// Use [Self::add_transport()] to add or change a transport /// Use [Self::add_or_update_transport()] to add or change a transport
/// and [Self::delete_transport()] to delete a transport. /// and [Self::delete_transport()] to delete a transport.
async fn list_transports(&self, account_id: u32) -> Result<Vec<EnteredLoginParam>> { async fn list_transports(&self, account_id: u32) -> Result<Vec<EnteredLoginParam>> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;

View File

@@ -111,9 +111,9 @@ class Account:
yield self._rpc.configure.future(self.id) yield self._rpc.configure.future(self.id)
@futuremethod @futuremethod
def add_transport(self, params): def add_or_update_transport(self, params):
"""Add a new transport.""" """Add a new transport."""
yield self._rpc.add_transport.future(self.id, params) yield self._rpc.add_or_update_transport.future(self.id, params)
def bring_online(self): def bring_online(self):
"""Start I/O and wait until IMAP becomes IDLE.""" """Start I/O and wait until IMAP becomes IDLE."""

View File

@@ -34,7 +34,7 @@ class ACFactory:
addr, password = self.get_credentials() addr, password = self.get_credentials()
account = self.get_unconfigured_account() account = self.get_unconfigured_account()
params = {"addr": addr, "password": password} params = {"addr": addr, "password": password}
yield account.add_transport.future(params) yield account.add_or_update_transport.future(params)
assert account.is_configured() assert account.is_configured()
return account return account

View File

@@ -17,7 +17,7 @@ def test_event_on_configuration(acfactory: ACFactory) -> None:
account = acfactory.get_unconfigured_account() account = acfactory.get_unconfigured_account()
account.clear_all_events() account.clear_all_events()
assert not account.is_configured() assert not account.is_configured()
future = account.add_transport.future({"addr": addr, "password": password}) future = account.add_or_update_transport.future({"addr": addr, "password": password})
while True: while True:
event = account.wait_for_event() event = account.wait_for_event()
if event.kind == EventType.ACCOUNTS_ITEM_CHANGED: if event.kind == EventType.ACCOUNTS_ITEM_CHANGED:

View File

@@ -63,7 +63,7 @@ def test_acfactory(acfactory) -> None:
def test_configure_starttls(acfactory) -> None: def test_configure_starttls(acfactory) -> None:
addr, password = acfactory.get_credentials() addr, password = acfactory.get_credentials()
account = acfactory.get_unconfigured_account() account = acfactory.get_unconfigured_account()
account.add_transport( account.add_or_update_transport(
{ {
"addr": addr, "addr": addr,
"password": password, "password": password,
@@ -80,7 +80,7 @@ def test_configure_ip(acfactory) -> None:
ip_address = socket.gethostbyname(addr.rsplit("@")[-1]) ip_address = socket.gethostbyname(addr.rsplit("@")[-1])
with pytest.raises(JsonRpcError): with pytest.raises(JsonRpcError):
account.add_transport( account.add_or_update_transport(
{ {
"addr": addr, "addr": addr,
"password": password, "password": password,
@@ -94,7 +94,7 @@ def test_configure_alternative_port(acfactory) -> None:
"""Test that configuration with alternative port 443 works.""" """Test that configuration with alternative port 443 works."""
addr, password = acfactory.get_credentials() addr, password = acfactory.get_credentials()
account = acfactory.get_unconfigured_account() account = acfactory.get_unconfigured_account()
account.add_transport( account.add_or_update_transport(
{ {
"addr": addr, "addr": addr,
"password": password, "password": password,
@@ -108,7 +108,7 @@ def test_configure_alternative_port(acfactory) -> None:
def test_list_transports(acfactory) -> None: def test_list_transports(acfactory) -> None:
addr, password = acfactory.get_credentials() addr, password = acfactory.get_credentials()
account = acfactory.get_unconfigured_account() account = acfactory.get_unconfigured_account()
account.add_transport( account.add_or_update_transport(
{ {
"addr": addr, "addr": addr,
"password": password, "password": password,
@@ -420,7 +420,7 @@ def test_wait_next_messages(acfactory) -> None:
addr, password = acfactory.get_credentials() addr, password = acfactory.get_credentials()
bot = acfactory.get_unconfigured_account() bot = acfactory.get_unconfigured_account()
bot.set_config("bot", "1") bot.set_config("bot", "1")
bot.add_transport({"addr": addr, "password": password}) bot.add_or_update_transport({"addr": addr, "password": password})
assert bot.is_configured() assert bot.is_configured()
# There are no old messages and the call returns immediately. # There are no old messages and the call returns immediately.
@@ -603,7 +603,7 @@ def test_reactions_for_a_reordering_move(acfactory, direct_imap):
addr, password = acfactory.get_credentials() addr, password = acfactory.get_credentials()
ac2 = acfactory.get_unconfigured_account() ac2 = acfactory.get_unconfigured_account()
ac2.add_transport({"addr": addr, "password": password}) ac2.add_or_update_transport({"addr": addr, "password": password})
ac2.set_config("mvbox_move", "1") ac2.set_config("mvbox_move", "1")
assert ac2.is_configured() assert ac2.is_configured()

View File

@@ -69,7 +69,7 @@ impl Context {
/// Configures this account with the currently provided parameters. /// Configures this account with the currently provided parameters.
/// ///
/// Deprecated since 2025-02; use `add_transport_from_qr()` /// Deprecated since 2025-02; use `add_transport_from_qr()`
/// or `add_transport()` instead. /// or `add_or_update_transport()` instead.
pub async fn configure(&self) -> Result<()> { pub async fn configure(&self) -> Result<()> {
let param = EnteredLoginParam::load(self).await?; let param = EnteredLoginParam::load(self).await?;
@@ -105,7 +105,7 @@ impl Context {
/// from a server encoded in a QR code. /// from a server encoded in a QR code.
/// - [Self::list_transports()] to get a list of all configured transports. /// - [Self::list_transports()] to get a list of all configured transports.
/// - [Self::delete_transport()] to remove a transport. /// - [Self::delete_transport()] to remove a transport.
pub async fn add_transport(&self, param: &EnteredLoginParam) -> Result<()> { pub async fn add_or_update_transport(&self, param: &EnteredLoginParam) -> Result<()> {
self.stop_io().await; self.stop_io().await;
let result = self.add_transport_inner(param).await; let result = self.add_transport_inner(param).await;
if result.is_err() { if result.is_err() {
@@ -156,7 +156,7 @@ impl Context {
/// Adds a new email account as a transport /// Adds a new email account as a transport
/// using the server encoded in the QR code. /// using the server encoded in the QR code.
/// See [Self::add_transport]. /// See [Self::add_or_update_transport].
pub async fn add_transport_from_qr(&self, qr: &str) -> Result<()> { pub async fn add_transport_from_qr(&self, qr: &str) -> Result<()> {
self.stop_io().await; self.stop_io().await;
@@ -178,7 +178,7 @@ impl Context {
} }
/// Returns the list of all email accounts that are used as a transport in the current profile. /// Returns the list of all email accounts that are used as a transport in the current profile.
/// Use [Self::add_transport()] to add or change a transport /// Use [Self::add_or_update_transport()] to add or change a transport
/// and [Self::delete_transport()] to delete a transport. /// and [Self::delete_transport()] to delete a transport.
pub async fn list_transports(&self) -> Result<Vec<EnteredLoginParam>> { pub async fn list_transports(&self) -> Result<Vec<EnteredLoginParam>> {
let transports = self let transports = self