Change the API, add some logging to debug test failure

This commit is contained in:
Hocuri
2026-03-16 20:08:26 +01:00
parent b9886d1593
commit ef0780b431
7 changed files with 77 additions and 56 deletions

View File

@@ -68,6 +68,7 @@ use self::types::{
}, },
}; };
use crate::api::types::chat_list::{get_chat_list_item_by_id, ChatListItemFetchResult}; use crate::api::types::chat_list::{get_chat_list_item_by_id, ChatListItemFetchResult};
use crate::api::types::login_param::Transport;
use crate::api::types::qr::{QrObject, SecurejoinSource, SecurejoinUiPath}; use crate::api::types::qr::{QrObject, SecurejoinSource, SecurejoinUiPath};
#[derive(Debug)] #[derive(Debug)]
@@ -554,7 +555,23 @@ impl CommandApi {
/// 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_or_update_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.
/// Use [Self::list_transports_ex()] to additionally query
/// whether the transports are marked as 'unpublished'.
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 res = ctx
.list_transports()
.await?
.into_iter()
.map(|t| t.param.into())
.collect();
Ok(res)
}
/// Returns the list of all email accounts that are used as a transport in the current profile.
/// Use [Self::add_or_update_transport()] to add or change a transport
/// and [Self::delete_transport()] to delete a transport.
async fn list_transports_ex(&self, account_id: u32) -> Result<Vec<Transport>> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;
let res = ctx let res = ctx
.list_transports() .list_transports()
@@ -592,13 +609,6 @@ impl CommandApi {
ctx.set_transport_unpublished(&addr, unpublished).await ctx.set_transport_unpublished(&addr, unpublished).await
} }
/// Check whether the transport is unpublished.
/// See [`Self::set_transport_unpublished`] / `setTransportUnpublished` for details.
async fn is_transport_unpublished(&self, account_id: u32, addr: String) -> Result<bool> {
let ctx = self.get_context(account_id).await?;
ctx.is_transport_unpublished(&addr).await
}
/// Signal an ongoing process to stop. /// Signal an ongoing process to stop.
async fn stop_ongoing_process(&self, account_id: u32) -> Result<()> { async fn stop_ongoing_process(&self, account_id: u32) -> Result<()> {
let ctx = self.get_context(account_id).await?; let ctx = self.get_context(account_id).await?;

View File

@@ -4,6 +4,16 @@ use serde::Deserialize;
use serde::Serialize; use serde::Serialize;
use yerpc::TypeDef; use yerpc::TypeDef;
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct Transport {
/// The login data entered by the user.
pub param: EnteredLoginParam,
/// Whether this transport is set to 'unpublished'.
/// See `set_transport_unpublished` / `setTransportUnpublished` for details.
pub is_unpublished: bool,
}
/// Login parameters entered by the user. /// Login parameters entered by the user.
/// ///
/// Usually it will be enough to only set `addr` and `password`, /// Usually it will be enough to only set `addr` and `password`,
@@ -56,6 +66,15 @@ pub struct EnteredLoginParam {
pub oauth2: Option<bool>, pub oauth2: Option<bool>,
} }
impl From<dc::Transport> for Transport {
fn from(transport: dc::Transport) -> Self {
Transport {
param: transport.param.into(),
is_unpublished: transport.is_unpublished,
}
}
}
impl From<dc::EnteredLoginParam> for EnteredLoginParam { impl From<dc::EnteredLoginParam> for EnteredLoginParam {
fn from(param: dc::EnteredLoginParam) -> Self { fn from(param: dc::EnteredLoginParam) -> Self {
let imap_security: Socket = param.imap.security.into(); let imap_security: Socket = param.imap.security.into();

View File

@@ -2738,6 +2738,7 @@ async fn prepare_send_msg(
} }
chat.prepare_msg_raw(context, msg, update_msg_id).await?; chat.prepare_msg_raw(context, msg, update_msg_id).await?;
dbg!("create_send_msg_jobs");
let row_ids = create_send_msg_jobs(context, msg) let row_ids = create_send_msg_jobs(context, msg)
.await .await
.context("Failed to create send jobs")?; .context("Failed to create send jobs")?;
@@ -2844,10 +2845,11 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) -
let lowercase_from = from.to_lowercase(); let lowercase_from = from.to_lowercase();
recipients.retain(|x| x.to_lowercase() != lowercase_from); recipients.retain(|x| x.to_lowercase() != lowercase_from);
if context.get_config_bool(Config::BccSelf).await? if dbg!(
|| msg.param.get_cmd() == SystemMessage::AutocryptSetupMessage context.get_config_bool(Config::BccSelf).await?
{ || msg.param.get_cmd() == SystemMessage::AutocryptSetupMessage
smtp::add_self_recipients(context, &mut recipients, needs_encryption).await?; ) {
smtp::add_self_recipients(context, dbg!(&mut recipients), needs_encryption).await?;
} }
// Default Webxdc integrations are hidden messages and must not be sent out // Default Webxdc integrations are hidden messages and must not be sent out

View File

@@ -28,8 +28,8 @@ use crate::constants::NON_ALPHANUMERIC_WITHOUT_DOT;
use crate::context::Context; use crate::context::Context;
use crate::imap::Imap; use crate::imap::Imap;
use crate::log::warn; use crate::log::warn;
use crate::login_param::EnteredCertificateChecks;
pub use crate::login_param::EnteredLoginParam; pub use crate::login_param::EnteredLoginParam;
use crate::login_param::{EnteredCertificateChecks, Transport};
use crate::message::Message; use crate::message::Message;
use crate::net::proxy::ProxyConfig; use crate::net::proxy::ProxyConfig;
use crate::oauth2::get_oauth2_addr; use crate::oauth2::get_oauth2_addr;
@@ -189,14 +189,22 @@ 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_or_update_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<Transport>> {
let transports = self let transports = self
.sql .sql
.query_map_vec("SELECT entered_param FROM transports", (), |row| { .query_map_vec(
let entered_param: String = row.get(0)?; "SELECT entered_param, is_published FROM transports",
let transport: EnteredLoginParam = serde_json::from_str(&entered_param)?; (),
Ok(transport) |row| {
}) let param: String = row.get(0)?;
let param: EnteredLoginParam = serde_json::from_str(&param)?;
let is_published: bool = row.get(1)?;
Ok(Transport {
param,
is_unpublished: !is_published,
})
},
)
.await?; .await?;
Ok(transports) Ok(transports)
@@ -284,17 +292,6 @@ impl Context {
Ok(()) Ok(())
} }
/// Check whether the transport is unpublished.
/// See [`Self::set_transport_unpublished`] for details.
pub async fn is_transport_unpublished(&self, addr: &str) -> Result<bool> {
let published: bool = self
.sql
.query_get_value("SELECT is_published FROM transports WHERE addr=?", (addr,))
.await?
.context("is_published is not supposed to be NULL")?;
Ok(!published)
}
async fn inner_configure(&self, param: &EnteredLoginParam) -> Result<()> { async fn inner_configure(&self, param: &EnteredLoginParam) -> Result<()> {
info!(self, "Configure ..."); info!(self, "Configure ...");

View File

@@ -79,6 +79,16 @@ pub struct EnteredServerLoginParam {
pub password: String, pub password: String,
} }
/// A transport, as shown in the "relays" list in the UI.
#[derive(Debug)]
pub struct Transport {
/// The login data entered by the user.
pub param: EnteredLoginParam,
/// Whether this transport is set to 'unpublished'.
/// See [`Context::set_transport_unpublished`] for details.
pub is_unpublished: bool,
}
/// Login parameters entered by the user. /// Login parameters entered by the user.
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EnteredLoginParam { pub struct EnteredLoginParam {

View File

@@ -693,6 +693,7 @@ pub(crate) async fn add_self_recipients(
recipients: &mut Vec<String>, recipients: &mut Vec<String>,
encrypted: bool, encrypted: bool,
) -> Result<()> { ) -> Result<()> {
dbg!("add_self_rcpnts");
// Previous versions of Delta Chat did not send BCC self // Previous versions of Delta Chat did not send BCC self
// if DeleteServerAfter was set to immediately delete messages // if DeleteServerAfter was set to immediately delete messages
// from the server. This is not the case anymore // from the server. This is not the case anymore
@@ -701,12 +702,14 @@ pub(crate) async fn add_self_recipients(
// and connection is frequently lost // and connection is frequently lost
// before receiving status line. NB: This is not a problem for chatmail servers, so `BccSelf` // before receiving status line. NB: This is not a problem for chatmail servers, so `BccSelf`
// disabled by default is fine. // disabled by default is fine.
if context.get_config_delete_server_after().await? != Some(0) || !recipients.is_empty() { if dbg!(context.get_config_delete_server_after().await? != Some(0))
|| dbg!(!recipients.is_empty())
{
// Avoid sending unencrypted messages to all transports, chatmail relays won't accept // Avoid sending unencrypted messages to all transports, chatmail relays won't accept
// them. Normally the user should have a non-chatmail primary transport to send unencrypted // them. Normally the user should have a non-chatmail primary transport to send unencrypted
// messages. // messages.
if encrypted { if dbg!(encrypted) {
for addr in context.get_published_secondary_self_addrs().await? { for addr in dbg!(context.get_published_secondary_self_addrs().await?) {
recipients.push(addr); recipients.push(addr);
} }
} }

View File

@@ -312,10 +312,7 @@ async fn test_is_published_flag() -> Result<()> {
alice.get_published_secondary_self_addrs().await?, alice.get_published_secondary_self_addrs().await?,
Vec::<String>::new() Vec::<String>::new()
); );
assert_eq!( // TODO test list_transports API
alice.is_transport_unpublished("alice@example.org").await?,
false
);
send_recv_check_recipients(alice, bob, "alice@example.org").await; send_recv_check_recipients(alice, bob, "alice@example.org").await;
dummy_configured_login_param("alice@otherprovider.com", None) dummy_configured_login_param("alice@otherprovider.com", None)
@@ -347,16 +344,8 @@ async fn test_is_published_flag() -> Result<()> {
a.get_published_secondary_self_addrs().await?, a.get_published_secondary_self_addrs().await?,
vec!["alice@otherprovider.com".to_string()] vec!["alice@otherprovider.com".to_string()]
); );
assert_eq!( // TODO test list_transports API
alice.is_transport_unpublished("alice@example.org").await?, dbg!("This will likely fail:");
false
);
assert_eq!(
alice
.is_transport_unpublished("alice@otherprovider.com")
.await?,
false
);
send_recv_check_recipients(a, bob, "alice@example.org alice@otherprovider.com").await; send_recv_check_recipients(a, bob, "alice@example.org alice@otherprovider.com").await;
} }
@@ -391,16 +380,7 @@ async fn test_is_published_flag() -> Result<()> {
a.get_published_secondary_self_addrs().await?, a.get_published_secondary_self_addrs().await?,
Vec::<String>::new() Vec::<String>::new()
); );
assert_eq!( // TODO test list_transports API
alice.is_transport_unpublished("alice@example.org").await?,
false
);
assert_eq!(
alice
.is_transport_unpublished("alice@otherprovider.com")
.await?,
true
);
send_recv_check_recipients(a, bob, "alice@example.org").await; send_recv_check_recipients(a, bob, "alice@example.org").await;
} }