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

Anyway to handle "mailto:" from inside mblaze ? #189

Closed
stacyharper opened this issue Oct 15, 2020 · 9 comments
Closed

Anyway to handle "mailto:" from inside mblaze ? #189

stacyharper opened this issue Oct 15, 2020 · 9 comments

Comments

@stacyharper
Copy link
Contributor

Hello there,

I'd like to use mcom to handle the mailto: protocol from my personal xdg-open.

How should I do that ? Does mblaze can handle it directly ?

Thanks a lot !

@leahneukirchen
Copy link
Owner

Very rough idea:

#!/bin/sh

mailto=$1
mailto="mailto:${mailto#mailto:}"
xterm -e mcom "$1"

Needs better parsing for subject etc. I would add something like this to contrib.

@stacyharper
Copy link
Contributor Author

stacyharper commented Oct 15, 2020

I use something very similar but I do not handle bcc, subject, in-reply-to, and others. I dunno if mcom can take additional arguments for those and I'd prefer mblaze to handle it internaly.

ps: here a typical complex mailto that I would need a solution "mailto:~mil/sxmo-devel@lists.sr.ht?cc=Eddie%20Barraco%20%3Ccontact%40eddiebarraco.fr%3E&in-reply-to=%3C22DDDZGB7TN5A.3QNVU0UJ98DBD%40eddiebarraco.fr%3E&subject=Re%3A%20Current%20status%20of%20telephony%3F"

@leahneukirchen
Copy link
Owner

Yes, -cc ... -reply-to ... etc.

@leahneukirchen
Copy link
Owner

Another try:

IFS='
'

mcom $(
awk -v url="$1" '

function decode(s) {
  hexdigits = "0123456789abcdef"
  for (i = 1; i < length(s); i++) {
    if (substr(s, i, 3) ~ /%[0-9a-fA-F][0-9a-fA-F]/) {
      c = sprintf("%c", (index(hexdigits, tolower(substr(s, i+1, 1)))-1) * 16 + \
                         index(hexdigits, tolower(substr(s, i+2, 1)))-1)
      s = substr(s, 1, i-1) c substr(s, i+3)
      i += 2
    }
  }
  return s
}

BEGIN {
  url = decode(url)
  sub(/^mailto:/, "", url)
  split(url, parts, "?")
  to = parts[1]
  split(parts[2], fields, "&") 
  args[1] = to
  for (i in fields) {
    split(fields[i], kv, "=")
    if (kv[1] != "r") {
      args[length(args)+1] = "-" kv[1]
      args[length(args)+1] =  kv[2]
    }
  }
  for (i in args) {
    print decode(args[i])
  }
}
'
)

@stacyharper
Copy link
Contributor Author

stacyharper commented Oct 15, 2020

wow amazing, that rocks !

ps: So I just wrote a mmailto to wrap this awk script and that do the job perfectly.

Thanks a lot !

@leahneukirchen
Copy link
Owner

ok, then i'll wrap it up and add it.

I'm not sure why urldecoding twice is needed, but oh well.

@stacyharper
Copy link
Contributor Author

I pretty much think something is now broken while it worked in the first place.

We now got one line per subject word:

$ mmailto "mailto:contact@foobar.com?subject=toto%20titi" 
To: contact@foobar.com
Cc:
Bcc:
Subject: toto
Subject: titi
From: Toto Titi <toto@titi.com>
Message-Id: <3N9CFLPTCRUVZ.3861YVA3MMQR4@tototiti.net>
User-Agent: mblaze/1.1

But the mmailto seems to do its job. Something changed in how mcom handle arguments in the recent release ?

@leahneukirchen
Copy link
Owner

Can't reproduce, it calls here as follows:

5772 urxvt -e mcom contact@foobar.com -subject 'toto titi'

@stacyharper
Copy link
Contributor Author

stacyharper commented Apr 7, 2021 via email

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

2 participants