--- /dev/null
+Return-Path: <too@guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 34818431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 10 Jul 2014 14:13:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id V+tidhWHrZwI for <notmuch@notmuchmail.org>;\r
+ Thu, 10 Jul 2014 14:13:17 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 8F573431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 10 Jul 2014 14:13:17 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id 833171000C9; Fri, 11 Jul 2014 00:13:08 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org, jani@nikula.org, david@tethera.net,\r
+ jrollins@finestructure.net\r
+Subject: [DRAFT PATCH] modified notmuch-emacs-mua\r
+Date: Fri, 11 Jul 2014 00:12:59 +0300\r
+Message-Id: <1405026779-29966-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 2.0.0\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 10 Jul 2014 21:13:24 -0000\r
+\r
+Highlights:\r
+\r
+* notmuch-emacs-mua without arguments runs (notmuch-hello)\r
+\r
+* runs emacs(1) in case emacsclient(1) fails to connect to running emacs\r
+\r
+* takes -nw option\r
+\r
+* handles mailto:\r
+\r
+* --from option when sending non-mailto: way\r
+\r
+* -i includes file --body[= ]string inserts string\r
+---\r
+ notmuch-emacs-mua | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 200 insertions(+)\r
+ create mode 100755 notmuch-emacs-mua\r
+\r
+diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
+new file mode 100755\r
+index 0000000..b1696f7\r
+--- /dev/null\r
++++ b/notmuch-emacs-mua\r
+@@ -0,0 +1,200 @@\r
++#!/usr/bin/env bash\r
++# -*- mode: shell-script; sh-basic-offset: 4; tab-width: 8 -*-\r
++#\r
++# notmuch-emacs-mua - start composing a mail on the command line\r
++#\r
++# Copyright © 2014 Jani Nikula\r
++#\r
++# This program is free software: you can redistribute it and/or modify\r
++# it under the terms of the GNU General Public License as published by\r
++# the Free Software Foundation, either version 3 of the License, or\r
++# (at your option) any later version.\r
++#\r
++# This program is distributed in the hope that it will be useful,\r
++# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
++# GNU General Public License for more details.\r
++#\r
++# You should have received a copy of the GNU General Public License\r
++# along with this program. If not, see http://www.gnu.org/licenses/ .\r
++#\r
++# Authors: Jani Nikula <jani@nikula.org>\r
++# Tomi Ollila <tomi.ollila@iki.fi>\r
++#\r
++\r
++set -eu\r
++\r
++# "expand" '\' to '\\' & '"' to '\"'\r
++escape_optarg ()\r
++{\r
++ OPTARG=${OPTARG//\\/\\\\}; OPTARG=${OPTARG//\"/\\\"}\r
++}\r
++\r
++# ditto, in case there is '\n' sequence in the source, otherwise\r
++# "expand" only trailing '\'s to '\\'s\r
++escape_body_optarg ()\r
++{\r
++ case ${OPTARG} in\r
++ *'\"'*) OPTARG=${OPTARG//\\/\\\\} ;;\r
++ *'\') OPTARG=$( printf %s "${OPTARG}" | sed 's/\(\\*\)$/\1\1/' )\r
++ esac\r
++ OPTARG=${OPTARG//\"/\\\"}\r
++}\r
++\r
++unset ALTERNATE_EDITOR\r
++exec_mua ()\r
++{\r
++ if "${EMACSCLIENT:=emacsclient}" --eval t >/dev/null 2>&1\r
++ then\r
++ emacs=$EMACSCLIENT\r
++ # close stdout in case no -nw (and no --print)\r
++ test -n "$W$X" || exec >/dev/null\r
++ else\r
++ emacs=${EMACS:-emacs}\r
++ fi\r
++ ${X:-exec} "$emacs" $W --eval "$*"\r
++ exit\r
++ ${X:-exec "$emacs" $W --eval} "$*"\r
++}\r
++\r
++X=\r
++W=\r
++\r
++SUBJECT= TO= CC= BCC= BODY= FROM= IB=\r
++\r
++while\r
++ # first, handle "long" options which cannot be handled by getopts\r
++ case ${1-} in\r
++ -nw)\r
++ W=-nw\r
++ shift\r
++ continue\r
++ ;;\r
++ mailto:*)\r
++ oIFS=$IFS; IFS=; OPTARG="$*" IFS=$oIFS\r
++ escape_optarg\r
++ exec_mua "(progn (require 'notmuch) (browse-url-mail \"$OPTARG\"))"\r
++ exit\r
++ esac\r
++\r
++ getopts :s:c:b:i:h opt\r
++do\r
++ # Handle errors and long options.\r
++ case ${opt} in\r
++ :)\r
++ echo "$0: short option '-${OPTARG}' requires an argument." >&2\r
++ exit 1\r
++ ;;\r
++ \?)\r
++ opt=$1\r
++ if [[ ${OPTARG} != '-' ]]; then\r
++ echo "$0: unknown short option '-${OPTARG}'." >&2\r
++ exit 1\r
++ fi\r
++\r
++ case ${opt} in\r
++ # Long options with arguments.\r
++ --subject=*|--to=*|--cc=*|--bcc=*|--body=*|--from=*)\r
++ OPTARG=${opt#--*=}\r
++ opt=${opt%%=*}\r
++ ;;\r
++ # Long options with argument in next arg.\r
++ --subject |--to |--cc |--bcc |--body |--from )\r
++ if [[ $# < 2 ]]; then\r
++ echo "$0: option '${opt}' requires an argument." >&2\r
++ exit 1\r
++ fi\r
++ OPTARG=$2\r
++ OPTIND=$((OPTIND + 1))\r
++ ;;\r
++ # Long options without arguments.\r
++ --help|--nw|--print)\r
++ ;;\r
++ *)\r
++ echo "$0: unknown long option '${opt}', or argument mismatch." >&2\r
++ exit 1\r
++ ;;\r
++ esac\r
++ # getopts does not do this for what it considers errors.\r
++ OPTIND=$((OPTIND + 1))\r
++ ;;\r
++ esac\r
++\r
++ case ${opt} in\r
++ --help|h)\r
++ exec man notmuch-emacs-mua\r
++ ;;\r
++ --from)\r
++ escape_optarg\r
++ FROM=${OPTARG}\r
++ ;;\r
++ --subject|s)\r
++ escape_optarg\r
++ SUBJECT=${SUBJECT:+$SUBJECT }${OPTARG}\r
++ ;;\r
++ --to)\r
++ escape_optarg\r
++ TO=${TO:+$TO, }${OPTARG}\r
++ ;;\r
++ --cc|c)\r
++ escape_optarg\r
++ CC=${CC:+$CC, }${OPTARG}\r
++ ;;\r
++ --bcc|b)\r
++ escape_optarg\r
++ BCC=${BCC:+$BCC, }${OPTARG}\r
++ ;;\r
++ i)\r
++ escape_optarg\r
++ if [[ ! -f ${OPTARG} ]]; then\r
++ echo "$0: '${OPTARG}': no such file" >&2\r
++ exit 1\r
++ fi\r
++ IB=${IB}$'\n'" (insert-file \"${OPTARG}\")"\r
++ IB=${IB}$'\n'" (if /= (point) (line-beginning-position) (insert \"\\n\"))"\r
++ ;;\r
++ --body)\r
++ escape_body_optarg\r
++ IB=${IB}$'\n'" (insert \"${OPTARG}\\n\")"\r
++ ;;\r
++ --nw)\r
++ W=-nw\r
++ ;;\r
++ --print)\r
++ X=echo\r
++ ;;\r
++ *)\r
++ # We should never end up here.\r
++ echo "$0: internal error (option '${opt}')." >&2\r
++ exit 1\r
++ ;;\r
++ esac\r
++\r
++ shift $((OPTIND - 1))\r
++ OPTIND=1\r
++done\r
++\r
++# Positional parameters.\r
++for arg; do\r
++ arg=${arg//\\/\\\\}; arg=${arg//\"/\\\"}\r
++ TO=${TO:+$TO, }${arg}\r
++done\r
++\r
++NL=$'\n'\r
++ELISP="\\r
++${CC:+$NL (message-goto-cc) (insert \"$CC\")}\\r
++${BCC:+$NL (message-goto-bcc) (insert \"$BCC\")}\\r
++${IB:+$NL (message-goto-body)$IB}"\r
++\r
++if [[ $TO == '' && $SUBJECT == '' && $ELISP == '' ]]\r
++then\r
++ exec_mua "(progn (require 'notmuch) (notmuch-hello))"\r
++else\r
++ [[ $FROM != '' ]] && OH="(list (cons 'From \"$FROM\"))" || OH=nil\r
++ [[ $TO != '' ]] && TO=\"$TO\" || TO=nil\r
++ [[ $SUBJECT != '' ]] && SUBJECT=\"$SUBJECT\" || SUBJECT=nil\r
++ exec_mua "$NL(progn (require 'notmuch)\r
++ (notmuch-mua-mail $TO $SUBJECT\r
++ $OH nil (notmuch-mua-get-switch-function))\\r
++$ELISP$NL (set-buffer-modified-p nil) (message-goto-to))"\r
++fi\r
+-- \r
+1.9.0\r
+\r