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

Support xdg-email via mailto: scheme #162

Closed
toastal opened this issue Jun 3, 2021 · 16 comments
Closed

Support xdg-email via mailto: scheme #162

toastal opened this issue Jun 3, 2021 · 16 comments

Comments

@toastal
Copy link
Contributor

toastal commented Jun 3, 2021

https://www.systutorials.com/docs/linux/man/1-xdg-email/

By using the himalaya.desktop file, I discovered new errors

$ xdg-email --body "test"                                      
error: The subcommand 'mailto:?body=test' wasn't recognized
	Did you mean 'mailboxes'?

If you believe you received this message in error, try re-running with 'himalaya -- mailto:?body=test'

USAGE:
    himalaya [OPTIONS] [SUBCOMMAND]

For more information try --help

This looks like the mailto: protocol you might see on an HTML anchor <a href="mailto:[email protected]?body=xx&cc=yy">mail it</a>. With this being the XDG standard, it would be nice if this mailto: were given a special case and handed off to himalaya write. What this would then allow is downstream scripts to hand-off email duty to whatever tool the user has set.

@toastal toastal changed the title Support xdg-email Support xdg-email via mailto: scheme Jun 3, 2021
@soywod
Copy link
Member

soywod commented Jun 3, 2021

Maybe we should introduce a new subcommand (let's say mailto) for this specific use case. This way we can also replace the Exec command in the .desktop file with himalaya mailto -- %U. What do you think?

@toastal
Copy link
Contributor Author

toastal commented Jun 3, 2021

I would disagree. As a user, if I saw a application menu item for Himalaya (ala the Start menu in Windows), I would expect:

  1. Default terminal opens
  2. My default inbox is shown (maybe in the Vim client, I dunno)

This is what the default action should probably be (which is why himalaya with no args does exactly this). I added "Compose" as an Action because it would be the second most common task: starting a blank message.

xdg-email is just going to pass this mailto: scheme to the default command. For reference, thunderbird %U is for Thunderbird.


Docs show:

Description

xdg-email opens the user's preferred e-mail composer in order to send a mail to
address(es) or mailto-uri. RFC2368 defines mailto: URIs. xdg-email limits
support to, cc, subject and body fields in mailto-uri, all other fields are
silently ignored. address(es) must follow the syntax of RFC822. Multiple
addresses may be provided as separate arguments.

All information provided on the command line is used to prefill corresponding
fields in the user's e-mail composer. The user will have the opportunity to
change any of this information before actually sending the e-mail.

Examples

xdg-email 'Jeremy White <[email protected]>'
xdg-email --attach /tmp/logo.png \
          --subject 'Logo contest' \
          --body 'Attached you find the logo for the contest.' \
          '[email protected]'
xdg-email --subject 'Your password is about to expire' \
          '[email protected]' '[email protected]' '[email protected]'

which is just handed off to the default .desktop file. I assume given this scheme, the onus is the client is to recognize and use this information. If you do a web search for like "how to send email using default mail app" or whatever, everyone will point you to using xdg-email so it's probably best to support it "as is".

That last command for reference:

$ xdg-email --subject 'Your password is about to expire' \                                                       
                      '[email protected]' '[email protected]' '[email protected]'
error: Found argument 'mailto:[email protected]?subject=Your%20password%20is%20about%20to%20expire&[email protected]&[email protected]' which wasn't expected, or isn't valid in this context

USAGE:
    himalaya [OPTIONS] [SUBCOMMAND]

For more information try --help

Other effects: I would assume this is similar if not exactly what a browser would give you too which is another common vector for opening the TUI.

Thoughts?

@toastal
Copy link
Contributor Author

toastal commented Jun 3, 2021

I have never written C but here's what NeoMutt appears to be doing

https://github.com/neomutt/neomutt/blob/a5f8317a52aca8dee96335888eb17ac53c959805/main.c#L865

And it being in the main file with argv tells me it's parsed as an input arg.

@soywod
Copy link
Member

soywod commented Jun 3, 2021

I totally agree with you. Thank you for your deep analysis.

The template API I refactored recently really looks like the xdg-email one, I think a simple bridge could be enough. I will take care of this one ASAP.

@soywod soywod self-assigned this Jun 3, 2021
@soywod soywod added cli labels Jun 5, 2021
@soywod soywod added this to the v1.0.0 milestone Jun 5, 2021
@soywod
Copy link
Member

soywod commented Aug 4, 2021

After diving into this issue, I realize that a simple bridge will not be enough. In fact we need to be able to parse the mailto URL scheme (which is specified in the RFC2368). I did not find a crate doing this job. I'm thinking about creating a special crate for this purpose, what do you think @toastal?

@soywod
Copy link
Member

soywod commented Aug 4, 2021

Wait, in fact I just tried with https://crates.io/crates/url and it works well. I thought it was only for URLs, but it seems to be more generic. Good news!

@toastal
Copy link
Contributor Author

toastal commented Aug 4, 2021

Good to hear!

soywod added a commit that referenced this issue Aug 4, 2021
@soywod
Copy link
Member

soywod commented Aug 4, 2021

I just pushed a first attempt. Could you try and let me know? Notice that attachments are not handled yet (I would like to validate the model with you first).

@soywod
Copy link
Member

soywod commented Aug 4, 2021

Oops, I forgot the From header. I just pushed the fix!

@TornaxO7
Copy link
Contributor

Can this be closed or does this issue still exist?

@soywod
Copy link
Member

soywod commented Sep 11, 2021

Well, I would like to wait for @toastal to approve the fix whenever he can. It's been a while tho. Let's wait a bit more before closing!

@toastal
Copy link
Contributor Author

toastal commented Sep 11, 2021

Approve what?

I haven't seen a new release cut, so I'm still on the latest stable from my package manager.

@TornaxO7
Copy link
Contributor

The master branch has been merged with my PR with several changes. So it might fix your issue as well. Could you please try it again with the master branch?

@soywod
Copy link
Member

soywod commented Sep 12, 2021

Approve what?

I haven't seen a new release cut, so I'm still on the latest stable from my package manager.

I was referring to this comment of mine: #162 (comment). I can also put this feature in the next release and I will let you open an issue if sth does not work as expected? I just wanted to be sure to have implemented the thing correctly (as you described).

@toastal
Copy link
Contributor Author

toastal commented Sep 13, 2021

As I described? 😅 I'm no expert; I was just relaying what other mail apps were doing/expecting. I only vaguely know Rust, but it seems okay. A faster, even slightly broken release would be preferable. Currently the app is mildly broken on Linux because of the desktop file passing in arguments that Himalaya cannot handle which makes it able to but unsuitable to be the default mail app on GNU/Linux.

@soywod
Copy link
Member

soywod commented Sep 13, 2021

Alright, then let's see the result in the next release. Thanks!

@soywod soywod closed this as completed Sep 13, 2021
@soywod soywod removed their assignment Feb 11, 2022
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

No branches or pull requests

3 participants