Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions deltachat-ffi/deltachat.h
Original file line number Diff line number Diff line change
Expand Up @@ -7215,11 +7215,6 @@ void dc_event_unref(dc_event_t* event);
/// Used as device message text.
#define DC_STR_SELF_DELETED_MSG_BODY 91

/// "'Delete messages from server' turned off as now all folders are affected."
///
/// Used as device message text.
#define DC_STR_SERVER_TURNED_OFF 92

/// "Message deletion timer is set to %1$s minutes."
///
/// Used in status messages.
Expand Down
15 changes: 7 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::context::Context;
use crate::events::EventType;
use crate::log::LogExt;
use crate::mimefactory::RECOMMENDED_FILE_SIZE;
use crate::provider::{Provider, get_provider_by_id};
use crate::provider::Provider;
use crate::sync::{self, Sync::*, SyncData};
use crate::tools::get_abs_path;
use crate::transport::ConfiguredLoginParam;
Expand Down Expand Up @@ -646,15 +646,14 @@ impl Context {
Ok(val)
}

/// Gets the configured provider, as saved in the `configured_provider` value.
/// Gets the configured provider.
///
/// The provider is determined by `get_provider_info()` during configuration and then saved
/// to the db in `param.save_to_database()`, together with all the other `configured_*` values.
/// The provider is determined by the current primary transport.
pub async fn get_configured_provider(&self) -> Result<Option<&'static Provider>> {
if let Some(cfg) = self.get_config(Config::ConfiguredProvider).await? {
return Ok(get_provider_by_id(&cfg));
}
Ok(None)
let provider = ConfiguredLoginParam::load(self)
.await?
.and_then(|(_transport_id, param)| param.provider);
Ok(provider)
}

/// Gets configured "delete_device_after" value.
Expand Down
2 changes: 1 addition & 1 deletion src/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) struct Imap {
pub(crate) idle_interrupt_receiver: Receiver<()>,

/// Email address.
addr: String,
pub(crate) addr: String,

/// Login parameters.
lp: Vec<ConfiguredServerLoginParam>,
Expand Down
19 changes: 13 additions & 6 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,19 @@ async fn fetch_idle(
mvbox.as_deref().unwrap_or(&watch_folder)
}
};
session
.send_sync_msgs(ctx, syncbox)
.await
.context("fetch_idle: send_sync_msgs")
.log_err(ctx)
.ok();
if ctx
.get_config(Config::ConfiguredAddr)
.await?
.unwrap_or_default()
== connection.addr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a side question: should this better be something like has_transport_address(connection.addr) in the multi-transport feature? "ConfiguredAddr" does not feel like a valid thing to work with anymore.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configured_addr is the address of the primary transport. Unlike all other configured_* settings it is not deprecated and is used to set the primary transport and tell which transport is currently the primary one.

{
session
.send_sync_msgs(ctx, syncbox)
.await
.context("fetch_idle: send_sync_msgs")
.log_err(ctx)
.ok();
}

session
.store_seen_flags_on_imap(ctx)
Expand Down
19 changes: 2 additions & 17 deletions src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rusqlite::{Connection, OpenFlags, Row, config::DbConfig, types::ValueRef};
use tokio::sync::RwLock;

use crate::blob::BlobObject;
use crate::chat::add_device_msg;
use crate::config::Config;
use crate::constants::DC_CHAT_ID_TRASH;
use crate::context::Context;
Expand All @@ -18,12 +17,11 @@ use crate::ephemeral::start_ephemeral_timers;
use crate::imex::BLOBS_BACKUP_NAME;
use crate::location::delete_orphaned_poi_locations;
use crate::log::{LogExt, warn};
use crate::message::{Message, MsgId};
use crate::message::MsgId;
use crate::net::dns::prune_dns_cache;
use crate::net::http::http_cache_cleanup;
use crate::net::prune_connection_history;
use crate::param::{Param, Params};
use crate::stock_str;
use crate::tools::{SystemTime, Time, delete_file, time, time_elapsed};

