-
-
Notifications
You must be signed in to change notification settings - Fork 122
Add unpublished flag for transports
#7994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2737,7 +2737,6 @@ async fn prepare_send_msg( | |
| chat_id.unarchive_if_not_muted(context, msg.state).await?; | ||
| } | ||
| chat.prepare_msg_raw(context, msg, update_msg_id).await?; | ||
|
|
||
| let row_ids = create_send_msg_jobs(context, msg) | ||
| .await | ||
| .context("Failed to create send jobs")?; | ||
|
|
@@ -2844,19 +2843,12 @@ 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?; | ||
| } | ||
|
|
||
| // Default Webxdc integrations are hidden messages and must not be sent out | ||
| if msg.param.get_int(Param::WebxdcIntegration).is_some() && msg.hidden { | ||
| recipients.clear(); | ||
| } | ||
|
|
||
| if recipients.is_empty() { | ||
| // may happen eg. for groups with only SELF and bcc_self disabled | ||
| // Default Webxdc integrations are hidden messages and must not be sent out: | ||
| if (msg.param.get_int(Param::WebxdcIntegration).is_some() && msg.hidden) | ||
| // This may happen eg. for groups with only SELF and bcc_self disabled: | ||
| || (!context.get_config_bool(Config::BccSelf).await? && recipients.is_empty()) | ||
| { | ||
| info!( | ||
| context, | ||
| "Message {} has no recipient, skipping smtp-send.", msg.id | ||
|
|
@@ -2895,6 +2887,12 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) - | |
| ); | ||
| } | ||
|
|
||
| if context.get_config_bool(Config::BccSelf).await? | ||
| || msg.param.get_cmd() == SystemMessage::AutocryptSetupMessage | ||
| { | ||
| smtp::add_self_recipients(context, &mut recipients, rendered_msg.is_encrypted).await?; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change actually fixes an unrelated bug, and is necessary for the tests to pass: We need to pass |
||
| } | ||
|
|
||
| if needs_encryption && !rendered_msg.is_encrypted { | ||
| /* unrecoverable */ | ||
| message::set_msg_failed( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -837,7 +837,7 @@ impl Context { | |||||
| // which only fetches from the primary transport. | ||||||
| transaction | ||||||
| .execute( | ||||||
| "UPDATE transports SET add_timestamp=? WHERE addr=?", | ||||||
| "UPDATE transports SET add_timestamp=?, is_published=1 WHERE addr=?", | ||||||
| (time(), addr), | ||||||
| ) | ||||||
| .context( | ||||||
|
|
@@ -974,6 +974,21 @@ impl Context { | |||||
| .await | ||||||
| } | ||||||
|
|
||||||
| /// Returns all published self addresses, newest first. | ||||||
| /// See `[Context::set_transport_unpublished]` | ||||||
| pub(crate) async fn get_published_self_addrs(&self) -> Result<Vec<String>> { | ||||||
| self.sql | ||||||
| .query_map_vec( | ||||||
| "SELECT addr FROM transports WHERE is_published=1 ORDER BY add_timestamp DESC", | ||||||
| (), | ||||||
| |row| { | ||||||
| let addr: String = row.get(0)?; | ||||||
| Ok(addr) | ||||||
| }, | ||||||
| ) | ||||||
| .await | ||||||
| } | ||||||
|
|
||||||
| /// Returns all secondary self addresses. | ||||||
| pub(crate) async fn get_secondary_self_addrs(&self) -> Result<Vec<String>> { | ||||||
| self.sql.query_map_vec("SELECT addr FROM transports WHERE addr NOT IN (SELECT value FROM config WHERE keyname='configured_addr')", (), |row| { | ||||||
|
|
@@ -982,6 +997,23 @@ impl Context { | |||||
| }).await | ||||||
| } | ||||||
|
|
||||||
| /// Returns all published secondary self addresses. | ||||||
| /// See `[Context::set_transport_unpublished]` | ||||||
| pub(crate) async fn get_published_secondary_self_addrs(&self) -> Result<Vec<String>> { | ||||||
| self.sql | ||||||
| .query_map_vec( | ||||||
| "SELECT addr FROM transports | ||||||
| WHERE is_published=1 | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| AND addr NOT IN (SELECT value FROM config WHERE keyname='configured_addr')", | ||||||
| (), | ||||||
| |row| { | ||||||
| let addr: String = row.get(0)?; | ||||||
| Ok(addr) | ||||||
| }, | ||||||
| ) | ||||||
| .await | ||||||
| } | ||||||
|
|
||||||
| /// Returns the primary self address. | ||||||
| /// Returns an error if no self addr is configured. | ||||||
| pub async fn get_primary_self_addr(&self) -> Result<String> { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -110,6 +110,7 @@ impl Context { | |
| /// from a server encoded in a QR code. | ||
| /// - [Self::list_transports()] to get a list of all configured transports. | ||
| /// - [Self::delete_transport()] to remove a transport. | ||
| /// - [Self::set_transport_unpublished()] to set whether contacts see this transport. | ||
| pub async fn add_or_update_transport(&self, param: &mut EnteredLoginParam) -> Result<()> { | ||
| self.stop_io().await; | ||
| let result = self.add_transport_inner(param).await; | ||
|
|
@@ -188,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<Vec<EnteredLoginParam>> { | ||
| pub async fn list_transports(&self) -> Result<Vec<Transport>> { | ||
| 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) | ||
|
|
@@ -261,6 +270,40 @@ impl Context { | |
| Ok(()) | ||
| } | ||
|
|
||
| /// Change whether the transport is unpublished. | ||
| /// | ||
| /// Unpublished transports are not advertised to contacts, | ||
| /// and self-sent messages are not sent there, | ||
| /// so that we don't cause extra messages to the corresponding inbox, | ||
| /// but can still receive messages from contacts who don't know the new relay addresses yet. | ||
| /// | ||
| /// The default is true, but when updating, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default is false, because it is "unpublished", not "published" |
||
| /// existing secondary transports are set to unpublished, | ||
| /// so that an existing transport address doesn't suddenly get spammed with a lot of messages. | ||
| pub async fn set_transport_unpublished(&self, addr: &str, unpublished: bool) -> Result<()> { | ||
| // We need to update the timestamp so that the key's timestamp changes | ||
| // and is recognized as newer by our peers | ||
| self.sql | ||
| .transaction(|trans| { | ||
| let primary_addr: String = trans.query_row( | ||
| "SELECT value FROM config WHERE keyname='configured_addr'", | ||
| (), | ||
| |row| row.get(0), | ||
| )?; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs |
||
| if primary_addr == addr && unpublished { | ||
| bail!("Can't set primary relay as unpublished"); | ||
| } | ||
| trans.execute( | ||
| "UPDATE transports SET is_published=?, add_timestamp=? WHERE addr=?", | ||
| (!unpublished, time(), addr), | ||
| )?; | ||
| Ok(()) | ||
| }) | ||
| .await?; | ||
| send_sync_transports(self).await?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| async fn inner_configure(&self, param: &EnteredLoginParam) -> Result<()> { | ||
| info!(self, "Configure ..."); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,7 +204,7 @@ async fn test_qr_code_security() -> Result<()> { | |
| let charlie_addr = charlie.get_config(Config::Addr).await?.unwrap(); | ||
|
|
||
| let alice_fp = self_fingerprint(alice).await?; | ||
| let secret_for_encryption = dbg!(format!("securejoin/{alice_fp}/{authcode}")); | ||
| let secret_for_encryption = format!("securejoin/{alice_fp}/{authcode}"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something unrelated |
||
| test_shared_secret_decryption_ex( | ||
| bob, | ||
| &charlie_addr, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default is false