about summary refs log tree commit diff
path: root/contrib
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-10-15 17:11:35 +0200
committerLeah Neukirchen <leah@vuxu.org>2020-10-15 17:11:35 +0200
commitb076d09f3abb4fb1d352f6f7448770d15d5709ca (patch)
tree955bb272b1970877a840e938755b3ca281c77f11 /contrib
parent5d8f070e260b061a1d3c219200276d20045c4bdc (diff)
downloadmblaze-b076d09f3abb4fb1d352f6f7448770d15d5709ca.tar.gz
mblaze-b076d09f3abb4fb1d352f6f7448770d15d5709ca.tar.xz
mblaze-b076d09f3abb4fb1d352f6f7448770d15d5709ca.zip
add contrib/mmailto
Closes #189.

This does not work with terminal emulators that don't use -e or
properly support arbitrary arguments after it.  Here's a nickel,
get yourself a proper terminal emulator.
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/mmailto58
1 files changed, 58 insertions, 0 deletions
diff --git a/contrib/mmailto b/contrib/mmailto
new file mode 100755
index 0000000..7feabb4
--- /dev/null
+++ b/contrib/mmailto
@@ -0,0 +1,58 @@
+#!/bin/sh
+# mmailto mailto:... - mailto: handler spawning mcom in a terminal emulator
+
+tryterm() {
+	if [ -z "$TERMINAL" ] && command -v "$1" >/dev/null; then
+		TERMINAL="$*"
+	fi
+}
+
+tryterm x-terminal-emulator
+tryterm urxvt
+tryterm xterm
+
+if [ -z "$TERMINAL" ]; then
+	echo 'No terminal emulator found, set $TERMINAL.' 1>&2
+        exit 1
+fi
+
+IFS='
+'
+
+exec $TERMINAL -e 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)
+      if (c == "\n") c = " "
+      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])
+  }
+}
+'
+)