diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index 69df000a7..ea1e45e27 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -2209,6 +2209,19 @@ def test_configure_error_msgs_wrong_pw(acfactory): # Password is wrong so it definitely has to say something about "password" assert "password" in ev.data2 + ac1.stop_io() + ac1.set_config("mail_pw", "abc") # Wrong mail pw + ac1.configure() + while True: + ev = ac1._evtracker.get_matching("DC_EVENT_CONFIGURE_PROGRESS") + print(f"Configuration progress: {ev.data1}") + if ev.data1 == 0: + break + assert "password" in ev.data2 + # Account will continue to work with the old password, so if it becomes wrong, a notification + # must be shown. + assert ac1.get_config("notify_about_wrong_pw") == "1" + def test_configure_error_msgs_invalid_server(acfactory): ac2 = acfactory.get_unconfigured_account() diff --git a/src/configure.rs b/src/configure.rs index a46338d9c..58f5aab5b 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -111,15 +111,10 @@ impl Context { let param = EnteredLoginParam::load(self).await?; let old_addr = self.get_config(Config::ConfiguredAddr).await?; - - let configured_param_res = configure(self, ¶m).await; - self.set_config_internal(Config::NotifyAboutWrongPw, None) - .await?; - - on_configure_completed(self, configured_param_res?, old_addr).await?; - + let configured_param = configure(self, ¶m).await?; self.set_config_internal(Config::NotifyAboutWrongPw, Some("1")) .await?; + on_configure_completed(self, configured_param, old_addr).await?; Ok(()) } } @@ -417,7 +412,8 @@ async fn configure(ctx: &Context, param: &EnteredLoginParam) -> Result session, Err(err) => bail!("{}", nicer_configuration_error(ctx, err.to_string()).await), }; diff --git a/src/imap.rs b/src/imap.rs index 0a74b8b6b..297af1a2a 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -290,7 +290,11 @@ impl Imap { /// Calling this function is not enough to perform IMAP operations. Use [`Imap::prepare`] /// instead if you are going to actually use connection rather than trying connection /// parameters. - pub(crate) async fn connect(&mut self, context: &Context) -> Result { + pub(crate) async fn connect( + &mut self, + context: &Context, + configuring: bool, + ) -> Result { let now = tools::Time::now(); let until_can_send = max( min(self.conn_last_try, now) @@ -416,19 +420,12 @@ impl Imap { warn!(context, "IMAP failed to login: {err:#}."); first_error.get_or_insert(format_err!("{message} ({err:#})")); - let lock = context.wrong_pw_warning_mutex.lock().await; - if self.login_failed_once + let _lock = context.wrong_pw_warning_mutex.lock().await; + if !configuring + && self.login_failed_once && err_str.to_lowercase().contains("authentication") && context.get_config_bool(Config::NotifyAboutWrongPw).await? { - if let Err(e) = context - .set_config_internal(Config::NotifyAboutWrongPw, None) - .await - { - warn!(context, "{e:#}."); - } - drop(lock); - let mut msg = Message::new(Viewtype::Text); msg.text.clone_from(&message); if let Err(e) = chat::add_device_msg_with_importance( @@ -440,6 +437,12 @@ impl Imap { .await { warn!(context, "Failed to add device message: {e:#}."); + } else { + context + .set_config_internal(Config::NotifyAboutWrongPw, None) + .await + .log_err(context) + .ok(); } } else { self.login_failed_once = true; @@ -456,7 +459,8 @@ impl Imap { /// Ensure that IMAP client is connected, folders are created and IMAP capabilities are /// determined. pub(crate) async fn prepare(&mut self, context: &Context) -> Result { - let mut session = match self.connect(context).await { + let configuring = false; + let mut session = match self.connect(context, configuring).await { Ok(session) => session, Err(err) => { self.connectivity.set_err(context, &err).await;