1 Return-Path: <too@guru-group.fi>
\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 34818431FAF
\r
6 for <notmuch@notmuchmail.org>; Thu, 10 Jul 2014 14:13:24 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 V+tidhWHrZwI for <notmuch@notmuchmail.org>;
\r
16 Thu, 10 Jul 2014 14:13:17 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 8F573431FAE
\r
19 for <notmuch@notmuchmail.org>; Thu, 10 Jul 2014 14:13:17 -0700 (PDT)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 833171000C9; Fri, 11 Jul 2014 00:13:08 +0300 (EEST)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org, jani@nikula.org, david@tethera.net,
\r
24 jrollins@finestructure.net
\r
25 Subject: [DRAFT PATCH] modified notmuch-emacs-mua
\r
26 Date: Fri, 11 Jul 2014 00:12:59 +0300
\r
27 Message-Id: <1405026779-29966-1-git-send-email-tomi.ollila@iki.fi>
\r
28 X-Mailer: git-send-email 2.0.0
\r
30 Content-Type: text/plain; charset=UTF-8
\r
31 Content-Transfer-Encoding: 8bit
\r
32 Cc: tomi.ollila@iki.fi
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.13
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Thu, 10 Jul 2014 21:13:24 -0000
\r
49 * notmuch-emacs-mua without arguments runs (notmuch-hello)
\r
51 * runs emacs(1) in case emacsclient(1) fails to connect to running emacs
\r
57 * --from option when sending non-mailto: way
\r
59 * -i includes file --body[= ]string inserts string
\r
61 notmuch-emacs-mua | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
62 1 file changed, 200 insertions(+)
\r
63 create mode 100755 notmuch-emacs-mua
\r
65 diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua
\r
66 new file mode 100755
\r
67 index 0000000..b1696f7
\r
69 +++ b/notmuch-emacs-mua
\r
71 +#!/usr/bin/env bash
\r
72 +# -*- mode: shell-script; sh-basic-offset: 4; tab-width: 8 -*-
\r
74 +# notmuch-emacs-mua - start composing a mail on the command line
\r
76 +# Copyright © 2014 Jani Nikula
\r
78 +# This program is free software: you can redistribute it and/or modify
\r
79 +# it under the terms of the GNU General Public License as published by
\r
80 +# the Free Software Foundation, either version 3 of the License, or
\r
81 +# (at your option) any later version.
\r
83 +# This program is distributed in the hope that it will be useful,
\r
84 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
85 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
86 +# GNU General Public License for more details.
\r
88 +# You should have received a copy of the GNU General Public License
\r
89 +# along with this program. If not, see http://www.gnu.org/licenses/ .
\r
91 +# Authors: Jani Nikula <jani@nikula.org>
\r
92 +# Tomi Ollila <tomi.ollila@iki.fi>
\r
97 +# "expand" '\' to '\\' & '"' to '\"'
\r
100 + OPTARG=${OPTARG//\\/\\\\}; OPTARG=${OPTARG//\"/\\\"}
\r
103 +# ditto, in case there is '\n' sequence in the source, otherwise
\r
104 +# "expand" only trailing '\'s to '\\'s
\r
105 +escape_body_optarg ()
\r
107 + case ${OPTARG} in
\r
108 + *'\"'*) OPTARG=${OPTARG//\\/\\\\} ;;
\r
109 + *'\') OPTARG=$( printf %s "${OPTARG}" | sed 's/\(\\*\)$/\1\1/' )
\r
111 + OPTARG=${OPTARG//\"/\\\"}
\r
114 +unset ALTERNATE_EDITOR
\r
117 + if "${EMACSCLIENT:=emacsclient}" --eval t >/dev/null 2>&1
\r
119 + emacs=$EMACSCLIENT
\r
120 + # close stdout in case no -nw (and no --print)
\r
121 + test -n "$W$X" || exec >/dev/null
\r
123 + emacs=${EMACS:-emacs}
\r
125 + ${X:-exec} "$emacs" $W --eval "$*"
\r
127 + ${X:-exec "$emacs" $W --eval} "$*"
\r
133 +SUBJECT= TO= CC= BCC= BODY= FROM= IB=
\r
136 + # first, handle "long" options which cannot be handled by getopts
\r
144 + oIFS=$IFS; IFS=; OPTARG="$*" IFS=$oIFS
\r
146 + exec_mua "(progn (require 'notmuch) (browse-url-mail \"$OPTARG\"))"
\r
150 + getopts :s:c:b:i:h opt
\r
152 + # Handle errors and long options.
\r
155 + echo "$0: short option '-${OPTARG}' requires an argument." >&2
\r
160 + if [[ ${OPTARG} != '-' ]]; then
\r
161 + echo "$0: unknown short option '-${OPTARG}'." >&2
\r
166 + # Long options with arguments.
\r
167 + --subject=*|--to=*|--cc=*|--bcc=*|--body=*|--from=*)
\r
168 + OPTARG=${opt#--*=}
\r
171 + # Long options with argument in next arg.
\r
172 + --subject |--to |--cc |--bcc |--body |--from )
\r
173 + if [[ $# < 2 ]]; then
\r
174 + echo "$0: option '${opt}' requires an argument." >&2
\r
178 + OPTIND=$((OPTIND + 1))
\r
180 + # Long options without arguments.
\r
181 + --help|--nw|--print)
\r
184 + echo "$0: unknown long option '${opt}', or argument mismatch." >&2
\r
188 + # getopts does not do this for what it considers errors.
\r
189 + OPTIND=$((OPTIND + 1))
\r
195 + exec man notmuch-emacs-mua
\r
203 + SUBJECT=${SUBJECT:+$SUBJECT }${OPTARG}
\r
207 + TO=${TO:+$TO, }${OPTARG}
\r
211 + CC=${CC:+$CC, }${OPTARG}
\r
215 + BCC=${BCC:+$BCC, }${OPTARG}
\r
219 + if [[ ! -f ${OPTARG} ]]; then
\r
220 + echo "$0: '${OPTARG}': no such file" >&2
\r
223 + IB=${IB}$'\n'" (insert-file \"${OPTARG}\")"
\r
224 + IB=${IB}$'\n'" (if /= (point) (line-beginning-position) (insert \"\\n\"))"
\r
227 + escape_body_optarg
\r
228 + IB=${IB}$'\n'" (insert \"${OPTARG}\\n\")"
\r
237 + # We should never end up here.
\r
238 + echo "$0: internal error (option '${opt}')." >&2
\r
243 + shift $((OPTIND - 1))
\r
247 +# Positional parameters.
\r
249 + arg=${arg//\\/\\\\}; arg=${arg//\"/\\\"}
\r
250 + TO=${TO:+$TO, }${arg}
\r
255 +${CC:+$NL (message-goto-cc) (insert \"$CC\")}\
\r
256 +${BCC:+$NL (message-goto-bcc) (insert \"$BCC\")}\
\r
257 +${IB:+$NL (message-goto-body)$IB}"
\r
259 +if [[ $TO == '' && $SUBJECT == '' && $ELISP == '' ]]
\r
261 + exec_mua "(progn (require 'notmuch) (notmuch-hello))"
\r
263 + [[ $FROM != '' ]] && OH="(list (cons 'From \"$FROM\"))" || OH=nil
\r
264 + [[ $TO != '' ]] && TO=\"$TO\" || TO=nil
\r
265 + [[ $SUBJECT != '' ]] && SUBJECT=\"$SUBJECT\" || SUBJECT=nil
\r
266 + exec_mua "$NL(progn (require 'notmuch)
\r
267 + (notmuch-mua-mail $TO $SUBJECT
\r
268 + $OH nil (notmuch-mua-get-switch-function))\
\r
269 +$ELISP$NL (set-buffer-modified-p nil) (message-goto-to))"
\r