--- /dev/null
+Return-Path: <tomi.ollila@iki.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 AD934431FAF\r
+ for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 13:07:40 -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 odb7M8y4-6VO for <notmuch@notmuchmail.org>;\r
+ Sun, 18 Jan 2015 13:07:37 -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 C17B0431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 13:07:36 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id D71771000E0;\r
+ Sun, 18 Jan 2015 23:07:04 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] cli: add a tool for starting new message in the emacs ui\r
+In-Reply-To: <1421598115-4889-1-git-send-email-david@tethera.net>\r
+References: <1404244957-3671-1-git-send-email-david@tethera.net>\r
+ <1421598115-4889-1-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.19+29~g7367d27 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Sun, 18 Jan 2015 23:07:04 +0200\r
+Message-ID: <m2h9vnssqv.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\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: Sun, 18 Jan 2015 21:07:40 -0000\r
+\r
+On Sun, Jan 18 2015, David Bremner <david@tethera.net> wrote:\r
+\r
+> From: Jani Nikula <jani@nikula.org>\r
+>\r
+> Add a tool to start composing an email in the Notmuch Emacs UI with\r
+> the specified subject, recipients, and message body.\r
+> ---\r
+>\r
+> This version fixes my complaint about the previous version not\r
+> starting emacs. It does this by starting a new "frame", either at the\r
+> window system level, or in the current terminal. The traditional\r
+> "-nw" short form of the argument "--no-window-system" seems maybe more\r
+> work to parse than it's worth.\r
+\r
+Well, id:1405026779-29966-1-git-send-email-tomi.ollila@iki.fi (*) had -nw\r
+parsing, but I can live without...\r
+\r
+But more than that one important feature has to be agreed before initial\r
+interface is locked down -- how to provide body content from command line\r
+without resorting to temporary files. In (*) --body was adding those lines\r
+instead of reading file and I later suggested that --include or --insert\r
+could do the same as -i ... but I am open to any solution that gives me\r
+opportunity to provide body *content* from command line.\r
+\r
+Tomi\r
+\r
+>\r
+> doc/conf.py | 4 ++\r
+> doc/man1/notmuch-emacs-mua.rst | 53 ++++++++++++++++++\r
+> notmuch-emacs-mua | 122 +++++++++++++++++++++++++++++++++++=\r
+++++++\r
+> 3 files changed, 179 insertions(+)\r
+> create mode 100644 doc/man1/notmuch-emacs-mua.rst\r
+> create mode 100755 notmuch-emacs-mua\r
+>\r
+> diff --git a/doc/conf.py b/doc/conf.py\r
+> index fb49f6e..8fbc854 100644\r
+> --- a/doc/conf.py\r
+> +++ b/doc/conf.py\r
+> @@ -78,6 +78,10 @@ man_pages =3D [\r
+> u'creates a plain-text dump of the tags of each message',\r
+> [u'Carl Worth and many others'], 1),\r
+>=20=20\r
+> +('man1/notmuch-emacs-mua','notmuch-emacs-mua',\r
+> + u'send mail with notmuch and emacs',\r
+> + [u'Carl Worth and many others'], 1),\r
+> +\r
+> ('man5/notmuch-hooks','notmuch-hooks',\r
+> u'hooks for notmuch',\r
+> [u'Carl Worth and many others'], 5),\r
+> diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.=\r
+rst\r
+> new file mode 100644\r
+> index 0000000..bf8c3aa\r
+> --- /dev/null\r
+> +++ b/doc/man1/notmuch-emacs-mua.rst\r
+> @@ -0,0 +1,53 @@\r
+> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
+> +notmuch-emacs-mua\r
+> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
+> +\r
+> +SYNOPSIS\r
+> +=3D=3D=3D=3D=3D=3D=3D=3D\r
+> +\r
+> +**notmuch-emacs-mua** [options ...] [<to-address> ...]\r
+> +\r
+> +DESCRIPTION\r
+> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
+> +\r
+> +Start composing an email in the Notmuch Emacs UI with the specified\r
+> +subject, recipients, and message body.\r
+> +\r
+> +For **notmuch-emacs-mua** to work, you need **emacsclient** and an\r
+> +already running Emacs with a server.\r
+> +\r
+> +Supported options for **notmuch-emacs-mua** include\r
+> +\r
+> + ``-h, --help``\r
+> + Display help.\r
+> +\r
+> + ``-s, --subject=3D``\ <subject>\r
+> + Specify the subject of the message.\r
+> +\r
+> + ``--to=3D``\ <to-address>\r
+> + Specify a recipient (To).\r
+> +\r
+> + ``-c, --cc=3D``\ <cc-address>\r
+> + Specify a carbon-copy (Cc) recipient.\r
+> +\r
+> + ``-b, --bcc=3D``\ <bcc-address>\r
+> + Specify a blind-carbon-copy (Bcc) recipient.\r
+> +\r
+> + ``-i, --body=3D``\ <file>\r
+> + Specify a file to include into the body of the message.\r
+> +\r
+> + ``--no-window-system``\r
+> + Even if a window system is available, use the current terminal\r
+> +\r
+> + ``--print``\r
+> + Output the resulting elisp to stdout instead of evaluating it.\r
+> +\r
+> +The supported positional parameters and short options are a compatible\r
+> +subset of the **mutt** MUA command-line options.\r
+> +\r
+> +Options may be specified multiple times.\r
+> +\r
+> +SEE ALSO\r
+> +=3D=3D=3D=3D=3D=3D=3D=3D\r
+> +\r
+> +**notmuch(1)**, **emacsclient(1)**, **mutt(1)**\r
+> diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
+> new file mode 100755\r
+> index 0000000..fdf4024\r
+> --- /dev/null\r
+> +++ b/notmuch-emacs-mua\r
+> @@ -0,0 +1,122 @@\r
+> +#!/usr/bin/env bash\r
+> +#\r
+> +# notmuch-emacs-mua - start composing a mail on the command line\r
+> +#\r
+> +# Copyright =C2=A9 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
+> +#\r
+> +\r
+> +set -eu\r
+> +\r
+> +escape ()\r
+> +{\r
+> + echo "${1//\"/\\\"}"\r
+> +}\r
+> +\r
+> +PRINT_ONLY=3D\r
+> +CLIENT_TYPE=3D"-c"\r
+> +\r
+> +# The crux of it all: construct an elisp progn and eval it.\r
+> +ELISP=3D"(prog1 'done (require 'notmuch) (notmuch-mua-new-mail)"\r
+> +\r
+> +while getopts :s:c:b:i: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=3D$1\r
+> + if [ "${OPTARG}" !=3D "-" ]; 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=3D*|--to=3D*|--cc=3D*|--bcc=3D*|--body=3D*)\r
+> + OPTARG=3D${opt#--*=3D}\r
+> + opt=3D${opt%%=3D*}\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=3D$((OPTIND + 1))\r
+> + ;;\r
+> + esac\r
+> +\r
+> + OPTARG=3D"$(escape "${OPTARG}")"\r
+> +\r
+> + case "${opt}" in\r
+> + --help|h)\r
+> + exec man notmuch-emacs-mua\r
+> + ;;\r
+> + --subject|s)\r
+> + ELISP=3D"${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"\r
+> + ;;\r
+> + --to)\r
+> + ELISP=3D"${ELISP} (message-goto-to) (insert \"${OPTARG}, \")"\r
+> + ;;\r
+> + --cc|c)\r
+> + ELISP=3D"${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")"\r
+> + ;;\r
+> + --bcc|b)\r
+> + ELISP=3D"${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")"\r
+> + ;;\r
+> + --body|i)\r
+> + ELISP=3D"${ELISP} (message-goto-body) (cd \"${PWD}\") (insert-file =\r
+\"${OPTARG}\")"\r
+> + ;;\r
+> + --print)\r
+> + PRINT_ONLY=3D1\r
+> + ;;\r
+> + --no-window-system)\r
+> + CLIENT_TYPE=3D"-t"\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=3D1\r
+> +done\r
+> +\r
+> +# Positional parameters.\r
+> +for arg; do\r
+> + arg=3D"$(escape "${arg}")"\r
+> + ELISP=3D"${ELISP} (message-goto-to) (insert \"${arg}, \")"\r
+> +done\r
+> +\r
+> +# End progn.\r
+> +ELISP=3D"${ELISP})"\r
+> +\r
+> +if [ -n "$PRINT_ONLY" ]; then\r
+> + echo ${ELISP}\r
+> + exit 0\r
+> +fi\r
+> +\r
+> +# Evaluate the progn.\r
+> +exec emacsclient ${CLIENT_TYPE} -a '' --eval "${ELISP}"\r
+> --=20\r
+> 2.1.4\r