--- /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 878E4431FCB\r
+ for <notmuch@notmuchmail.org>; Tue, 20 Jan 2015 09:54:15 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.438\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438] 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 5oI+kXYniMRP for <notmuch@notmuchmail.org>;\r
+ Tue, 20 Jan 2015 09:54:12 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id AB2F8431FC9\r
+ for <notmuch@notmuchmail.org>; Tue, 20 Jan 2015 09:54:11 -0800 (PST)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id 317D21000F3; Tue, 20 Jan 2015 19:53:46 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org,\r
+ Jani Nikula <jani@nikula.org>\r
+Subject: [DRAFT PATCH v2] modified notmuch-emacs-mua v2\r
+Date: Tue, 20 Jan 2015 19:53:44 +0200\r
+Message-Id: <1421776424-24304-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <1421598115-4889-1-git-send-email-david@tethera.net>\r
+References: <1421598115-4889-1-git-send-email-david@tethera.net>\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: Tue, 20 Jan 2015 17:54:15 -0000\r
+\r
+This is second draft patch of (first being)\r
+\r
+id:1405026779-29966-1-git-send-email-tomi.ollila@iki.fi\r
+\r
+I saw potential problem with only supporting emacsclient(1) in\r
+the version David sent:\r
+id:1421598115-4889-1-git-send-email-david@tethera.net\r
+\r
+(no emacs server running and no tty -- new X client not started)\r
+\r
+therefore I started to modify that part -- and soon adding all features\r
+I'd like to see there. As I expect some bikeshedding to continue I skip\r
+doc update for the time being (to avoid unnecessary work), therefore\r
+calling this as "draft patch".\r
+\r
+This implIments many of my first draft features:\r
+\r
+mailto: is handled if given as first argument (not yet all the nice stuff\r
+Jameson suggested, we'll perhaps get there later...)\r
+\r
+--from option when sending non-mailto: way\r
+\r
+And, -nw (*) in a new way...\r
+\r
+The -i and --body are done as in initial Jani's version ( also as in\r
+id:1421598115-4889-1-git-send-email-david@tethera.net )\r
+\r
+Also, --long SPC value is not implemented, format is --long=value\r
+\r
+In case emacsclient(1) is used and no --no-window-system, '-c' arg is\r
+given to emacsclient like in the version David sent.\r
+\r
+(this means that if emacs is not running on X, user may get this message:\r
+ "emacsclient: could not get terminal name" -- we need to document user\r
+ to give -nw (--no-window-system) option then)\r
+\r
+Other "new" things:\r
+\r
+Option --bodytext to give body content from command line (not documented\r
+yet, but I'll add privacy warning when updating NaMual page.\r
+\r
+Final cursor position goes based on last option given from command line,\r
+unless to: or subject: is missing -- cursor is positioned after these\r
+headers in this case.\r
+\r
+(*) -nw works so that the 'n' is given to getopts and it expects an\r
+argument; the argument is checked being w (this means -nw and -n w are\r
+accepted). this also gives interesting output when one attempts to use\r
+plain '-n' (error message shows next arg concatenated into this or...\r
+"./notmuch-emacs-mua: short option -n requires an argument." -- OK,\r
+forgot to handle this special case at this time...)\r
+\r
+Anyway, I'd rather have -nw and some peculiarity than no -nw at all ;)\r
+\r
+Tomi\r
+---\r
+ notmuch-emacs-mua | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 217 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 000000000000..42275cd1a563\r
+--- /dev/null\r
++++ b/notmuch-emacs-mua\r
+@@ -0,0 +1,217 @@\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
++# Cannot use [[ ]] until we know we have bash.\r
++case ${BASH_VERSION-} in '')\r
++ echo "Not BASH!" >&2\r
++ exit 1\r
++esac\r
++\r
++# escape: "expand" '\' to '\\' & '"' to '\"'\r
++# Calling convention: escape -v var "$arg" (like in bash printf).\r
++escape ()\r
++{\r
++ local arg=${3//\\/\\\\}\r
++ eval $2='${arg//\"/\\\"}'\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 --no-window-system (and no --print).\r
++ test -n "$W$X" || exec >/dev/null\r
++ # W/ emacsclient, use '-c' in case no --no-window-system.\r
++ [[ -n $W ]] || W=-c\r
++ else\r
++ emacs=${EMACS:-emacs}\r
++ fi\r
++ ${X:-exec} "${emacs}" $W --eval "(prog1 'done $*)"\r
++ exit\r
++}\r
++\r
++X= # This is chaged to 'echo' when --print is used.\r
++W= # This is changed to '-nw' when --no-window-system is used.\r
++\r
++SUBJECT= TO= CC= BCC= BODY= FROM=\r
++\r
++unset message_goto # Final elisp function to execute, when defined.\r
++cddone=false\r
++\r
++# "Short circuit" mailto handling.\r
++case ${1-} in mailto:*)\r
++ oIFS=$IFS; IFS=\r
++ escape -v OPTARG "$*"\r
++ IFS=$oIFS\r
++ exec_mua "(require 'notmuch) (browse-url-mail \"$OPTARG\")"\r
++ exit\r
++esac\r
++\r
++while getopts :s:c:b:i:n:h opt; 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=*|--bodytext=*)\r
++ OPTARG=${opt#--*=}\r
++ opt=${opt%%=*}\r
++ ;;\r
++ # Long options without arguments.\r
++ --help|--print|--no-window-system)\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
++ escape -v OPTARG "${OPTARG}"\r
++\r
++ case "${opt}" in\r
++ --help|h)\r
++ exec man notmuch-emacs-mua\r
++ ;;\r
++ --from)\r
++ escape -v FROM "${OPTARG}"\r
++ ;;\r
++ --subject|s)\r
++ escape -v OPTARG "${OPTARG}"\r
++ SUBJECT=${SUBJECT:+$SUBJECT }${OPTARG}\r
++ message_goto='(message-goto-subject)'\r
++ ;;\r
++ --to)\r
++ escape -v OPTARG "${OPTARG}"\r
++ TO=${TO:+$TO, }${OPTARG}\r
++ message_goto='(message-goto-to)'\r
++ ;;\r
++ --cc|c)\r
++ escape -v OPTARG "${OPTARG}"\r
++ CC=${CC:+$CC, }${OPTARG}\r
++ message_goto='(message-goto-cc)'\r
++ ;;\r
++ --bcc|b)\r
++ escape -v OPTARG "${OPTARG}"\r
++ BCC=${BCC:+$BCC, }${OPTARG}\r
++ message_goto='(message-goto-bcc)'\r
++ ;;\r
++ --body|i)\r
++ escape -v OPTARG "${OPTARG}"\r
++ if [[ ! -f ${OPTARG} ]]; then\r
++ echo "$0: '${OPTARG}': no such file" >&2\r
++ exit 1\r
++ fi\r
++ if [[ $cddone == 'false' ]]; then\r
++ BODY=${BODY}$'\n'" (cd \"${PWD}\")"\r
++ cddone=true\r
++ fi\r
++ BODY=${BODY}$'\n'" (insert-file \"${OPTARG}\")"\r
++ BODY=${BODY}$'\n'" (if (/= (point) (line-beginning-position)) (insert \"\\n\"))"\r
++ unset message_goto\r
++ ;;\r
++ --bodytext)\r
++ escape -v OPTARG "${OPTARG}"\r
++ BODY=${BODY}$'\n'" (insert \"${OPTARG}\\n\")"\r
++ unset message_goto\r
++ ;;\r
++ --no-window-system)\r
++ W=-nw\r
++ ;;\r
++ n) # -nw !!!\r
++ if [[ $OPTARG == 'w' ]]; then\r
++ W=-nw\r
++ else\r
++ echo "$0: unknown option -n${OPTARG}, or argument mismatch." >&2\r
++ exit 1\r
++ fi\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
++ escape -v arg "${arg}"\r
++ TO=${TO:+$TO, }${arg}\r
++ message_goto='(message-goto-to)'\r
++done\r
++\r
++# The newlines are here for --print (only) output.\r
++NL=$'\n'\r
++ELISP="\\r
++${CC:+$NL (message-goto-cc) (insert \"$CC\")}\\r
++${BCC:+$NL (message-goto-bcc) (insert \"$BCC\")}\\r
++${BODY:+$NL (message-goto-body)$BODY}"\r
++\r
++if [[ $TO == '' && $SUBJECT == '' && $ELISP == '' ]]\r
++then\r
++ exec_mua "(require 'notmuch) (notmuch-hello)"\r
++else\r
++ [[ $FROM != '' ]] && OH="(list (cons 'From \"$FROM\"))" || OH=nil\r
++\r
++ if [[ $SUBJECT == '' ]]; then\r
++ SUBJECT=nil\r
++ message_goto='(message-goto-subject)'\r
++ else\r
++ SUBJECT=\"$SUBJECT\"\r
++ fi\r
++ if [[ $TO == '' ]]; then\r
++ TO=nil\r
++ message_goto='(message-goto-to)'\r
++ else\r
++ TO=\"$TO\"\r
++ fi\r
++ exec_mua "(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+ $message_goto}"\r
++fi\r
+-- \r
+2.0.0\r
+\r