Skip to content

Commit 9933a42

Browse files
committed
fix: Create mvbox on setting mvbox_move
1 parent 8a54c22 commit 9933a42

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

src/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use strum::{EnumProperty, IntoEnumIterator};
1010
use strum_macros::{AsRefStr, Display, EnumIter, EnumProperty, EnumString};
1111

1212
use crate::blob::BlobObject;
13-
use crate::constants::DC_VERSION_STR;
13+
use crate::constants::{self, DC_VERSION_STR};
1414
use crate::contact::addr_cmp;
1515
use crate::context::Context;
1616
use crate::events::EventType;
@@ -596,6 +596,12 @@ impl Context {
596596
.set_raw_config(key.as_ref(), value.map(|s| s.to_lowercase()).as_deref())
597597
.await?;
598598
}
599+
Config::MvboxMove => {
600+
self.sql.set_raw_config(key.as_ref(), value).await?;
601+
self.sql
602+
.set_raw_config(constants::DC_FOLDERS_CONFIGURED_KEY, None)
603+
.await?;
604+
}
599605
_ => {
600606
self.sql.set_raw_config(key.as_ref(), value).await?;
601607
}

src/constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ pub(crate) const WORSE_AVATAR_SIZE: u32 = 128;
206206
pub const BALANCED_IMAGE_SIZE: u32 = 1280;
207207
pub const WORSE_IMAGE_SIZE: u32 = 640;
208208

209+
// Key for the folder configuration version (see below).
210+
pub(crate) const DC_FOLDERS_CONFIGURED_KEY: &str = "folders_configured";
209211
// this value can be increased if the folder configuration is changed and must be redone on next program start
210212
pub(crate) const DC_FOLDERS_CONFIGURED_VERSION: i32 = 4;
211213

src/context.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::aheader::EncryptPreference;
1818
use crate::chat::{get_chat_cnt, ChatId, ProtectionStatus};
1919
use crate::config::Config;
2020
use crate::constants::{
21-
DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT, DC_CHAT_ID_TRASH, DC_VERSION_STR,
21+
self, DC_BACKGROUND_FETCH_QUOTA_CHECK_RATELIMIT, DC_CHAT_ID_TRASH, DC_VERSION_STR,
2222
};
2323
use crate::contact::Contact;
2424
use crate::debug_logging::DebugLogging;
@@ -672,7 +672,7 @@ impl Context {
672672
let only_fetch_mvbox = self.get_config_int(Config::OnlyFetchMvbox).await?;
673673
let folders_configured = self
674674
.sql
675-
.get_raw_config_int("folders_configured")
675+
.get_raw_config_int(constants::DC_FOLDERS_CONFIGURED_KEY)
676676
.await?
677677
.unwrap_or_default();
678678

@@ -764,7 +764,10 @@ impl Context {
764764
res.insert("sentbox_watch", sentbox_watch.to_string());
765765
res.insert("mvbox_move", mvbox_move.to_string());
766766
res.insert("only_fetch_mvbox", only_fetch_mvbox.to_string());
767-
res.insert("folders_configured", folders_configured.to_string());
767+
res.insert(
768+
constants::DC_FOLDERS_CONFIGURED_KEY,
769+
folders_configured.to_string(),
770+
);
768771
res.insert("configured_inbox_folder", configured_inbox_folder);
769772
res.insert("configured_sentbox_folder", configured_sentbox_folder);
770773
res.insert("configured_mvbox_folder", configured_mvbox_folder);

src/imap.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ use tokio::sync::RwLock;
2222

2323
use crate::chat::{self, ChatId, ChatIdBlocked};
2424
use crate::config::Config;
25-
use crate::constants::{
26-
Blocked, Chattype, ShowEmails, DC_FETCH_EXISTING_MSGS_COUNT, DC_FOLDERS_CONFIGURED_VERSION,
27-
};
25+
use crate::constants::{self, Blocked, Chattype, ShowEmails, DC_FETCH_EXISTING_MSGS_COUNT};
2826
use crate::contact::{normalize_name, Contact, ContactAddress, ContactId, Modifier, Origin};
2927
use crate::context::Context;
3028
use crate::events::EventType;
@@ -1767,11 +1765,17 @@ impl Imap {
17671765
context: &Context,
17681766
create_mvbox: bool,
17691767
) -> Result<()> {
1770-
let folders_configured = context.sql.get_raw_config_int("folders_configured").await?;
1771-
if folders_configured.unwrap_or_default() >= DC_FOLDERS_CONFIGURED_VERSION {
1768+
let folders_configured = context
1769+
.sql
1770+
.get_raw_config_int(constants::DC_FOLDERS_CONFIGURED_KEY)
1771+
.await?;
1772+
if folders_configured.unwrap_or_default() >= constants::DC_FOLDERS_CONFIGURED_VERSION {
17721773
return Ok(());
17731774
}
1774-
1775+
if let Err(err) = self.connect(context).await {
1776+
self.connectivity.set_err(context, &err).await;
1777+
return Err(err);
1778+
}
17751779
self.configure_folders(context, create_mvbox).await
17761780
}
17771781

@@ -1893,7 +1897,10 @@ impl Imap {
18931897
}
18941898
context
18951899
.sql
1896-
.set_raw_config_int("folders_configured", DC_FOLDERS_CONFIGURED_VERSION)
1900+
.set_raw_config_int(
1901+
constants::DC_FOLDERS_CONFIGURED_KEY,
1902+
constants::DC_FOLDERS_CONFIGURED_VERSION,
1903+
)
18971904
.await?;
18981905

18991906
info!(context, "FINISHED configuring IMAP-folders.");

src/scheduler.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,20 @@ pub async fn convert_folder_meaning(
521521
/// critical operation fails such as fetching new messages fails, connection is reset via
522522
/// `trigger_reconnect`, so a fresh one can be opened.
523523
async fn fetch_idle(ctx: &Context, connection: &mut Imap, folder_meaning: FolderMeaning) {
524+
let create_mvbox = true;
525+
if let Err(err) = connection
526+
.ensure_configured_folders(ctx, create_mvbox)
527+
.await
528+
{
529+
warn!(
530+
ctx,
531+
"Cannot watch {folder_meaning}, ensure_configured_folders() failed: {:#}", err,
532+
);
533+
connection
534+
.fake_idle(ctx, None, FolderMeaning::Unknown)
535+
.await;
536+
return;
537+
}
524538
let (folder_config, watch_folder) = match convert_folder_meaning(ctx, folder_meaning).await {
525539
Ok(meaning) => meaning,
526540
Err(error) => {

0 commit comments

Comments
 (0)