leahneukirchen / mblaze

Unix utilities to deal with Maildir
Other
441 stars 48 forks source link

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

Closed stacyharper closed 3 years ago

stacyharper commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

leahneukirchen commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

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

stacyharper commented 3 years ago

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 commented 3 years ago

Can't reproduce, it calls here as follows:

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

stacyharper commented 3 years ago

Okay got it ! My mmailto was missing the IFS setup. It now works, ty :D