[PATCH] contrib: add notmuch-emacs-mailto.sh

Subject: [PATCH] contrib: add notmuch-emacs-mailto.sh

Date: Tue, 1 Jul 2014 21:06:32 +0300

To: notmuch@notmuchmail.org

Cc: tomi.ollila@iki.fi

From: Tomi Ollila


Add a shell handler which sends to/invokes notmuch-emacs mua
mailto: urls for further processing.
---

I wish notmuch-mua-mailto (not (yet) in notmuch improves as
"promised" in id:87vcin2fo6.fsf@servo.finestructure.net ;D
(that version seems to do more than implementation of
browse-url-mail (in emacs-23.1/lisp/net/browse-url.el) and
with that buffer is not marked "modified" when some initial
body added).

 contrib/notmuch-emacs-mailto.sh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100755 contrib/notmuch-emacs-mailto.sh

diff --git a/contrib/notmuch-emacs-mailto.sh b/contrib/notmuch-emacs-mailto.sh
new file mode 100755
index 000000000000..03719f806250
--- /dev/null
+++ b/contrib/notmuch-emacs-mailto.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# use notmuch mua via emacsclient or in emacs to handle mailto: request
+
+set -eu
+
+case $# in 0)
+	echo Usage: $0 mailto-url >&2
+	exit 1
+esac
+
+# concatenate args in $* w/o space (note: empty $IFS is somewhat special case)
+IFS=
+
+case $* in *['"\']*)
+	url=`printf %s "$*" | sed 's/\\\\/\\\\\\\\/; s/"/\\\\"/'`
+;; *)	url=$*
+esac
+
+case $url in mailto:*) ;; *) url=mailto:$url ;; esac
+
+unset ALTERNATE_EDITOR
+if "${EMACSCLIENT:=emacsclient}" --eval t >/dev/null 2>&1
+then	exec >/dev/null
+	editor=$EMACSCLIENT
+else	editor=${EMACS:-emacs}
+fi
+
+exec "$editor" --eval "\
+(let ((url \"$url\"))
+  (require 'notmuch)
+  (if (fboundp 'notmuch-mua-mailto)
+      (notmuch-mua-mailto url)
+    (browse-url-mail url)))"
-- 
2.0.0


Thread: