diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index a07df3530..7a41792fd 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -68,6 +68,7 @@ use self::types::{ }, }; 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}; #[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. /// Use [Self::add_or_update_transport()] to add or change 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> { + 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> { let ctx = self.get_context(account_id).await?; let res = ctx .list_transports() @@ -592,13 +609,6 @@ impl CommandApi { 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 { - let ctx = self.get_context(account_id).await?; - ctx.is_transport_unpublished(&addr).await - } - /// Signal an ongoing process to stop. async fn stop_ongoing_process(&self, account_id: u32) -> Result<()> { let ctx = self.get_context(account_id).await?; diff --git a/deltachat-jsonrpc/src/api/types/login_param.rs b/deltachat-jsonrpc/src/api/types/login_param.rs index 6036709cd..71b42add6 100644 --- a/deltachat-jsonrpc/src/api/types/login_param.rs +++ b/deltachat-jsonrpc/src/api/types/login_param.rs @@ -4,6 +4,16 @@ use serde::Deserialize; use serde::Serialize; 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. /// /// Usually it will be enough to only set `addr` and `password`, @@ -56,6 +66,15 @@ pub struct EnteredLoginParam { pub oauth2: Option, } +impl From for Transport { + fn from(transport: dc::Transport) -> Self { + Transport { + param: transport.param.into(), + is_unpublished: transport.is_unpublished, + } + } +} + impl From for EnteredLoginParam { fn from(param: dc::EnteredLoginParam) -> Self { let imap_security: Socket = param.imap.security.into(); diff --git a/src/chat.rs b/src/chat.rs index 2dd153570..65ebf22ca 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2738,6 +2738,7 @@ async fn prepare_send_msg( } chat.prepare_msg_raw(context, msg, update_msg_id).await?; + dbg!("create_send_msg_jobs"); let row_ids = create_send_msg_jobs(context, msg) .await .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(); recipients.retain(|x| x.to_lowercase() != lowercase_from); - if context.get_config_bool(Config::BccSelf).await? - || msg.param.get_cmd() == SystemMessage::AutocryptSetupMessage - { - smtp::add_self_recipients(context, &mut recipients, needs_encryption).await?; + if dbg!( + context.get_config_bool(Config::BccSelf).await? + || msg.param.get_cmd() == SystemMessage::AutocryptSetupMessage + ) { + smtp::add_self_recipients(context, dbg!(&mut recipients), needs_encryption).await?; } // Default Webxdc integrations are hidden messages and must not be sent out diff --git a/src/configure.rs b/src/configure.rs index 6a195af22..d73cbd708 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -28,8 +28,8 @@ use crate::constants::NON_ALPHANUMERIC_WITHOUT_DOT; use crate::context::Context; use crate::imap::Imap; use crate::log::warn; -use crate::login_param::EnteredCertificateChecks; pub use crate::login_param::EnteredLoginParam; +use crate::login_param::{EnteredCertificateChecks, Transport}; use crate::message::Message; use crate::net::proxy::ProxyConfig; 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. /// Use [Self::add_or_update_transport()] to add or change a transport /// and [Self::delete_transport()] to delete a transport. - pub async fn list_transports(&self) -> Result> { + pub async fn list_transports(&self) -> Result> { let transports = self .sql - .query_map_vec("SELECT entered_param FROM transports", (), |row| { - let entered_param: String = row.get(0)?; - let transport: EnteredLoginParam = serde_json::from_str(&entered_param)?; - Ok(transport) - }) + .query_map_vec( + "SELECT entered_param, is_published FROM transports", + (), + |row| { + let param: String = row.get(0)?; + let param: EnteredLoginParam = serde_json::from_str(¶m)?; + let is_published: bool = row.get(1)?; + Ok(Transport { + param, + is_unpublished: !is_published, + }) + }, + ) .await?; Ok(transports) @@ -284,17 +292,6 @@ impl Context { Ok(()) } - /// Check whether the transport is unpublished. - /// See [`Self::set_transport_unpublished`] for details. - pub async fn is_transport_unpublished(&self, addr: &str) -> Result { - 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<()> { info!(self, "Configure ..."); diff --git a/src/login_param.rs b/src/login_param.rs index 5c6864f11..f4469be47 100644 --- a/src/login_param.rs +++ b/src/login_param.rs @@ -79,6 +79,16 @@ pub struct EnteredServerLoginParam { 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. #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct EnteredLoginParam { diff --git a/src/smtp.rs b/src/smtp.rs index aca1f46ea..c52b142d7 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -693,6 +693,7 @@ pub(crate) async fn add_self_recipients( recipients: &mut Vec, encrypted: bool, ) -> Result<()> { + dbg!("add_self_rcpnts"); // Previous versions of Delta Chat did not send BCC self // if DeleteServerAfter was set to immediately delete messages // 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 // before receiving status line. NB: This is not a problem for chatmail servers, so `BccSelf` // 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 // them. Normally the user should have a non-chatmail primary transport to send unencrypted // messages. - if encrypted { - for addr in context.get_published_secondary_self_addrs().await? { + if dbg!(encrypted) { + for addr in dbg!(context.get_published_secondary_self_addrs().await?) { recipients.push(addr); } } diff --git a/src/transport/transport_tests.rs b/src/transport/transport_tests.rs index db08229b9..a28fcdc14 100644 --- a/src/transport/transport_tests.rs +++ b/src/transport/transport_tests.rs @@ -312,10 +312,7 @@ async fn test_is_published_flag() -> Result<()> { alice.get_published_secondary_self_addrs().await?, Vec::::new() ); - assert_eq!( - alice.is_transport_unpublished("alice@example.org").await?, - false - ); + // TODO test list_transports API send_recv_check_recipients(alice, bob, "alice@example.org").await; 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?, vec!["alice@otherprovider.com".to_string()] ); - assert_eq!( - alice.is_transport_unpublished("alice@example.org").await?, - false - ); - assert_eq!( - alice - .is_transport_unpublished("alice@otherprovider.com") - .await?, - false - ); + // TODO test list_transports API + dbg!("This will likely fail:"); 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?, Vec::::new() ); - assert_eq!( - alice.is_transport_unpublished("alice@example.org").await?, - false - ); - assert_eq!( - alice - .is_transport_unpublished("alice@otherprovider.com") - .await?, - true - ); + // TODO test list_transports API send_recv_check_recipients(a, bob, "alice@example.org").await; }