Re: [PATCH] add has: query prefix to search for specific properties
[notmuch-archives.git] / 38 / bb4ce1200c32f7b7c262c1a899ffe9ef3d648a
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 56201431FAF\r
6         for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 12:26:06 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 1R+g0w7lFk78 for <notmuch@notmuchmail.org>;\r
16         Wed, 19 Mar 2014 12:25:57 -0700 (PDT)\r
17 Received: from mail-ee0-f51.google.com (mail-ee0-f51.google.com\r
18  [74.125.83.51])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  13F2F431FAE    for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 12:25:56 -0700\r
21  (PDT)\r
22 Received: by mail-ee0-f51.google.com with SMTP id c13so7045928eek.10\r
23         for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 12:25:55 -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:cc:subject:date:message-id:mime-version\r
27         :content-type:content-transfer-encoding;\r
28         bh=x92F1NPeXe3/Vicu3SOY9mckk4+ceONYwongSXhm8l0=;\r
29         b=KxgfH1W240joGMJc+rQX1FZCLkavdoEPFDMd+NntfVefMge6pbjMrDjbb8QoCC5SPq\r
30         xJSCoJ46eqPksQsl6A7ppcqUMUI5FGU7EHRX7IqHJkW5M6ullFdOJ5yvaWAAimdntS9V\r
31         14tF889KDHzptuIIiFB+ViFGXdljU9E29iPSl/XOvv98gsUFeLRUZoGrnvSs1ja1i6pU\r
32         WLdszfufEYYcXtNm9FXFjyG3pJbD8ZtQHUFVFGeAaA486thFKNofd1Eirhh5YTHdSk9n\r
33         BfWasFogcFdc/D/OsEmB78EEaBYOnoWjA5VRS30DzcyZMwNJt0iLwFBkcwz0m9hu8e+l\r
34         JyrQ==\r
35 X-Gm-Message-State:\r
36  ALoCoQmVAocU4lPnWbIVYaAIT1xkZ79w7HaLALPX8IWCfKdFEJ2A+PK6Z5x7Cy0Dk3Lak/x61Yvr\r
37 X-Received: by 10.15.100.196 with SMTP id bn44mr538463eeb.104.1395257155785;\r
38         Wed, 19 Mar 2014 12:25:55 -0700 (PDT)\r
39 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
40         [88.195.111.91])\r
41         by mx.google.com with ESMTPSA id w6sm56664932eex.9.2014.03.19.12.25.54\r
42         for <multiple recipients>\r
43         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
44         Wed, 19 Mar 2014 12:25:55 -0700 (PDT)\r
45 From: Jani Nikula <jani@nikula.org>\r
46 To: notmuch@notmuchmail.org\r
47 Subject: [PATCH] cli: add a tool for starting new message in the emacs ui\r
48 Date: Wed, 19 Mar 2014 21:25:53 +0200\r
49 Message-Id: <1395257153-29764-1-git-send-email-jani@nikula.org>\r
50 X-Mailer: git-send-email 1.9.0\r
51 MIME-Version: 1.0\r
52 Content-Type: text/plain; charset=UTF-8\r
53 Content-Transfer-Encoding: 8bit\r
54 X-BeenThere: notmuch@notmuchmail.org\r
55 X-Mailman-Version: 2.1.13\r
56 Precedence: list\r
57 List-Id: "Use and development of the notmuch mail system."\r
58         <notmuch.notmuchmail.org>\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
62 List-Post: <mailto:notmuch@notmuchmail.org>\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
66 X-List-Received-Date: Wed, 19 Mar 2014 19:26:06 -0000\r
67 \r
68 Add a tool to start composing an email in the Notmuch Emacs UI with\r
69 the specified subject, recipients, and message body.\r
70 \r
71 ---\r
72 \r
73 I need something like this to script some mails, particularly with the\r
74 mutt compatible options, but I also think notmuch must have long\r
75 options. I then got a little carried away with figuring out how to\r
76 support both. I think it turned out pretty neat, except due to some\r
77 subtlety it only works with bash.\r
78 \r
79 I didn't integrate this in the man build or install or anything,\r
80 because I wanted to get feedback first on whether we want to have this\r
81 at all. Or if it should live in contrib or something.\r
82 \r
83 BR,\r
84 Jani.\r
85 ---\r
86  doc/man1/notmuch-emacs-mua.rst |  50 ++++++++++++++++++\r
87  notmuch-emacs-mua              | 113 +++++++++++++++++++++++++++++++++++++++++\r
88  2 files changed, 163 insertions(+)\r
89  create mode 100644 doc/man1/notmuch-emacs-mua.rst\r
90  create mode 100755 notmuch-emacs-mua\r
91 \r
92 diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.rst\r
93 new file mode 100644\r
94 index 000000000000..6e63818492fb\r
95 --- /dev/null\r
96 +++ b/doc/man1/notmuch-emacs-mua.rst\r
97 @@ -0,0 +1,50 @@\r
98 +=================\r
99 +notmuch-emacs-mua\r
100 +=================\r
101 +\r
102 +SYNOPSIS\r
103 +========\r
104 +\r
105 +**notmuch-emacs-mua** [options ...] [<to-address> ...]\r
106 +\r
107 +DESCRIPTION\r
108 +===========\r
109 +\r
110 +Start composing an email in the Notmuch Emacs UI with the specified\r
111 +subject, recipients, and message body.\r
112 +\r
113 +For **notmuch-emacs-mua** to work, you need **emacsclient** and an\r
114 +already running Emacs with a server.\r
115 +\r
116 +Supported options for **notmuch-emacs-mua** include\r
117 +\r
118 +    ``-h, --help``\r
119 +        Display help.\r
120 +\r
121 +    ``-s, --subject=``\ <subject>\r
122 +        Specify the subject of the message.\r
123 +\r
124 +    ``--to=``\ <to-address>\r
125 +        Specify a recipient (To).\r
126 +\r
127 +    ``-c, --cc=``\ <cc-address>\r
128 +        Specify a carbon-copy (Cc) recipient.\r
129 +\r
130 +    ``-b, --bcc=``\ <bcc-address>\r
131 +        Specify a blind-carbon-copy (Bcc) recipient.\r
132 +\r
133 +    ``-i, --body=``\ <file>\r
134 +        Specify a file to include into the body of the message.\r
135 +\r
136 +    ``--print``\r
137 +        Output the resulting elisp to stdout instead of evaluating it.\r
138 +\r
139 +The supported positional parameters and short options are a compatible\r
140 +subset of the **mutt** MUA command-line options.\r
141 +\r
142 +Options may be specified multiple times.\r
143 +\r
144 +SEE ALSO\r
145 +========\r
146 +\r
147 +**notmuch(1)**, **emacsclient(1)**, **mutt(1)**\r
148 diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
149 new file mode 100755\r
150 index 000000000000..a482fe1a8eca\r
151 --- /dev/null\r
152 +++ b/notmuch-emacs-mua\r
153 @@ -0,0 +1,113 @@\r
154 +#!/bin/bash\r
155 +#\r
156 +# notmuch-emacs-mua - start composing a mail on the command line\r
157 +#\r
158 +# Copyright © 2014 Jani Nikula\r
159 +#\r
160 +# This program is free software: you can redistribute it and/or modify\r
161 +# it under the terms of the GNU General Public License as published by\r
162 +# the Free Software Foundation, either version 3 of the License, or\r
163 +# (at your option) any later version.\r
164 +#\r
165 +# This program is distributed in the hope that it will be useful,\r
166 +# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
167 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
168 +# GNU General Public License for more details.\r
169 +#\r
170 +# You should have received a copy of the GNU General Public License\r
171 +# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
172 +#\r
173 +# Authors: Jani Nikula <jani@nikula.org>\r
174 +#\r
175 +\r
176 +set -e\r
177 +\r
178 +# The crux of it all: construct an elisp progn and eval it.\r
179 +ELISP="(progn (notmuch-mua-new-mail)"\r
180 +\r
181 +while getopts :s:c:b:i:h opt; do\r
182 +    # Handle errors and long options.\r
183 +    case "${opt}" in\r
184 +       :)\r
185 +           echo "$0: short option -${OPTARG} requires an argument." >&2\r
186 +           exit 1\r
187 +           ;;\r
188 +       \?)\r
189 +           opt=$1\r
190 +           if [ "${OPTARG}" != "-" ]; then\r
191 +               echo "$0: unknown short option -${OPTARG}." >&2\r
192 +               exit 1\r
193 +           fi\r
194 +\r
195 +           case "${opt}" in\r
196 +               # Long options with arguments.\r
197 +               --subject=*|--to=*|--cc=*|--bcc=*|--body=*)\r
198 +                   OPTARG=${opt#--*=}\r
199 +                   opt=${opt%%=*}\r
200 +                   ;;\r
201 +               # Long options without arguments.\r
202 +               --help|--print)\r
203 +                   ;;\r
204 +               *)\r
205 +                   echo "$0: unknown long option ${opt}, or argument mismatch." >&2\r
206 +                   exit 1\r
207 +                   ;;\r
208 +           esac\r
209 +           # getopts does not do this for what it considers errors.\r
210 +           OPTIND=$((OPTIND + 1))\r
211 +           ;;\r
212 +    esac\r
213 +\r
214 +    case "${opt}" in\r
215 +       --help|h)\r
216 +           exec man notmuch-search\r
217 +           ;;\r
218 +       --subject|s)\r
219 +           ELISP="${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"\r
220 +           ;;\r
221 +       --to)\r
222 +           ELISP="${ELISP} (message-goto-to) (insert \"${OPTARG}, \")"\r
223 +           ;;\r
224 +       --cc|c)\r
225 +           ELISP="${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")"\r
226 +           ;;\r
227 +       --bcc|b)\r
228 +           ELISP="${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")"\r
229 +           ;;\r
230 +       --body|i)\r
231 +           ELISP="${ELISP} (message-goto-body) (cd \"${PWD}\") (insert-file \"${OPTARG}\")"\r
232 +           ;;\r
233 +       --print)\r
234 +           PRINT_ONLY=1\r
235 +           ;;\r
236 +       *)\r
237 +           # We should never end up here.\r
238 +           echo "$0: internal error (option ${opt})." >&2\r
239 +           exit 1\r
240 +           ;;\r
241 +    esac\r
242 +\r
243 +    shift $((OPTIND - 1))\r
244 +    OPTIND=1\r
245 +done\r
246 +\r
247 +# Positional parameters.\r
248 +while [ $# -gt 0 ]; do\r
249 +    ELISP="${ELISP} (message-goto-to) (insert \"${1}, \")"\r
250 +    shift\r
251 +done\r
252 +\r
253 +# End progn.\r
254 +ELISP="${ELISP})"\r
255 +\r
256 +if [ -n "$PRINT_ONLY" ]; then\r
257 +    echo ${ELISP}\r
258 +    exit 0\r
259 +fi\r
260 +\r
261 +# Evaluate the progn.\r
262 +emacsclient --eval "${ELISP}" &>/dev/null\r
263 +if [ $? -ne 0 ]; then\r
264 +    echo "$0: emacsclient failed" >&2\r
265 +    exit 1\r
266 +fi\r
267 -- \r
268 1.9.0\r
269 \r