--- /dev/null
+Return-Path: <jani@nikula.org>\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 1628C431FAF\r
+ for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 14:54:30 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 b546+2belAIF for <notmuch@notmuchmail.org>;\r
+ Wed, 19 Mar 2014 14:54:21 -0700 (PDT)\r
+Received: from mail-la0-f53.google.com (mail-la0-f53.google.com\r
+ [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 65BD4431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 14:54:21 -0700 (PDT)\r
+Received: by mail-la0-f53.google.com with SMTP id b8so6288937lan.26\r
+ for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 14:54:19 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type\r
+ :content-transfer-encoding;\r
+ bh=5f1TvgYuiL9m3PlxRQ7+DlgiPangqPmJN7lxenFFImM=;\r
+ b=R4YU8esDyw0x/Ab1+zLSKdO9+c7ZHUODWgA0kzDW8llx1ZG8JUQ6FkMR+gvTrtbtUY\r
+ 3DhDYmejcp2lzxwAY+iD4GHaOxwI9/i24WfrV1ctADpc3VIj6+OdylV7mQrQctXeQBKS\r
+ is+LftTb6IlqKimGTMjDMuafUej7VknwuAdGG2yn2A05Pbl6XKlaFQqmxldRjY82ZwGb\r
+ sExQlItANE0NFnGXXzjA/hTWF3lc09t77rQtDVIEjDBcxPw6eh39B1GmV2P3NcbEuHMy\r
+ oNDPtm2Yyrs+NLFAGTgkgQgdAKTLEmd+wbo9GLOdp1pqEva9flutiXQv25brn7fK3DBA\r
+ uaGw==\r
+X-Gm-Message-State:\r
+ ALoCoQm4HWKiVXGMk0uOeHHEqHDxAportEC0yCUYnxLq/ucBcMHkSHrv1cu6ZawNF4+LTcpW+w+/\r
+X-Received: by 10.112.137.5 with SMTP id qe5mr26138470lbb.16.1395266058612;\r
+ Wed, 19 Mar 2014 14:54:18 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+ [88.195.111.91])\r
+ by mx.google.com with ESMTPSA id rd5sm17906775lbb.0.2014.03.19.14.54.16\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Wed, 19 Mar 2014 14:54:17 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] cli: add a tool for starting new message in the emacs ui\r
+In-Reply-To: <m2eh1x6fwt.fsf@guru.guru-group.fi>\r
+References: <1395257153-29764-1-git-send-email-jani@nikula.org>\r
+ <m2eh1x6fwt.fsf@guru.guru-group.fi>\r
+User-Agent: Notmuch/0.17+142~g30045abd801f (http://notmuchmail.org)\r
+ Emacs/24.3.1 (x86_64-pc-linux-gnu)\r
+Date: Wed, 19 Mar 2014 23:54:15 +0200\r
+Message-ID: <877g7pn9bs.fsf@nikula.org>\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: Wed, 19 Mar 2014 21:54:30 -0000\r
+\r
+On Wed, 19 Mar 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+> On Wed, Mar 19 2014, Jani Nikula <jani@nikula.org> wrote:\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
+>>\r
+>> I need something like this to script some mails, particularly with the\r
+>> mutt compatible options, but I also think notmuch must have long\r
+>> options. I then got a little carried away with figuring out how to\r
+>> support both. I think it turned out pretty neat, except due to some\r
+>> subtlety it only works with bash.\r
+>>\r
+>> I didn't integrate this in the man build or install or anything,\r
+>> because I wanted to get feedback first on whether we want to have this\r
+>> at all. Or if it should live in contrib or something.\r
+>>\r
+>> BR,\r
+>> Jani.\r
+>> ---\r
+>\r
+> Quick glance to the code and some thoughts.\r
+\r
+Thanks!\r
+\r
+>\r
+>> doc/man1/notmuch-emacs-mua.rst | 50 ++++++++++++++++++\r
+>> notmuch-emacs-mua | 113 ++++++++++++++++++++++++++++++++++=\r
++++++++\r
+>> 2 files changed, 163 insertions(+)\r
+>> create mode 100644 doc/man1/notmuch-emacs-mua.rst\r
+>> create mode 100755 notmuch-emacs-mua\r
+>>\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 000000000000..6e63818492fb\r
+>> --- /dev/null\r
+>> +++ b/doc/man1/notmuch-emacs-mua.rst\r
+>> @@ -0,0 +1,50 @@\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
+>> + ``--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
+>\r
+> It would be convenient to the user to have the manual embedded in\r
+> the script in case no args are given or so (or that is convenient\r
+> to me ;) and no namual page at all...\r
+\r
+If this is to become part of notmuch, I think a separate man page is in\r
+order. Otherwise, agreed (and even had that in an earlier version).\r
+\r
+>\r
+>> diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
+>> new file mode 100755\r
+>> index 000000000000..a482fe1a8eca\r
+>> --- /dev/null\r
+>> +++ b/notmuch-emacs-mua\r
+>> @@ -0,0 +1,113 @@\r
+>> +#!/bin/bash\r
+>\r
+> #!/usr/bin/env bash\r
+\r
+Agreed.\r
+\r
+>\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 -e\r
+>\r
+> set -eu would be nice IMO...\r
+>\r
+> ... then initialize all vars to empty strings, like PRINT_ONLY=3D\r
+> ... and in cases not possible syntax ${1-} can be used.\r
+\r
+Agreed.\r
+\r
+>\r
+>> +\r
+>> +# The crux of it all: construct an elisp progn and eval it.\r
+>> +ELISP=3D"(progn (notmuch-mua-new-mail)"\r
+>\r
+> ELISP=3D"(progn (require 'notmuch) (notmuch-mua-new-mail)"\r
+\r
+Right.\r
+\r
+>\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)\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
+>> + case "${opt}" in\r
+>> + --help|h)\r
+>> + exec man notmuch-search\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
+>> + *)\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
+>> +while [ $# -gt 0 ]; do\r
+>> + ELISP=3D"${ELISP} (message-goto-to) (insert \"${1}, \")"\r
+>> + shift\r
+>> +done\r
+>\r
+> for arg; do\r
+\r
+for arg in $@; ?\r
+\r
+> ELISP=3D"${ELISP} (message-goto-to) (insert \"${arg}, \")"\r
+> done\r
+>\r
+> I tried to address Austin's comment on IRC with=20\r
+> printf -v qarg %q "$arg" -- that has problem if there is whitespace\r
+> in arg. maybe printf -v qarg '%q ' "$arg" -- then there is always one\r
+> trailing ws (and spaces are always prefixed w/ \ -- (insert "foo\ bar")\r
+> just makes the ' ' disappear (which is not good...).\r
+>\r
+> maybe arg=3D${arg//\\/\\\\}; arg=3D${arg//"/\\"};=20\r
+>\r
+> ${parameter/pattern/string} -- Pattern substition in bash manual.\r
+\r
+I'm inclined to go with "don't do that then" ;)\r
+\r
+>\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
+>> +emacsclient --eval "${ELISP}" &>/dev/null\r
+>\r
+> emacsclient --eval "${ELISP}" >/dev/null 2>&1\r
+>\r
+> (why do you want to redirect stdout & stderr to devnull ?)\r
+\r
+Okay, maybe it could be just stdout (which will be the eval result, in\r
+this case nil).\r
+\r
+>\r
+>> +if [ $? -ne 0 ]; then\r
+>> + echo "$0: emacsclient failed" >&2\r
+>> + exit 1\r
+>> +fi\r
+>> --=20\r
+>> 1.9.0\r