--- /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 22A64431FBC\r
+ for <notmuch@notmuchmail.org>; Sun, 6 Apr 2014 08:43:35 -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 ghZITI3M2TF2 for <notmuch@notmuchmail.org>;\r
+ Sun, 6 Apr 2014 08:43:31 -0700 (PDT)\r
+Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com\r
+ [74.125.82.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ 8B0D4431FB6 for <notmuch@notmuchmail.org>; Sun, 6 Apr 2014 08:43:30 -0700\r
+ (PDT)\r
+Received: by mail-wg0-f41.google.com with SMTP id n12so5719162wgh.12\r
+ for <notmuch@notmuchmail.org>; Sun, 06 Apr 2014 08:43:27 -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:cc:subject:date:message-id:in-reply-to\r
+ :references:mime-version:content-type:content-transfer-encoding;\r
+ bh=IwQWOpo9fN83PjMm6/YFzIZXmGz4YIkTyYwk7M+w+0w=;\r
+ b=KbmXkiU5NfLmmcL8R52561MidoPnY9aCYawfoGlaiHYMv2T4BuiP6O/k/T9f8sHiVb\r
+ SIzpvKm7DqhXLCxePKaG49CmqScegu4bMQ8fZz6bkKOJ2+umhp05qNy4IBRlFnCLZGsQ\r
+ 7ewIihefsk5l5dmJNYQLbzxh5YKLXGBmpK8oEVseITFnOO1DZ8QTaQDEhfi2YL3hml6s\r
+ uBsVApQMdKR0YWaMepxm8bA1KF8/cuvBlMAREHAdWbhhA7b0/otFo/zZAspC2gYwDwad\r
+ ao+WYi578/EyyarMwpHlBPSO5ruSEp/6qBKPoKqcbyfRHxeBw8KGGY+fJ1knutamgFB9\r
+ vIzg==\r
+X-Gm-Message-State:\r
+ ALoCoQnuFli7e0NHAT10WeA4XC3aYbNhEbFktWcNmF/8Gu4qF7e/N95HGVJCTnZ3PmB7Dbv1rSdp\r
+X-Received: by 10.180.78.200 with SMTP id d8mr19673019wix.34.1396799006544;\r
+ Sun, 06 Apr 2014 08:43:26 -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 m8sm35281700eeg.11.2014.04.06.08.43.24\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 06 Apr 2014 08:43:25 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org,\r
+ Tomi Ollila <tomi.ollila@iki.fi>\r
+Subject: [PATCH v2] cli: add a tool for starting new message in the emacs ui\r
+Date: Sun, 6 Apr 2014 18:43:23 +0300\r
+Message-Id: <1396799003-14855-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 1.9.1\r
+In-Reply-To: <m2bnx1duv7.fsf@guru.guru-group.fi>\r
+References: <m2bnx1duv7.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\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, 06 Apr 2014 15:43:35 -0000\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
+ doc/man1/notmuch-emacs-mua.rst | 50 +++++++++++++++++\r
+ notmuch-emacs-mua | 122 +++++++++++++++++++++++++++++++++++++++++\r
+ 2 files changed, 172 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.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
++=================\r
++notmuch-emacs-mua\r
++=================\r
++\r
++SYNOPSIS\r
++========\r
++\r
++**notmuch-emacs-mua** [options ...] [<to-address> ...]\r
++\r
++DESCRIPTION\r
++===========\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=``\ <subject>\r
++ Specify the subject of the message.\r
++\r
++ ``--to=``\ <to-address>\r
++ Specify a recipient (To).\r
++\r
++ ``-c, --cc=``\ <cc-address>\r
++ Specify a carbon-copy (Cc) recipient.\r
++\r
++ ``-b, --bcc=``\ <bcc-address>\r
++ Specify a blind-carbon-copy (Bcc) recipient.\r
++\r
++ ``-i, --body=``\ <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
++========\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 000000000000..7f94271d8a44\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 © 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=\r
++\r
++# The crux of it all: construct an elisp progn and eval it.\r
++ELISP="(progn (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=$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=*)\r
++ OPTARG=${opt#--*=}\r
++ opt=${opt%%=*}\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=$((OPTIND + 1))\r
++ ;;\r
++ esac\r
++\r
++ OPTARG="$(escape "${OPTARG}")"\r
++\r
++ case "${opt}" in\r
++ --help|h)\r
++ exec man notmuch-emacs-mua\r
++ ;;\r
++ --subject|s)\r
++ ELISP="${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"\r
++ ;;\r
++ --to)\r
++ ELISP="${ELISP} (message-goto-to) (insert \"${OPTARG}, \")"\r
++ ;;\r
++ --cc|c)\r
++ ELISP="${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")"\r
++ ;;\r
++ --bcc|b)\r
++ ELISP="${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")"\r
++ ;;\r
++ --body|i)\r
++ ELISP="${ELISP} (message-goto-body) (cd \"${PWD}\") (insert-file \"${OPTARG}\")"\r
++ ;;\r
++ --print)\r
++ PRINT_ONLY=1\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="$(escape "${arg}")"\r
++ ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")"\r
++done\r
++\r
++# End progn.\r
++ELISP="${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
++if [ $? -ne 0 ]; then\r
++ echo "$0: emacsclient failed" >&2\r
++ exit 1\r
++fi\r
+-- \r
+1.9.1\r
+\r