/// Extension to [`rusqlite::ToSql`] trait
Expand Down Expand Up @@ -216,26 +214,13 @@ impl Sql {
// this should be done before updates that use high-level objects that
// rely themselves on the low-level structure.

// `update_icons` is not used anymore, since it's not necessary anymore to "update" icons:
let (_update_icons, disable_server_delete, recode_avatar) = migrations::run(context, self)
let recode_avatar = migrations::run(context, self)
.await
.context("failed to run migrations")?;

// (2) updates that require high-level objects
// the structure is complete now and all objects are usable

if disable_server_delete {
// We now always watch all folders and delete messages there if delete_server is enabled.
// So, for people who have delete_server enabled, disable it and add a hint to the devicechat:
if context.get_config_delete_server_after().await?.is_some() {
let mut msg = Message::new_text(stock_str::delete_server_turned_off(context).await);
add_device_msg(context, None, Some(&mut msg)).await?;
context
.set_config_internal(Config::DeleteServerAfter, Some("0"))
.await?;
}
}

if recode_avatar && let Some(avatar) = context.get_config(Config::Selfavatar).await? {
let mut blob = BlobObject::from_path(context, Path::new(&avatar))?;
match blob.recode_to_avatar_size(context).await {
Expand Down
19 changes: 2 additions & 17 deletions src/sql/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tokio::task_local! {
static STOP_MIGRATIONS_AT: i32;
}

pub async fn run(context: &Context, sql: &Sql) -> Result<(bool, bool, bool)> {
pub async fn run(context: &Context, sql: &Sql) -> Result<bool> {
let mut exists_before_update = false;
let mut dbversion_before_update = DBVERSION;

Expand Down Expand Up @@ -68,8 +68,6 @@ pub async fn run(context: &Context, sql: &Sql) -> Result<(bool, bool, bool)> {
}

let dbversion = dbversion_before_update;
let mut update_icons = !exists_before_update;
let mut disable_server_delete = false;
let mut recode_avatar = false;

if dbversion < 1 {
Expand Down Expand Up @@ -299,7 +297,6 @@ CREATE INDEX devmsglabels_index1 ON devmsglabels (label);"#, 59)
61,
)
.await?;
update_icons = true;
}
if dbversion < 62 {
sql.execute_migration(
Expand Down Expand Up @@ -327,7 +324,6 @@ ALTER TABLE msgs ADD COLUMN ephemeral_timestamp INTEGER DEFAULT 0;"#,
.await?;
}
if dbversion < 66 {
update_icons = true;
sql.set_db_version(66).await?;
}
if dbversion < 67 {
Expand Down Expand Up @@ -445,17 +441,6 @@ CREATE TABLE imap_sync (folder TEXT PRIMARY KEY, uidvalidity INTEGER DEFAULT 0,
}
}
}
if exists_before_update {
disable_server_delete = true;

// Don't disable server delete if it was on by default (Nauta):
if let Some(provider) = context.get_configured_provider().await?
&& let Some(defaults) = &provider.config_defaults
&& defaults.iter().any(|d| d.key == Config::DeleteServerAfter)
{
disable_server_delete = false;
}
}
sql.set_db_version(73).await?;
}
if dbversion < 74 {
Expand Down Expand Up @@ -1468,7 +1453,7 @@ CREATE INDEX imap_sync_index ON imap_sync(transport_id, folder);
}
info!(context, "Database version: v{new_version}.");

Ok((update_icons, disable_server_delete, recode_avatar))
Ok(recode_avatar)
}

fn migrate_key_contacts(
Expand Down
5 changes: 2 additions & 3 deletions src/sql/sql_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use crate::message::Message;
use crate::{EventType, test_utils::TestContext};

#[test]
Expand Down Expand Up @@ -179,9 +180,7 @@ async fn test_migration_flags() -> Result<()> {
// as migrations::run() was already executed on context creation,
// another call should not result in any action needed.
// this test catches some bugs where dbversion was forgotten to be persisted.
let (update_icons, disable_server_delete, recode_avatar) = migrations::run(&t, &t.sql).await?;
assert!(!update_icons);
assert!(!disable_server_delete);
let recode_avatar = migrations::run(&t, &t.sql).await?;
assert!(!recode_avatar);

info!(&t, "test_migration_flags: XXX END MARKER");
Expand Down
12 changes: 0 additions & 12 deletions src/stock_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,6 @@ pub enum StockMessage {
To use the \"Saved messages\" feature again, create a new chat with yourself."))]
SelfDeletedMsgBody = 91,

#[strum(props(
fallback = "⚠️ The \"Delete messages from server\" feature now also deletes messages in folders other than Inbox, DeltaChat and Sent.\n\n\
ℹ️ To avoid accidentally deleting messages, we turned it off for you. Please turn it on again at \
Settings → \"Chats and Media\" → \"Delete messages from server\" to continue using it."
))]
DeleteServerTurnedOff = 92,

#[strum(props(fallback = "Forwarded"))]
Forwarded = 97,

Expand Down Expand Up @@ -1041,11 +1034,6 @@ pub(crate) async fn self_deleted_msg_body(context: &Context) -> String {
translated(context, StockMessage::SelfDeletedMsgBody).await
}

/// Stock string: `⚠️ The "Delete messages from server" feature now also...`.
pub(crate) async fn delete_server_turned_off(context: &Context) -> String {
translated(context, StockMessage::DeleteServerTurnedOff).await
}

/// Stock string: `Message deletion timer is set to %1$s minutes.`.
pub(crate) async fn msg_ephemeral_timer_minutes(
context: &Context,
Expand Down
13 changes: 13 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::context::Context;
use crate::events::{Event, EventEmitter, EventType, Events};
use crate::key::{self, DcKey, DcSecretKey, self_fingerprint};
use crate::log::warn;
use crate::login_param::EnteredLoginParam;
use crate::message::{Message, MessageState, MsgId, update_msg_state};
use crate::mimeparser::{MimeMessage, SystemMessage};
use crate::pgp::KeyPair;
Expand Down Expand Up @@ -200,6 +201,18 @@ impl TestContextManager {
"{} changes her self address and reconfigures",
test_context.name()
));

// Insert a transport for the new address.
test_context.sql
.execute(
"INSERT OR IGNORE INTO transports (addr, entered_param, configured_param) VALUES (?, ?, ?)",
(
new_addr,
serde_json::to_string(&EnteredLoginParam::default()).unwrap(),
format!(r#"{{"addr":"{new_addr}","imap":[],"imap_user":"","imap_password":"","smtp":[],"smtp_user":"","smtp_password":"","certificate_checks":"Automatic","oauth2":false}}"#)
),
).await.unwrap();

test_context.set_primary_self_addr(new_addr).await.unwrap();
// ensure_secret_key_exists() is called during configure
crate::e2ee::ensure_secret_key_exists(test_context)
Expand Down
5 changes: 4 additions & 1 deletion src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ impl ConfiguredLoginParam {
.unwrap_or_default();
let oauth2 = matches!(server_flags & DC_LP_AUTH_FLAGS, DC_LP_AUTH_OAUTH2);

let provider = context.get_configured_provider().await?;
let provider = context
.get_config(Config::ConfiguredProvider)
.await?
.and_then(|cfg| get_provider_by_id(&cfg));

let imap;
let smtp;
Expand Down