--- /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 C72B3431FBC\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 06:12:29 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.738\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.738 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7]\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 t01Kiu5cE2LQ for <notmuch@notmuchmail.org>;\r
+ Sat, 7 Mar 2015 06:12:26 -0800 (PST)\r
+Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com\r
+ [209.85.212.182]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id F2EE8431FAE\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 06:12:25 -0800 (PST)\r
+Received: by wibbs8 with SMTP id bs8so9778792wib.4\r
+ for <notmuch@notmuchmail.org>; Sat, 07 Mar 2015 06:12:24 -0800 (PST)\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:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=j+4em1Oc67LC6dexZRDuRa1iUu3w02KiwUKB6BeWscY=;\r
+ b=dzRNLvAxB4lRH5weZAr7zeOTHjE7hdC4FgeU/iG0L3XwrkGeTVxwWDRX+8QnYcoAUg\r
+ SRt0CtKp/krulIUTfHAExCaE8pcM6Eu62MOJYIQX6gEvDjMZbIk9Tz1vTKT40c0d9lGa\r
+ bvAcEzm7jat+AfuPVWXu+LRoR3OPYH/iJwm4WNt7qrgd0h+V/vdYDWH5I77ITVNcCHII\r
+ ZnUSIniI9MpkUP9Wjkpu55Amad9C7PQtwbjdDAcQGvep/V8rH0/m5HvnFvdNxvTQWml+\r
+ MyNL4hl9/drrbkZJAY4jR7EkLyicni1v2ALRScS0rgH1j7+YEgg2RdD/UjdmSp01jxXT\r
+ JybQ==\r
+X-Gm-Message-State:\r
+ ALoCoQlHLLGFFvf7YVm6VlHRUJ+ibBJecsvOO1hyc6izqXvwLgaCAP5Eigd7kk/VY8KeYfrbWThN\r
+X-Received: by 10.194.78.231 with SMTP id e7mr39089690wjx.33.1425737544834;\r
+ Sat, 07 Mar 2015 06:12:24 -0800 (PST)\r
+Received: from localhost (mobile-internet-bcee3b-76.dhcp.inet.fi.\r
+ [188.238.59.76])\r
+ by mx.google.com with ESMTPSA id nb18sm6844502wic.3.2015.03.07.06.12.23\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 07 Mar 2015 06:12:24 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] notmuch-emacs-mua: more options, some fixes\r
+In-Reply-To: <1425724605-392-1-git-send-email-tomi.ollila@iki.fi>\r
+References: <1425724605-392-1-git-send-email-tomi.ollila@iki.fi>\r
+User-Agent: Notmuch/0.19+74~g6aeef2e (http://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sat, 07 Mar 2015 16:12:43 +0200\r
+Message-ID: <87pp8kj3qc.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Sat, 07 Mar 2015 14:12:29 -0000\r
+\r
+On Sat, 07 Mar 2015, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+> Two new options added:\r
+> --from: specify alternate From: header\r
+> --bodytext: possibility to give body content from command line\r
+>\r
+> Non-forking escape() functionality, also escaping \ (backslash) characters.\r
+>\r
+> Without content arguments start emacs/emacsclient and run (notmuch-hello),\r
+> in this case without assigning anything to message-exit-actions.\r
+>\r
+> Point is now positioned at the end of the content given last on command\r
+> line, unless to: or subject: is missing -- in which case point is\r
+> positioned at one of these headers (is both missing, at to:)\r
+>\r
+> The -nw option is now given to emacs in case --no-window-system command\r
+> line option is provided (--no-window-system used to work with emacsclient\r
+> only).\r
+>\r
+> In case EMACS or EMACSCLIENT environment variable was defined but being\r
+> empty (null string), use emacs/emacsclient as command instead (null string\r
+> as executable name gives confusing error message). Also $EMACS/$EMACSCLIENT\r
+> executable name is now quoted to *NOT* split it to separate command line\r
+> arguments on any $IFS variables there might be.\r
+>\r
+> Reorganized content argument handling to combine the content of same option\r
+> given multiple times and make it look more readable when --print option is\r
+> used. --body option also now checks the existence of the file to be\r
+> included and if the file included does not end with newline trailing\r
+> newline is inserted to the message buffer.\r
+>\r
+> As bash supports [[ ]] command and it's special expansion (or lack thereof)\r
+> of variables (and ==, && and || inside) the few [ ]'s there were are now\r
+> changed to this more advanced format.\r
+\r
+As I mentioned on IRC, I think there are too many changes here for one\r
+patch. One change at a time! In particular because I'm not sure if all\r
+of this is really needed... like message_goto and point placement\r
+handling. Starts to feel like all of this would be better handled with a\r
+dedicated function in emacs!\r
+\r
+BR,\r
+Jani.\r
+\r
+> ---\r
+>\r
+> The changes *NOT* taken from my 2 draft patches (*)\r
+>\r
+> 1) no -nw hacking\r
+>\r
+> 2) no mailto: handling\r
+>\r
+> (*) id:1421776424-24304-1-git-send-email-tomi.ollila@iki.fi (later, linking\r
+> previous)\r
+>\r
+>\r
+> doc/man1/notmuch-emacs-mua.rst | 8 ++-\r
+> notmuch-emacs-mua | 123 ++++++++++++++++++++++++++++++-----------\r
+> 2 files changed, 99 insertions(+), 32 deletions(-)\r
+>\r
+> diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.rst\r
+> index eb47098..29f7e0c 100644\r
+> --- a/doc/man1/notmuch-emacs-mua.rst\r
+> +++ b/doc/man1/notmuch-emacs-mua.rst\r
+> @@ -22,6 +22,9 @@ Supported options for **notmuch-emacs-mua** include\r
+> Use emacsclient, rather than emacs. This will start\r
+> an emacs daemon process if necessary.\r
+> \r
+> + ``--from=``\ <from>\r
+> + Specify alternate sender (From) of the message.\r
+> +\r
+> ``-s, --subject=``\ <subject>\r
+> Specify the subject of the message.\r
+> \r
+> @@ -37,6 +40,9 @@ Supported options for **notmuch-emacs-mua** include\r
+> ``-i, --body=``\ <file>\r
+> Specify a file to include into the body of the message.\r
+> \r
+> + ``--bodytext=``\ <text>\r
+> + Specify text content to be inserted 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
+> @@ -60,4 +66,4 @@ Name of emacsclient comment to invoke\r
+> SEE ALSO\r
+> ========\r
+> \r
+> -**notmuch(1)**, **emacsclient(1)**, **mutt(1)**\r
+> +**notmuch(1)**, **emacs(1)**, **emacsclient(1)**, **mutt(1)**\r
+> diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
+> index b8cbc82..17365b9 100755\r
+> --- a/notmuch-emacs-mua\r
+> +++ b/notmuch-emacs-mua\r
+> @@ -1,4 +1,5 @@\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
+> @@ -18,25 +19,47 @@\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
+> +# escape: "expand" '\' to '\\' & '"' to '\"'\r
+> +# Calling convention: escape -v var "$arg" (like in bash printf).\r
+> escape ()\r
+> {\r
+> - echo "${1//\"/\\\"}"\r
+> + local arg=${3//\\/\\\\}\r
+> + eval $2='${arg//\"/\\\"}'\r
+> }\r
+> \r
+> -EMACS=${EMACS-emacs}\r
+> -EMACSCLIENT=${EMACSCLIENT-emacsclient}\r
+> +EMACS=${EMACS:-emacs}\r
+> +EMACSCLIENT=${EMACSCLIENT:-emacsclient}\r
+> \r
+> PRINT_ONLY=\r
+> USE_EMACSCLIENT=\r
+> -CLIENT_TYPE="-c"\r
+> +EMACSCLIENT_TYPE='-c'\r
+> +EMACS_NW=\r
+> \r
+> -# The crux of it all: construct an elisp progn and eval it.\r
+> -ELISP="(prog1 'done (require 'notmuch) (notmuch-mua-new-mail)"\r
+> -ELISP="${ELISP} (setq message-exit-actions (list #'save-buffers-kill-terminal))"\r
+> +exec_mua ()\r
+> +{\r
+> + if [[ -n $PRINT_ONLY ]]; then\r
+> + echo "$1"\r
+> + exit\r
+> + fi\r
+> +\r
+> + if [[ -n $USE_EMACSCLIENT ]]; then\r
+> + # Evaluate the progn.\r
+> + exec "${EMACSCLIENT}" ${EMACSCLIENT_TYPE} -a '' --eval "$1"\r
+> + else\r
+> + exec "${EMACS}" ${EMACS_NW} --eval "$1"\r
+> + fi\r
+> + exit not reached\r
+> +}\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
+> while getopts :s:c:b:i:hC opt; do\r
+> # Handle errors and long options.\r
+> @@ -47,14 +70,14 @@ while getopts :s:c:b:i:hC opt; do\r
+> ;;\r
+> \?)\r
+> opt=$1\r
+> - if [ "${OPTARG}" != "-" ]; then\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
+> + --subject=*|--to=*|--cc=*|--bcc=*|--body=*|--from=*|--bodytext=*)\r
+> OPTARG=${opt#--*=}\r
+> opt=${opt%%=*}\r
+> ;;\r
+> @@ -71,9 +94,7 @@ while getopts :s:c:b:i:hC opt; do\r
+> ;;\r
+> esac\r
+> \r
+> -\r
+> - OPTARG="${OPTARG-none}"\r
+> - OPTARG="$(escape "${OPTARG}")"\r
+> + escape -v OPTARG "${OPTARG-}"\r
+> \r
+> case "${opt}" in\r
+> --help|h)\r
+> @@ -82,26 +103,48 @@ while getopts :s:c:b:i:hC opt; do\r
+> --client|C)\r
+> USE_EMACSCLIENT="yes"\r
+> ;;\r
+> + --from)\r
+> + FROM=${OPTARG}\r
+> + ;;\r
+> --subject|s)\r
+> - ELISP="${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"\r
+> + SUBJECT=${SUBJECT:+$SUBJECT }${OPTARG}\r
+> + message_goto='(message-goto-subject)'\r
+> ;;\r
+> --to)\r
+> - ELISP="${ELISP} (message-goto-to) (insert \"${OPTARG}, \")"\r
+> + TO=${TO:+$TO, }${OPTARG}\r
+> + message_goto='(message-goto-to)'\r
+> ;;\r
+> --cc|c)\r
+> - ELISP="${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")"\r
+> + CC=${CC:+$CC, }${OPTARG}\r
+> + message_goto='(message-goto-cc)'\r
+> ;;\r
+> --bcc|b)\r
+> - ELISP="${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")"\r
+> + BCC=${BCC:+$BCC, }${OPTARG}\r
+> + message_goto='(message-goto-bcc)'\r
+> ;;\r
+> --body|i)\r
+> - ELISP="${ELISP} (message-goto-body) (cd \"${PWD}\") (insert-file \"${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
+> + BODY=${BODY}$'\n'" (insert \"${OPTARG}\\n\")"\r
+> + unset message_goto\r
+> ;;\r
+> --print)\r
+> PRINT_ONLY=1\r
+> ;;\r
+> --no-window-system)\r
+> - CLIENT_TYPE="-t"\r
+> + EMACSCLIENT_TYPE='-t'\r
+> + EMACS_NW='-nw'\r
+> ;;\r
+> *)\r
+> # We should never end up here.\r
+> @@ -116,21 +159,39 @@ done\r
+> \r
+> # Positional parameters.\r
+> for arg; do\r
+> - arg="$(escape "${arg}")"\r
+> - ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")"\r
+> + escape -v _arg "${arg}"\r
+> + TO=${TO:+$TO, }${_arg}\r
+> + message_goto='(message-goto-to)'\r
+> done\r
+> \r
+> -# End progn.\r
+> -ELISP="${ELISP})"\r
+> +# The newlines are here for better user experience when --print option is used.\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 [ -n "$PRINT_ONLY" ]; then\r
+> - echo ${ELISP}\r
+> - exit 0\r
+> -fi\r
+> -\r
+> -if [ -n "$USE_EMACSCLIENT" ]; then\r
+> - # Evaluate the progn.\r
+> - exec ${EMACSCLIENT} ${CLIENT_TYPE} -a '' --eval "${ELISP}"\r
+> +if [[ $TO == '' && $SUBJECT == '' && $ELISP == '' ]]\r
+> +then\r
+> + exec_mua "(prog1 'done (require 'notmuch) (notmuch-hello))"\r
+> else\r
+> - exec ${EMACS} --eval "${ELISP}"\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 "(prog1 'done (require 'notmuch)\r
+> + (setq message-exit-actions (list #'save-buffers-kill-terminal))\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.1.0\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r