--- /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 BCF75431FD0\r
+ for <notmuch@notmuchmail.org>; Sat, 1 Nov 2014 01:52:20 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\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 eRUxqBiQPMvb for <notmuch@notmuchmail.org>;\r
+ Sat, 1 Nov 2014 01:52:12 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 7B978431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 1 Nov 2014 01:52:12 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 547961000E0;\r
+ Sat, 1 Nov 2014 10:51:51 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org, david@tethera.net,\r
+ jrollins@finestructure.net\r
+Subject: Re: [DRAFT PATCH] modified notmuch-emacs-mua\r
+In-Reply-To: <871tpq1vn4.fsf@nikula.org>\r
+References: <1405026779-29966-1-git-send-email-tomi.ollila@iki.fi>\r
+ <871tpq1vn4.fsf@nikula.org>\r
+User-Agent: Notmuch/0.18.1+130~ga61922f (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: Sat, 01 Nov 2014 10:51:51 +0200\r
+Message-ID: <m2sii3fgm0.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: Sat, 01 Nov 2014 08:52:20 -0000\r
+\r
+On Wed, Oct 29 2014, Jani Nikula <jani@nikula.org> wrote:\r
+\r
+Thanks for quick response.=20\r
+\r
+There are only one (and half) thing that needs to be resolved before\r
+first inclusion, the desire for more versatile options can be discussed\r
+later...\r
+\r
+> On Fri, 11 Jul 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+>> Highlights:\r
+>>\r
+>> * notmuch-emacs-mua without arguments runs (notmuch-hello)\r
+>>\r
+>> * runs emacs(1) in case emacsclient(1) fails to connect to running emacs\r
+>>\r
+>> * takes -nw option\r
+>>\r
+>> * handles mailto:\r
+>>\r
+>> * --from option when sending non-mailto: way\r
+>>\r
+>> * -i includes file --body[=3D ]string inserts string\r
+>> ---\r
+>> notmuch-emacs-mua | 200 +++++++++++++++++++++++++++++++++++++++++++++++=\r
++++++++\r
+>> 1 file changed, 200 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 0000000..b1696f7\r
+>> --- /dev/null\r
+>> +++ b/notmuch-emacs-mua\r
+>> @@ -0,0 +1,200 @@\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 =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
+>> +# Tomi Ollila <tomi.ollila@iki.fi>\r
+>> +#\r
+>> +\r
+>> +set -eu\r
+>> +\r
+>> +# "expand" '\' to '\\' & '"' to '\"'\r
+>> +escape_optarg ()\r
+>> +{\r
+>> + OPTARG=3D${OPTARG//\\/\\\\}; OPTARG=3D${OPTARG//\"/\\\"}\r
+>> +}\r
+>> +\r
+>> +# ditto, in case there is '\n' sequence in the source, otherwise\r
+>> +# "expand" only trailing '\'s to '\\'s\r
+>> +escape_body_optarg ()\r
+>> +{\r
+>> + case ${OPTARG} in\r
+>> + *'\"'*) OPTARG=3D${OPTARG//\\/\\\\} ;;\r
+>> + *'\') OPTARG=3D$( printf %s "${OPTARG}" | sed 's/\(\\*\)$/\1\1/' )\r
+>> + esac\r
+>> + OPTARG=3D${OPTARG//\"/\\\"}\r
+>> +}\r
+>> +\r
+>> +unset ALTERNATE_EDITOR\r
+>> +exec_mua ()\r
+>> +{\r
+>> + if "${EMACSCLIENT:=3Demacsclient}" --eval t >/dev/null 2>&1\r
+>> + then\r
+>> + emacs=3D$EMACSCLIENT\r
+>> + # close stdout in case no -nw (and no --print)\r
+>> + test -n "$W$X" || exec >/dev/null\r
+>> + else\r
+>> + emacs=3D${EMACS:-emacs}\r
+>> + fi\r
+>> + ${X:-exec} "$emacs" $W --eval "$*"\r
+>> + exit\r
+>> + ${X:-exec "$emacs" $W --eval} "$*"\r
+>> +}\r
+>> +\r
+>> +X=3D\r
+>> +W=3D\r
+>> +\r
+>> +SUBJECT=3D TO=3D CC=3D BCC=3D BODY=3D FROM=3D IB=3D\r
+>> +\r
+>> +while\r
+>> + # first, handle "long" options which cannot be handled by getopts\r
+>> + case ${1-} in\r
+>> + -nw)\r
+>> + W=3D-nw\r
+>> + shift\r
+>> + continue\r
+>> + ;;\r
+>\r
+> How about generalizing this into letting the user pass arguments after a\r
+> "--" separator to emacs(client)? Would that work?\r
+\r
+That would technically work and be very easy to do. I don't know whether\r
+this is good option -- and such can be added later if decided.\r
+\r
+> Alternatively, why support -nw which is neither part of the mutt\r
+> interface I was originally aiming at emulating nor conforms to notmuch\r
+> style? Just go with --nw or the more verbose --no-window-system (which\r
+> is also compatible with emacs).\r
+\r
+The original mutt interface is there -- as this is notmuch-*emacs*-mua\r
+this could also have the original emacs -nw option (--nw came later, and\r
+is supported by the loop).\r
+\r
+But, what is the option is not important, as long as there is at least one\r
+emacs-compatible option to have this feature (--nw). (for now, Let's see\r
+whether I get irritated that notmuch-emacs-mua -nw does not work -- as I\r
+still have ESC g bound to goto-line as I cannot get used to ESC g g ;)\r
+\r
+>> + mailto:*)\r
+>> + oIFS=3D$IFS; IFS=3D; OPTARG=3D"$*" IFS=3D$oIFS\r
+>> + escape_optarg\r
+>> + exec_mua "(progn (require 'notmuch) (browse-url-mail \"$OPTARG\"))"\r
+>> + exit\r
+>> + esac\r
+>\r
+> Why does mailto: need to be handled here? I think you could either make\r
+> the usage have a special mailto: case where you only have mailto: at $1,\r
+> or you handle mailto: as a positional parameter at the end.\r
+\r
+To handle this here is probably a slip as i started using notmuch-emacs-mua\r
+as a drop-in replacement from notmuch-emacs-mailto (where I added\r
+possibility to do -nw).\r
+\r
+I agree that it is better to just check first arg for mailto: prefix\r
+and if matches, work accordingly.=20\r
+\r
+> With these, you could drop this one extra case here, and go back to the\r
+> more natural "while getopts" argument parsing loop.\r
+\r
+I agree to convert to "while getopts" loop which *apparently* feels more\r
+natural to most of the developers ;D\r
+\r
+>> +\r
+>> + getopts :s:c:b:i:h opt\r
+>> +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*|--from=3D*)\r
+>> + OPTARG=3D${opt#--*=3D}\r
+>> + opt=3D${opt%%=3D*}\r
+>> + ;;\r
+>> + # Long options with argument in next arg.\r
+>> + --subject |--to |--cc |--bcc |--body |--from )\r
+>\r
+> This may be git-ish, but I don't think we should support this in\r
+> notmuch.\r
+\r
+This is also emacs-ish, tar-ish, whatnot-ish (with notable exception of\r
+google-chrome).=20\r
+\r
+But we can go with only supporting --longarg=3Dval option now, and bikeshed\r
+that more if anyone wants to -- From some reason when command starts with\r
+'notmuch' I tend to write =3D to separate long option with arg (and have\r
+always done so with this script when not testing), although SPC is easier\r
+to press that shift-0 (which produces '=3D' on finnish keyboard ;)\r
+\r
+>> + if [[ $# < 2 ]]; then\r
+>> + echo "$0: option '${opt}' requires an argument." >&2\r
+>> + exit 1\r
+>> + fi\r
+>> + OPTARG=3D$2\r
+>> + OPTIND=3D$((OPTIND + 1))\r
+>> + ;;\r
+>> + # Long options without arguments.\r
+>> + --help|--nw|--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-emacs-mua\r
+>> + ;;\r
+>> + --from)\r
+>> + escape_optarg\r
+>> + FROM=3D${OPTARG}\r
+>> + ;;\r
+>> + --subject|s)\r
+>> + escape_optarg\r
+>> + SUBJECT=3D${SUBJECT:+$SUBJECT }${OPTARG}\r
+>> + ;;\r
+>> + --to)\r
+>> + escape_optarg\r
+>> + TO=3D${TO:+$TO, }${OPTARG}\r
+>> + ;;\r
+>> + --cc|c)\r
+>> + escape_optarg\r
+>> + CC=3D${CC:+$CC, }${OPTARG}\r
+>> + ;;\r
+>> + --bcc|b)\r
+>> + escape_optarg\r
+>> + BCC=3D${BCC:+$BCC, }${OPTARG}\r
+>> + ;;\r
+>> + i)\r
+>> + escape_optarg\r
+>> + if [[ ! -f ${OPTARG} ]]; then\r
+>> + echo "$0: '${OPTARG}': no such file" >&2\r
+>> + exit 1\r
+>> + fi\r
+>> + IB=3D${IB}$'\n'" (insert-file \"${OPTARG}\")"\r
+>\r
+> This needs the (cd \"${PWD}\") bit because --body given here may be\r
+> relative to the script, while emacs likely has a totally different cwd.\r
+\r
+Yes, the drop of that was accidental and not intentional. We could also\r
+escape $PWD too, in case user does:\r
+\r
+mkdir '.")(shell-command "/bin/rm -rf ~'; cd ...\r
+\r
+although that is probably not accidental... well have to think for\r
+cases user's PWD contains just one '"' for some reason..\r
+\r
+>> + IB=3D${IB}$'\n'" (if /=3D (point) (line-beginning-position) (inse=\r
+rt \"\\n\"))"\r
+>> + ;;\r
+>> + --body)\r
+>> + escape_body_optarg\r
+>> + IB=3D${IB}$'\n'" (insert \"${OPTARG}\\n\")"\r
+>\r
+> Why should --body and -i be different?\r
+\r
+Now, this is the one that is important to get decided now!\r
+\r
+The -i is different from other options as it loads a file to be added to\r
+the mail buffer, when all other options put the option value to the buffer.\r
+an analogous option to that would IMO be --insert (or --include).=20\r
+\r
+Also, I desire an option to write mail content lines from command line\r
+option directly. To me --body (which is not mutt(1) option) to work\r
+as adding the variable to mail buffer is more consistent with the other\r
+options -- and we could add this --insert as long option to -i.\r
+\r
+Anyway, whatever the option to be able to insert body content from command\r
+line is desired -- if there is any better choice :)\r
+\r
+I also think that s/escape_body_optarg/escape_optarg/ (and dropping=20\r
+escape_body_optarg) should be done. escape_body_optarg would have\r
+left e.g. "\n"s there and let emacs add newlines there. But this is\r
+some hidden emacs-specific magic and might not be compatible with\r
+e.g. notmuch-vim-mua (provided that someone(tm) will write such an utility).\r
+\r
+>> + ;;\r
+>> + --nw)\r
+>> + W=3D-nw\r
+\r
+I could change this to W=3D--nw :)\r
+\r
+>> + ;;\r
+>> + --print)\r
+>> + X=3Decho\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${arg//\\/\\\\}; arg=3D${arg//\"/\\\"}\r
+>> + TO=3D${TO:+$TO, }${arg}\r
+>> +done\r
+>> +\r
+>> +NL=3D$'\n'\r
+>> +ELISP=3D"\\r
+>> +${CC:+$NL (message-goto-cc) (insert \"$CC\")}\\r
+>> +${BCC:+$NL (message-goto-bcc) (insert \"$BCC\")}\\r
+>> +${IB:+$NL (message-goto-body)$IB}"\r
+>> +\r
+>> +if [[ $TO =3D=3D '' && $SUBJECT =3D=3D '' && $ELISP =3D=3D '' ]]\r
+>> +then\r
+>> + exec_mua "(progn (require 'notmuch) (notmuch-hello))"\r
+>> +else\r
+>> + [[ $FROM !=3D '' ]] && OH=3D"(list (cons 'From \"$FROM\"))" || OH=\r
+=3Dnil\r
+>> + [[ $TO !=3D '' ]] && TO=3D\"$TO\" || TO=3Dnil\r
+>> + [[ $SUBJECT !=3D '' ]] && SUBJECT=3D\"$SUBJECT\" || SUBJECT=3Dnil\r
+>> + exec_mua "$NL(progn (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-to))"\r
+>\r
+> I think the newlines with $NL hurt readability in the script more than\r
+> they help readability in the output... which is generally interpreted by\r
+> emacs which doesn't really care about the newlines! ;)\r
+\r
+This is half thing left to be decided now. The $NL:s make --print -output\r
+(very!) pretty.=20\r
+\r
+I can make $NL be empty in case --print is not given -- and and another\r
+variable to contain 0/2 spaces depending on --print value to make emacs\r
+and human viewer happy... >;)\r
+\r
+I personally don't think those 4 $NL:s make the readability of the script\r
+much worse -- but I can turn those to ${NL}:s if that help. It seems\r
+your original code uses those more and I have not -- not because of a\r
+style issue but because I am just so accustomed to do so... That said\r
+I take more care of those in future versions...\r
+\r
+>\r
+> BR,\r
+> Jani.\r
+\r
+Tomi\r
+\r
+>\r
+>\r
+>> +fi\r
+>> --=20\r
+>> 1.9.0\r