1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 1628C431FAF
\r
6 for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 14:54:30 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id b546+2belAIF for <notmuch@notmuchmail.org>;
\r
16 Wed, 19 Mar 2014 14:54:21 -0700 (PDT)
\r
17 Received: from mail-la0-f53.google.com (mail-la0-f53.google.com
\r
18 [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 65BD4431FAE
\r
21 for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 14:54:21 -0700 (PDT)
\r
22 Received: by mail-la0-f53.google.com with SMTP id b8so6288937lan.26
\r
23 for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 14:54:19 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=1e100.net; s=20130820;
\r
26 h=x-gm-message-state:from:to:subject:in-reply-to:references
\r
27 :user-agent:date:message-id:mime-version:content-type
\r
28 :content-transfer-encoding;
\r
29 bh=5f1TvgYuiL9m3PlxRQ7+DlgiPangqPmJN7lxenFFImM=;
\r
30 b=R4YU8esDyw0x/Ab1+zLSKdO9+c7ZHUODWgA0kzDW8llx1ZG8JUQ6FkMR+gvTrtbtUY
\r
31 3DhDYmejcp2lzxwAY+iD4GHaOxwI9/i24WfrV1ctADpc3VIj6+OdylV7mQrQctXeQBKS
\r
32 is+LftTb6IlqKimGTMjDMuafUej7VknwuAdGG2yn2A05Pbl6XKlaFQqmxldRjY82ZwGb
\r
33 sExQlItANE0NFnGXXzjA/hTWF3lc09t77rQtDVIEjDBcxPw6eh39B1GmV2P3NcbEuHMy
\r
34 oNDPtm2Yyrs+NLFAGTgkgQgdAKTLEmd+wbo9GLOdp1pqEva9flutiXQv25brn7fK3DBA
\r
37 ALoCoQm4HWKiVXGMk0uOeHHEqHDxAportEC0yCUYnxLq/ucBcMHkSHrv1cu6ZawNF4+LTcpW+w+/
\r
38 X-Received: by 10.112.137.5 with SMTP id qe5mr26138470lbb.16.1395266058612;
\r
39 Wed, 19 Mar 2014 14:54:18 -0700 (PDT)
\r
40 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.
\r
42 by mx.google.com with ESMTPSA id rd5sm17906775lbb.0.2014.03.19.14.54.16
\r
43 for <multiple recipients>
\r
44 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
45 Wed, 19 Mar 2014 14:54:17 -0700 (PDT)
\r
46 From: Jani Nikula <jani@nikula.org>
\r
47 To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org
\r
48 Subject: Re: [PATCH] cli: add a tool for starting new message in the emacs ui
\r
49 In-Reply-To: <m2eh1x6fwt.fsf@guru.guru-group.fi>
\r
50 References: <1395257153-29764-1-git-send-email-jani@nikula.org>
\r
51 <m2eh1x6fwt.fsf@guru.guru-group.fi>
\r
52 User-Agent: Notmuch/0.17+142~g30045abd801f (http://notmuchmail.org)
\r
53 Emacs/24.3.1 (x86_64-pc-linux-gnu)
\r
54 Date: Wed, 19 Mar 2014 23:54:15 +0200
\r
55 Message-ID: <877g7pn9bs.fsf@nikula.org>
\r
57 Content-Type: text/plain; charset=utf-8
\r
58 Content-Transfer-Encoding: quoted-printable
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Wed, 19 Mar 2014 21:54:30 -0000
\r
73 On Wed, 19 Mar 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:
\r
74 > On Wed, Mar 19 2014, Jani Nikula <jani@nikula.org> wrote:
\r
76 >> Add a tool to start composing an email in the Notmuch Emacs UI with
\r
77 >> the specified subject, recipients, and message body.
\r
81 >> I need something like this to script some mails, particularly with the
\r
82 >> mutt compatible options, but I also think notmuch must have long
\r
83 >> options. I then got a little carried away with figuring out how to
\r
84 >> support both. I think it turned out pretty neat, except due to some
\r
85 >> subtlety it only works with bash.
\r
87 >> I didn't integrate this in the man build or install or anything,
\r
88 >> because I wanted to get feedback first on whether we want to have this
\r
89 >> at all. Or if it should live in contrib or something.
\r
95 > Quick glance to the code and some thoughts.
\r
100 >> doc/man1/notmuch-emacs-mua.rst | 50 ++++++++++++++++++
\r
101 >> notmuch-emacs-mua | 113 ++++++++++++++++++++++++++++++++++=
\r
103 >> 2 files changed, 163 insertions(+)
\r
104 >> create mode 100644 doc/man1/notmuch-emacs-mua.rst
\r
105 >> create mode 100755 notmuch-emacs-mua
\r
107 >> diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua=
\r
109 >> new file mode 100644
\r
110 >> index 000000000000..6e63818492fb
\r
112 >> +++ b/doc/man1/notmuch-emacs-mua.rst
\r
113 >> @@ -0,0 +1,50 @@
\r
114 >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
\r
115 >> +notmuch-emacs-mua
\r
116 >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
\r
119 >> +=3D=3D=3D=3D=3D=3D=3D=3D
\r
121 >> +**notmuch-emacs-mua** [options ...] [<to-address> ...]
\r
124 >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
\r
126 >> +Start composing an email in the Notmuch Emacs UI with the specified
\r
127 >> +subject, recipients, and message body.
\r
129 >> +For **notmuch-emacs-mua** to work, you need **emacsclient** and an
\r
130 >> +already running Emacs with a server.
\r
132 >> +Supported options for **notmuch-emacs-mua** include
\r
134 >> + ``-h, --help``
\r
137 >> + ``-s, --subject=3D``\ <subject>
\r
138 >> + Specify the subject of the message.
\r
140 >> + ``--to=3D``\ <to-address>
\r
141 >> + Specify a recipient (To).
\r
143 >> + ``-c, --cc=3D``\ <cc-address>
\r
144 >> + Specify a carbon-copy (Cc) recipient.
\r
146 >> + ``-b, --bcc=3D``\ <bcc-address>
\r
147 >> + Specify a blind-carbon-copy (Bcc) recipient.
\r
149 >> + ``-i, --body=3D``\ <file>
\r
150 >> + Specify a file to include into the body of the message.
\r
153 >> + Output the resulting elisp to stdout instead of evaluating it.
\r
155 >> +The supported positional parameters and short options are a compatible
\r
156 >> +subset of the **mutt** MUA command-line options.
\r
158 >> +Options may be specified multiple times.
\r
161 >> +=3D=3D=3D=3D=3D=3D=3D=3D
\r
163 >> +**notmuch(1)**, **emacsclient(1)**, **mutt(1)**
\r
165 > It would be convenient to the user to have the manual embedded in
\r
166 > the script in case no args are given or so (or that is convenient
\r
167 > to me ;) and no namual page at all...
\r
169 If this is to become part of notmuch, I think a separate man page is in
\r
170 order. Otherwise, agreed (and even had that in an earlier version).
\r
173 >> diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua
\r
174 >> new file mode 100755
\r
175 >> index 000000000000..a482fe1a8eca
\r
177 >> +++ b/notmuch-emacs-mua
\r
178 >> @@ -0,0 +1,113 @@
\r
181 > #!/usr/bin/env bash
\r
187 >> +# notmuch-emacs-mua - start composing a mail on the command line
\r
189 >> +# Copyright =C2=A9 2014 Jani Nikula
\r
191 >> +# This program is free software: you can redistribute it and/or modify
\r
192 >> +# it under the terms of the GNU General Public License as published by
\r
193 >> +# the Free Software Foundation, either version 3 of the License, or
\r
194 >> +# (at your option) any later version.
\r
196 >> +# This program is distributed in the hope that it will be useful,
\r
197 >> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
198 >> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
199 >> +# GNU General Public License for more details.
\r
201 >> +# You should have received a copy of the GNU General Public License
\r
202 >> +# along with this program. If not, see http://www.gnu.org/licenses/ .
\r
204 >> +# Authors: Jani Nikula <jani@nikula.org>
\r
209 > set -eu would be nice IMO...
\r
211 > ... then initialize all vars to empty strings, like PRINT_ONLY=3D
\r
212 > ... and in cases not possible syntax ${1-} can be used.
\r
218 >> +# The crux of it all: construct an elisp progn and eval it.
\r
219 >> +ELISP=3D"(progn (notmuch-mua-new-mail)"
\r
221 > ELISP=3D"(progn (require 'notmuch) (notmuch-mua-new-mail)"
\r
227 >> +while getopts :s:c:b:i:h opt; do
\r
228 >> + # Handle errors and long options.
\r
229 >> + case "${opt}" in
\r
231 >> + echo "$0: short option -${OPTARG} requires an argument." >&2
\r
236 >> + if [ "${OPTARG}" !=3D "-" ]; then
\r
237 >> + echo "$0: unknown short option -${OPTARG}." >&2
\r
241 >> + case "${opt}" in
\r
242 >> + # Long options with arguments.
\r
243 >> + --subject=3D*|--to=3D*|--cc=3D*|--bcc=3D*|--body=3D*)
\r
244 >> + OPTARG=3D${opt#--*=3D}
\r
245 >> + opt=3D${opt%%=3D*}
\r
247 >> + # Long options without arguments.
\r
248 >> + --help|--print)
\r
251 >> + echo "$0: unknown long option ${opt}, or argument mismatch." >&2
\r
255 >> + # getopts does not do this for what it considers errors.
\r
256 >> + OPTIND=3D$((OPTIND + 1))
\r
260 >> + case "${opt}" in
\r
262 >> + exec man notmuch-search
\r
265 >> + ELISP=3D"${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"
\r
268 >> + ELISP=3D"${ELISP} (message-goto-to) (insert \"${OPTARG}, \")"
\r
271 >> + ELISP=3D"${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")"
\r
274 >> + ELISP=3D"${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")"
\r
277 >> + ELISP=3D"${ELISP} (message-goto-body) (cd \"${PWD}\") (insert-file=
\r
281 >> + PRINT_ONLY=3D1
\r
284 >> + # We should never end up here.
\r
285 >> + echo "$0: internal error (option ${opt})." >&2
\r
290 >> + shift $((OPTIND - 1))
\r
294 >> +# Positional parameters.
\r
295 >> +while [ $# -gt 0 ]; do
\r
296 >> + ELISP=3D"${ELISP} (message-goto-to) (insert \"${1}, \")"
\r
304 > ELISP=3D"${ELISP} (message-goto-to) (insert \"${arg}, \")"
\r
307 > I tried to address Austin's comment on IRC with=20
\r
308 > printf -v qarg %q "$arg" -- that has problem if there is whitespace
\r
309 > in arg. maybe printf -v qarg '%q ' "$arg" -- then there is always one
\r
310 > trailing ws (and spaces are always prefixed w/ \ -- (insert "foo\ bar")
\r
311 > just makes the ' ' disappear (which is not good...).
\r
313 > maybe arg=3D${arg//\\/\\\\}; arg=3D${arg//"/\\"};=20
\r
315 > ${parameter/pattern/string} -- Pattern substition in bash manual.
\r
317 I'm inclined to go with "don't do that then" ;)
\r
322 >> +ELISP=3D"${ELISP})"
\r
324 >> +if [ -n "$PRINT_ONLY" ]; then
\r
329 >> +# Evaluate the progn.
\r
330 >> +emacsclient --eval "${ELISP}" &>/dev/null
\r
332 > emacsclient --eval "${ELISP}" >/dev/null 2>&1
\r
334 > (why do you want to redirect stdout & stderr to devnull ?)
\r
336 Okay, maybe it could be just stdout (which will be the eval result, in
\r
340 >> +if [ $? -ne 0 ]; then
\r
341 >> + echo "$0: emacsclient failed" >&2
\r