bug: RELEASING should cover version & date in notmuch.1
[notmuch-archives.git] / ab / b486f5b9047419f1c665de4d62c98f9627b536
1 Return-Path: <sojkam1@fel.cvut.cz>\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 842BB40D148\r
6         for <notmuch@notmuchmail.org>; Fri, 22 Oct 2010 02:28:47 -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: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\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 PFCxltAzwREE for <notmuch@notmuchmail.org>;\r
16         Fri, 22 Oct 2010 02:28:32 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id 13AB140D14D\r
19         for <notmuch@notmuchmail.org>; Fri, 22 Oct 2010 02:28:18 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 1A57919F33B5;\r
22         Fri, 22 Oct 2010 11:28:17 +0200 (CEST)\r
23 X-Virus-Scanned: IMAP AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
26         port 10044)\r
27         with ESMTP id vHNwQ2xABZ-G; Fri, 22 Oct 2010 11:28:15 +0200 (CEST)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id EFADD19F3365;\r
30         Fri, 22 Oct 2010 11:28:14 +0200 (CEST)\r
31 Received: from steelpick.2x.cz (note-sojka.felk.cvut.cz [147.32.86.30])\r
32         (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 041F4FA006;\r
34         Fri, 22 Oct 2010 11:28:14 +0200 (CEST)\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.72)\r
36         (envelope-from <sojkam1@fel.cvut.cz>)\r
37         id 1P9Dv4-0006oz-0v; Fri, 22 Oct 2010 11:28:14 +0200\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 1/2] Add 'cat' subcommand\r
41 Date: Fri, 22 Oct 2010 11:28:03 +0200\r
42 Message-Id: <1287739684-26188-2-git-send-email-sojkam1@fel.cvut.cz>\r
43 X-Mailer: git-send-email 1.7.2.3\r
44 In-Reply-To: <1287739684-26188-1-git-send-email-sojkam1@fel.cvut.cz>\r
45 References: <1287739684-26188-1-git-send-email-sojkam1@fel.cvut.cz>\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Fri, 22 Oct 2010 09:28:47 -0000\r
59 \r
60 This command outputs a raw message matched by search term to the\r
61 standard output. It allows MUAs to access the messages for piping,\r
62 attachment manipulation, etc. by running notmuch cat rather then\r
63 directly access the file. This will simplify the MUAs when they need\r
64 to operate on a remote database.\r
65 ---\r
66  notmuch-client.h  |    3 ++\r
67  notmuch-show.c    |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
68  notmuch.1         |    4 ++\r
69  notmuch.c         |    4 ++\r
70  test/cat          |   38 ++++++++++++++++++++++++\r
71  test/notmuch-test |    2 +-\r
72  6 files changed, 133 insertions(+), 1 deletions(-)\r
73  create mode 100755 test/cat\r
74 \r
75 diff --git a/notmuch-client.h b/notmuch-client.h\r
76 index 20be43b..82526f8 100644\r
77 --- a/notmuch-client.h\r
78 +++ b/notmuch-client.h\r
79 @@ -111,6 +111,9 @@ int\r
80  notmuch_search_tags_command (void *ctx, int argc, char *argv[]);\r
81  \r
82  int\r
83 +notmuch_cat_command (void *ctx, int argc, char *argv[]);\r
84 +\r
85 +int\r
86  notmuch_part_command (void *ctx, int argc, char *argv[]);\r
87  \r
88  const char *\r
89 diff --git a/notmuch-show.c b/notmuch-show.c\r
90 index ea465de..285f38f 100644\r
91 --- a/notmuch-show.c\r
92 +++ b/notmuch-show.c\r
93 @@ -632,6 +632,89 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
94  }\r
95  \r
96  int\r
97 +notmuch_cat_command (void *ctx, unused (int argc), unused (char *argv[]))\r
98 +{\r
99 +    notmuch_config_t *config;\r
100 +    notmuch_database_t *notmuch;\r
101 +    notmuch_query_t *query;\r
102 +    notmuch_messages_t *messages;\r
103 +    notmuch_message_t *message;\r
104 +    char *query_string;\r
105 +    int i;\r
106 +    const char *filename;\r
107 +    FILE *file;\r
108 +    size_t size;\r
109 +    char buf[4096];\r
110 +\r
111 +    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
112 +       fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
113 +       return 1;\r
114 +    }\r
115 +\r
116 +    config = notmuch_config_open (ctx, NULL, NULL);\r
117 +    if (config == NULL)\r
118 +       return 1;\r
119 +\r
120 +    query_string = query_string_from_args (ctx, argc, argv);\r
121 +    if (query_string == NULL) {\r
122 +       fprintf (stderr, "Out of memory\n");\r
123 +       return 1;\r
124 +    }\r
125 +\r
126 +    if (*query_string == '\0') {\r
127 +       fprintf (stderr, "Error: notmuch cat requires at least one search term.\n");\r
128 +       return 1;\r
129 +    }\r
130 +\r
131 +    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
132 +                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
133 +    if (notmuch == NULL)\r
134 +       return 1;\r
135 +\r
136 +    query = notmuch_query_create (notmuch, query_string);\r
137 +    if (query == NULL) {\r
138 +       fprintf (stderr, "Error: Out of memory\n");\r
139 +       return 1;\r
140 +    }\r
141 +\r
142 +    if (notmuch_query_count_messages (query) != 1) {\r
143 +       fprintf (stderr, "Error: search term did not match precisely one message.\n");\r
144 +       return 1;\r
145 +    }\r
146 +    \r
147 +    messages = notmuch_query_search_messages (query);\r
148 +    message = notmuch_messages_get (messages);\r
149 +    \r
150 +    if (message == NULL) {\r
151 +       fprintf (stderr, "Error: Cannot find matching message.\n");\r
152 +       return 1;\r
153 +    }\r
154 +\r
155 +    filename = notmuch_message_get_filename (message);\r
156 +    if (filename == NULL) {\r
157 +       fprintf (stderr, "Error: Cannot message filename.\n");\r
158 +       return 1;\r
159 +    }\r
160 +\r
161 +    file = fopen (filename, "r");\r
162 +    if (file == NULL) {\r
163 +       fprintf (stderr, "Error: Cannot open file %s: %s\n", filename, strerror (errno));\r
164 +       return 1;\r
165 +    }\r
166 +    \r
167 +    while (!feof (file)) {\r
168 +       size = fread (buf, 1, sizeof (buf), file);\r
169 +       fwrite (buf, size, 1, stdout);\r
170 +    }\r
171 +\r
172 +    fclose (file);\r
173 +    notmuch_query_destroy (query);\r
174 +    notmuch_database_close (notmuch);\r
175 +\r
176 +    return 0;\r
177 +}\r
178 +\r
179 +int\r
180  notmuch_part_command (void *ctx, unused (int argc), unused (char *argv[]))\r
181  {\r
182         notmuch_config_t *config;\r
183 diff --git a/notmuch.1 b/notmuch.1\r
184 index 3ec9c55..2ec4048 100644\r
185 --- a/notmuch.1\r
186 +++ b/notmuch.1\r
187 @@ -255,6 +255,10 @@ See the\r
188  section below for details of the supported syntax for <search-terms>.\r
189  .RE\r
190  .TP\r
191 +.BR cat  " <search-term>..."\r
192 +\r
193 +Output raw content of a single message matched by the search term.\r
194 +.TP\r
195  .BR count " <search-term>..."\r
196  \r
197  Count messages matching the search terms.\r
198 diff --git a/notmuch.c b/notmuch.c\r
199 index f6b8c13..e36486c 100644\r
200 --- a/notmuch.c\r
201 +++ b/notmuch.c\r
202 @@ -310,6 +310,10 @@ command_t commands[] = {\r
203        "\tcontain tags only from messages that match the search-term(s).\n"\r
204        "\n"\r
205        "\tIn both cases the list will be alphabetically sorted." },\r
206 +    { "cat", notmuch_cat_command,\r
207 +      "<search-terms>",\r
208 +      "Output raw content of a single message matched by the search term.",\r
209 +      "" },\r
210      { "part", notmuch_part_command,\r
211        "--part=<num> <search-terms>",\r
212        "Output a single MIME part of a message.",\r
213 diff --git a/test/cat b/test/cat\r
214 new file mode 100755\r
215 index 0000000..c6cefea\r
216 --- /dev/null\r
217 +++ b/test/cat\r
218 @@ -0,0 +1,38 @@\r
219 +#!/bin/bash\r
220 +\r
221 +test_description='notmuch cat'\r
222 +. ./test-lib.sh\r
223 +\r
224 +test_begin_subtest "Generate some messages"\r
225 +generate_message\r
226 +generate_message\r
227 +output=$(NOTMUCH_NEW)\r
228 +test_expect_equal "$output" "Added 2 new messages to the database."\r
229 +\r
230 +test_begin_subtest "Without arguments"\r
231 +output=$(notmuch cat 2>&1)\r
232 +test_expect_equal "$output" "Error: notmuch cat requires at least one search term."\r
233 +\r
234 +test_begin_subtest "Attempt to cat multiple messages"\r
235 +output=$(notmuch cat "*" 2>&1)\r
236 +test_expect_equal "$output" "Error: search term did not match precisely one message."\r
237 +\r
238 +test_begin_subtest "Cat a message"\r
239 +output=$(notmuch cat id:msg-001@notmuch-test-suite)\r
240 +test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
241 +To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
242 +Message-Id: <msg-001@notmuch-test-suite>\r
243 +Subject: Test message #1\r
244 +Date: Tue, 05 Jan 2001 15:43:57 -0000\r
245 +\r
246 +This is just a test message (#1)"\r
247 +\r
248 +test_begin_subtest "Cat another message"\r
249 +output=$(notmuch cat id:msg-002@notmuch-test-suite)\r
250 +test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
251 +To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
252 +Message-Id: <msg-002@notmuch-test-suite>\r
253 +Subject: Test message #2\r
254 +Date: Tue, 05 Jan 2001 15:43:57 -0000\r
255 +\r
256 +This is just a test message (#2)"\r
257 diff --git a/test/notmuch-test b/test/notmuch-test\r
258 index 13c5d80..0c33a47 100755\r
259 --- a/test/notmuch-test\r
260 +++ b/test/notmuch-test\r
261 @@ -8,7 +8,7 @@\r
262  \r
263  cd $(dirname "$0")\r
264  \r
265 -TESTS="basic new search json thread-naming reply dump-restore uuencode thread-order author-order from-guessing long-id encoding"\r
266 +TESTS="basic new search json thread-naming reply dump-restore uuencode thread-order author-order from-guessing long-id encoding cat"\r
267  \r
268  # Clean up any results from a previous run\r
269  rm -r test-results >/dev/null 2>/dev/null\r
270 -- \r
271 1.7.2.3\r
272 \r