Skip to content
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

fix: Set Config::NotifyAboutWrongPw before saving configuration (#5896) #5967

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iequidoo
Copy link
Collaborator

@iequidoo iequidoo commented Sep 14, 2024

Fix #5896

@iequidoo iequidoo marked this pull request as ready for review September 14, 2024 02:01
@link2xt
Copy link
Collaborator

link2xt commented Sep 16, 2024

Have you checked that during failed configuration device message is not added? During configuration Imap::connect is called here:

let mut imap_session = match imap.connect(ctx).await {

It adds device message if it fails second time. I guess login_failed_once is set to false and device message will not be added.

src/configure.rs Outdated
.await?;
let configured_param = configure(self, &param).await?;
if old_addr.is_none() {
self.set_config_internal(Config::NotifyAboutWrongPw, Some("1"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to set it again? Is there a code path that resets NotifyAboutWrongPw during configure()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

old_addr.is_none() means that configuration is running the first time. So, we need to set NotifyAboutWrongPw because it's 0 by default

@link2xt
Copy link
Collaborator

link2xt commented Sep 16, 2024

Maybe Config::NotifyAboutWrongPw can be removed completely? In-memory login_failed_once is enough to prevent adding device message if we only try to connect once. If we fail multiple times with a single Imap instance, add device message with some special label to prevent spamming device chat. If we succeed, remove the message with this label.

@iequidoo
Copy link
Collaborator Author

Have you checked that during failed configuration device message is not added? During configuration Imap::connect is called here:

let mut imap_session = match imap.connect(ctx).await {

It adds device message if it fails second time. I guess login_failed_once is set to false and device message will not be added.

During initial configuration it's not added, but if the user runs reconfiguration, it's added unfortunately. Because it's not safe to disable NotifyAboutWrongPw during reconfiguration, otherwise if the program crashes, the setting will remain disabled. This can be fixed if we pass more context to configure().

Let's not complicate the logic and always set `Config::NotifyAboutWrongPw` before saving
configuration, better if a wrong password notification is shown once more than not shown at all. It
shouldn't be a big problem because reconfiguration is a manual action and isn't done frequently.

Also for the same reason reset `Config::NotifyAboutWrongPw` only after a successful addition of the
appropriate device message.
@iequidoo iequidoo changed the title fix: Set Config::NotifyAboutWrongPw before reconfiguring (#5896) fix: Set Config::NotifyAboutWrongPw before saving configuration (#5896) Sep 17, 2024
@iequidoo
Copy link
Collaborator Author

iequidoo commented Sep 17, 2024

I tried to simplify the logic and now (re)configuration doesn't add device messages about wrong password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config::NotifyAboutWrongPw logic is buggy
2 participants