[resources/maildir] Reload configuraton on configuration change
ClosedPublic

Authored by poboiko on Mar 6 2020, 10:00 PM.

Details

Summary

When user adds new maildir, a new resource gets created, with the default
directory ~/.local/share/local-mail. Since it's a new resource, with no
proper configuration, an attemptConfigRestoring() is called, which changes
it to ~/.local/share/akonadi_maildir_resource#. It's stored inside
mSettings->path().

Then a dialog appears, where user can choose prefered directory. It gets
written to the config file; then configurationChanged gets called.
We call mSettings->save(), which overwrites the path provided by user with
the default one (~/.local/share/akonadi_maildir_resource#), making it
impossible to create a new maildir anywhere else.

Just use load() instead, it makes more sense when configuration was changed.

BUG: 416287
CCBUG: 415245
CCBUG: 415922

Test Plan
  1. Create a new maildir resource pointing to /tmp/dummy.
  2. The resource gets created, with the name dummy. /tmp/dummy gets created.
  3. Drop some mails into it via KMail. Mails appear inside /tmp/dummy

Diff Detail

Repository
R44 KDE PIM Runtime
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
poboiko created this revision.Mar 6 2020, 10:00 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptMar 6 2020, 10:00 PM
poboiko requested review of this revision.Mar 6 2020, 10:00 PM

BTW, could anyone explain the reasoning behind attemptConfigRestoring?
It does quite a lot of stuff for new maildir, even before user provided a folder, which doesn't make any sense.
And if the maildir is not new, where could its config vanish?

dvratil accepted this revision.Mar 17 2020, 1:24 PM

Lots of the maildir code is from before Akonadi times and there's huge technical debt, I don't think anyone touched that code in ages, so it probably just accumulated various functionality throughout the years...

I haven't tested it, but your explanation sounds solid. Thanks a lot for diving into this!

This revision is now accepted and ready to land.Mar 17 2020, 1:24 PM
wbauer added a subscriber: wbauer.Mar 18 2020, 7:58 PM

With this change, all new maildir resources are now named "local-mail" and use ~/.local/share/local-mail/ by default, instead of something unique as before.

And this also affects new notes collections (i.e. akonotes resources) in knotes that now also always get named "local-mail" and use ~/.local/share/local-mail/ by default.

wbauer added a comment.EditedMar 18 2020, 8:06 PM

PS: AIUI, at least one thing that attemptConfigRestoring() does is trying to give every new resource a unique storage location, something like ~/.local/share/akonadi_maildir_resource_1/ (or ~/.local/share/notes/akonadi_akonotes_resource_1/), by default.

Also, I think this would now always change the resource name (to the name of the directory) when the user reconfigures the storage path, even if it was explicitly set to something (like "My mails") before.
I'm not sure that's really desired?

Also, I think this would now always change the resource name (to the name of the directory) when the user reconfigures the storage path, even if it was explicitly set to something (like "My mails") before.
I'm not sure that's really desired?

And as I just noticed, it also renames the default resources.
If you try on a fresh user account, they will be named according to the used directory now instead of a translated "Local Mail" or "Notes".

poboiko planned changes to this revision.Mar 20 2020, 4:18 PM

Hmm, okay, thanks for testing! I'll look into those issues.

poboiko updated this revision to Diff 79160.Apr 2 2020, 5:24 PM

Save settings inside attemptConfigRestoring; do not override user-specified name
(it is better to have a special "Name" field in the config dialog for this purpose)

This revision is now accepted and ready to land.Apr 2 2020, 5:24 PM
poboiko added a comment.EditedApr 2 2020, 5:28 PM

I'm not yet sure it works as expected together with D28523: Save configuration when creating resources for new user, it still needs testing.

When I create a new user, sometimes "Local Folders" get created right after first login, but the folder is akonadi_maildir_resource_0 (instead of local-mail);
sometimes "Local Folders" get created only after I run KMail for the first time, with the proper folder ("local-mail"), but also sometimes KMail crashes with weird Invalid parent message.
Weird as hell. Need to investigate it.


UPD: OK, it might have been an issue with not-so-fresh-start. I tried removing whole home folder of a new test user, rebooting and logging in, it seems to be working just fine, new resources are created with a proper name and proper folders.

And I am still able to change the folder of an existing resource so some another place, as well as create a new resource in non-default localtion. However, I would appreciate if someone tested it too, just to be sure...

Since D28523: Save configuration when creating resources for new user was landed, I think this one should be fairly safe to land.
Any objections? Should I go for 20.04 branch?

No objections from my side.

I just tested it a bit (sorry for the delay...), and I can't seem to reproduce the problems I noticed with the first version (i.e. the default resources are named as expected now, new resources get a unique folder by default again).
Changing the path for an existing resource seems to work as expected now too (I still have to manually "Restart" the resource to actually see the content of the new directory, but that's certainly unrelated to this change).

The summary is no longer correct though, at least the last paragraph.

PS:

but also sometimes KMail crashes with weird Invalid parent message.

That's probably https://bugs.kde.org/show_bug.cgi?id=380171.
Happens here too on a fresh account when starting kontact the first time (subsequent starts are fine).

I had a slight hope that maybe your other patch ( D28523 ) might fix that, but apparently not unfortunately...

poboiko edited the summary of this revision. (Show Details)May 1 2020, 11:16 AM
wbauer added a comment.May 1 2020, 1:05 PM

(I still have to manually "Restart" the resource to actually see the content of the new directory, but that's certainly unrelated to this change).

Sorry, I just noticed that I tested this *without* the patch applied by mistake.
With the patch, the change actually is picked up immediately now and the resource automatically shows the new directory's content.

So definitely an improvement, I'd say.

dvratil accepted this revision.May 2 2020, 9:35 PM

Thanks. Yes, please land this on 20.04 branch.

This revision was automatically updated to reflect the committed changes.