Bug 420513 - kde-open5 ignores default configured mail client
Summary: kde-open5 ignores default configured mail client
Status: REOPENED
Alias: None
Product: kde-cli-tools
Classification: Plasma
Component: general (other bugs)
Version First Reported In: 5.18.4
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Aleix Pol
URL:
Keywords: junior-jobs
Depends on:
Blocks:
 
Reported: 2020-04-24 13:43 UTC by Konstantin Kharlamov
Modified: 2020-04-25 14:02 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Kharlamov 2020-04-24 13:43:55 UTC
SUMMARY

I noted that opening mailto links in browsers results in kmail trying to get launched (which ATM is not even installed). That is despite Thunderbird being configured as default mail client in systemsettings5.

STEPS TO REPRODUCE
1. Open `systemsettings5`
2. Go to `Aplications → Default Aplications → Email Client`, set checkbox "Use a different email client", and write as the client `thunderbird`. Click `Apply` in the bottom-right corner.
3. Run in terminal `kde-open5 mailto:`

OBSERVED RESULT

It tries opening kmail.

EXPECTED RESULT

It tries opening thunderbird.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Archlinux
KDE Plasma Version: 5.18.4
KDE Frameworks Version: 5.69.0
Qt Version: 5.14.2

ADDITIONAL INFORMATION

To fix that so far I tried (and nothing worked):

1. Setting in `systemsettings5` thunderbird both by choosing with mouse and by typing manually (the difference is that I type `thunderbird`, whereas choosing with mouse results in `thun`)
2. Renaming `kmailservice` binary
3. Doing `strace -e open,openat kde-open5 mailto: 2>&1 | perl -lane 'print /".+?"/g if /home/ and not /No such file/'` and then grepping over all those files case-insensitive "mail" and "bird". That only gave a match in some of "recent files", nothing useful.
4. Repeating the 3rd point with `kmailservice` which `kde-open5` tries running. No result.
Comment 1 Konstantin Kharlamov 2020-04-24 18:46:16 UTC
FWIW I tried building it, but last two commits whose build configuration succeeds on my system are bb7e91e and da969d6, they're somewhat away from the master, and building for both of them ends up with same error:

../keditfiletype/mimetypedata.cpp: In member function ‘QStringList MimeTypeData::getAppOffers() const’:
../keditfiletype/mimetypedata.cpp:217:20: error: ‘class KService’ has no member named ‘allowAsDefault’
  217 |         if ((*it)->allowAsDefault())
      |                    ^~~~~~~~~~~~~~


Oh, well. I figured that kde-open5 consists of a single cpp file "kioclient.cpp", and that likely opening of a email/url happens at `ClientApp::kde_open()`. I am not completely sure though as I didn't manage to check it out. But if anybody is interested, that looks like nice starting point.
Comment 2 Konstantin Kharlamov 2020-04-24 23:38:51 UTC
Okay, so I debugged that a bit (I made use of latest release), turns out I was right about `kde_open()`.

On this line `KRun * run = new KRun( info.url, nullptr );`, the `url` is the `mailto:` string. Whole magic of finding the mail client happens inside `KRun` class.

The docs for KRun are here https://api.kde.org/frameworks/kio/html/classKRun.html they say it will run the app that is bound to a protocol given, but there's nothing about how that gets determined.
Comment 3 Konstantin Kharlamov 2020-04-25 00:13:06 UTC
Okay, so, I managed to find out how KRun apparently figures that out.

The "mailto:" as well as any url like "foo:" is a part of shared-mime-info-spec specification that is called "x-scheme-handler". For "mailto:" that would be "x-scheme-handler/mailto".

This means I could try setting the type with xdg-utils. And this is where the problem turns up:

    $ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default x-scheme-handler/mailto
    Running KDE trader query "x-scheme-handler/mailto" mimetype and "Application" servicetype
    kmailservice.desktop
    $ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime default thunderbird.desktop x-scheme-handler/mailto
    make_default_kde: No kde runtime detected
    make_default_generic thunderbird.desktop x-scheme-handler/mailto
    Updating /home/constantine/.config/mimeapps.list
    $ grep mail /home/constantine/.config/mimeapps.list
    x-scheme-handler/mailto=thunderbird.desktop
    $ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default x-scheme-handler/mailto
    Running KDE trader query "x-scheme-handler/mailto" mimetype and "Application" servicetype
    kmailservice.desktop

So apparently the bug is not in kde-open5 (which simply tries default app), nor in systemsettings5 (which same as xdg-mime is sure that it successfully changed the default client), but instead in xdg-utils which does not use the default mail client.

Hence, closing this as invalid.
Comment 4 Rex Dieter 2020-04-25 14:02:49 UTC
I would argue there is a bug... in systemsettings->default applications

When one sets a default email client there, part of that implementation should also set the synthetic x-scheme-handler/mailto mimetype 

(Same argument can be applied for when setting a default web browser too)