Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 53 / ba526a700956a8f38484ddcae3ee0934fc9b80
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 906A5431FDB\r
6         for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:39:44 -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: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] 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 tM0jdoT-sQLh for <notmuch@notmuchmail.org>;\r
16         Mon, 22 Sep 2014 02:39:39 -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 93EBB431FC2\r
19         for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:39:28 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.7])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 65B485CCE62;\r
22         Mon, 22 Sep 2014 11:39:27 +0200 (CEST)\r
23 X-Virus-Scanned: IMAP STYX AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
26         port 10044)\r
27         with ESMTP id OVZdS9Yu6svX; Mon, 22 Sep 2014 11:39:22 +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 880765CCE64;\r
30         Mon, 22 Sep 2014 11:39:22 +0200 (CEST)\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
32         (envelope-from <sojkam1@fel.cvut.cz>)\r
33         id 1XW05U-0001wG-MI; Mon, 22 Sep 2014 11:39:16 +0200\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH 2/5] cli: Extend the search command for --output=addresses and\r
37         similar\r
38 Date: Mon, 22 Sep 2014 11:37:56 +0200\r
39 Message-Id: <1411378679-7307-3-git-send-email-sojkam1@fel.cvut.cz>\r
40 X-Mailer: git-send-email 2.1.0\r
41 In-Reply-To: <1411378679-7307-1-git-send-email-sojkam1@fel.cvut.cz>\r
42 References: <1411378679-7307-1-git-send-email-sojkam1@fel.cvut.cz>\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Mon, 22 Sep 2014 09:39:44 -0000\r
56 \r
57 The new outputs allow printing senders, recipients or both of matching\r
58 messages.\r
59 \r
60 This code based on a patch from Jani Nikula.\r
61 ---\r
62  completion/notmuch-completion.bash |   2 +-\r
63  completion/notmuch-completion.zsh  |   3 +-\r
64  doc/man1/notmuch-search.rst        |  22 +++++++-\r
65  notmuch-search.c                   | 100 ++++++++++++++++++++++++++++++++++---\r
66  4 files changed, 118 insertions(+), 9 deletions(-)\r
67 \r
68 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash\r
69 index 0571dc9..c37ddf5 100644\r
70 --- a/completion/notmuch-completion.bash\r
71 +++ b/completion/notmuch-completion.bash\r
72 @@ -294,7 +294,7 @@ _notmuch_search()\r
73             return\r
74             ;;\r
75         --output)\r
76 -           COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )\r
77 +           COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients addresses" -- "${cur}" ) )\r
78             return\r
79             ;;\r
80         --sort)\r
81 diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh\r
82 index 67a9aba..bff8fd5 100644\r
83 --- a/completion/notmuch-completion.zsh\r
84 +++ b/completion/notmuch-completion.zsh\r
85 @@ -52,7 +52,8 @@ _notmuch_search()\r
86    _arguments -s : \\r
87      '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \\r
88      '--first=[omit the first x threads from the search results]:number of threads to omit: ' \\r
89 -    '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))'\r
90 +    '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \\r
91 +    '--output=[select what to output]:output:((summary threads messages files tags sender recipients addresses))'\r
92  }\r
93  \r
94  _notmuch()\r
95 diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst\r
96 index 90160f2..6094906 100644\r
97 --- a/doc/man1/notmuch-search.rst\r
98 +++ b/doc/man1/notmuch-search.rst\r
99 @@ -35,7 +35,7 @@ Supported options for **search** include\r
100          intended for programs that invoke **notmuch(1)** internally. If\r
101          omitted, the latest supported version will be used.\r
102  \r
103 -    ``--output=(summary|threads|messages|files|tags)``\r
104 +    ``--output=(summary|threads|messages|files|tags|sender|recipients|addresses)``\r
105  \r
106          **summary**\r
107              Output a summary of each thread with any message matching\r
108 @@ -78,6 +78,26 @@ Supported options for **search** include\r
109              by null characters (--format=text0), as a JSON array\r
110              (--format=json), or as an S-Expression list (--format=sexp).\r
111  \r
112 +       **sender**\r
113 +            Output all addresses from the *From* header that appear on\r
114 +            any message matching the search terms, either one per line\r
115 +            (--format=text), separated by null characters\r
116 +            (--format=text0), as a JSON array (--format=json), or as\r
117 +            an S-Expression list (--format=sexp).\r
118 +\r
119 +           Note: Searching for **sender** should much be faster than\r
120 +           searching for **recipients** or **addresses**, because\r
121 +           sender addresses are cached directly in the database\r
122 +           whereas other addresses need to be fetched from the\r
123 +           message file by parsing it.\r
124 +\r
125 +       **recipients**\r
126 +            Like **sender** but for addresses from *To*, *Cc* and\r
127 +           *Bcc* headers.\r
128 +\r
129 +       **addresses**\r
130 +           Like **sender** and **recipients** together.\r
131 +\r
132      ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)\r
133          This option can be used to present results in either\r
134          chronological order (**oldest-first**) or reverse chronological\r
135 diff --git a/notmuch-search.c b/notmuch-search.c\r
136 index 5ac2a26..0614f10 100644\r
137 --- a/notmuch-search.c\r
138 +++ b/notmuch-search.c\r
139 @@ -23,11 +23,14 @@\r
140  #include "string-util.h"\r
141  \r
142  typedef enum {\r
143 -    OUTPUT_SUMMARY,\r
144 -    OUTPUT_THREADS,\r
145 -    OUTPUT_MESSAGES,\r
146 -    OUTPUT_FILES,\r
147 -    OUTPUT_TAGS\r
148 +    OUTPUT_SUMMARY     = 1 << 0,\r
149 +    OUTPUT_THREADS     = 1 << 1,\r
150 +    OUTPUT_MESSAGES    = 1 << 2,\r
151 +    OUTPUT_FILES       = 1 << 3,\r
152 +    OUTPUT_TAGS                = 1 << 4,\r
153 +    OUTPUT_SENDER      = 1 << 5,\r
154 +    OUTPUT_RECIPIENTS  = 1 << 6,\r
155 +    OUTPUT_ADDRESSES   = OUTPUT_SENDER | OUTPUT_RECIPIENTS,\r
156  } output_t;\r
157  \r
158  typedef struct {\r
159 @@ -220,6 +223,67 @@ do_search_threads (search_options_t *o)\r
160      return 0;\r
161  }\r
162  \r
163 +static void\r
164 +print_address_list (const search_options_t *o, InternetAddressList *list)\r
165 +{\r
166 +    InternetAddress *address;\r
167 +    int i;\r
168 +\r
169 +    for (i = 0; i < internet_address_list_length (list); i++) {\r
170 +       address = internet_address_list_get_address (list, i);\r
171 +       if (INTERNET_ADDRESS_IS_GROUP (address)) {\r
172 +           InternetAddressGroup *group;\r
173 +           InternetAddressList *group_list;\r
174 +\r
175 +           group = INTERNET_ADDRESS_GROUP (address);\r
176 +           group_list = internet_address_group_get_members (group);\r
177 +           if (group_list == NULL)\r
178 +               continue;\r
179 +\r
180 +           print_address_list (o, group_list);\r
181 +       } else {\r
182 +           InternetAddressMailbox *mailbox;\r
183 +           const char *name;\r
184 +           const char *addr;\r
185 +           char *full_address;\r
186 +\r
187 +           mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
188 +\r
189 +           name = internet_address_get_name (address);\r
190 +           addr = internet_address_mailbox_get_addr (mailbox);\r
191 +\r
192 +           if (name && *name)\r
193 +               full_address = talloc_asprintf (o->format, "%s <%s>", name, addr);\r
194 +           else\r
195 +               full_address = talloc_strdup (o->format, addr);\r
196 +\r
197 +           if (!full_address) {\r
198 +               fprintf (stderr, "Error: out of memory\n");\r
199 +               break;\r
200 +           }\r
201 +           o->format->string (o->format, full_address);\r
202 +           o->format->separator (o->format);\r
203 +\r
204 +           talloc_free (full_address);\r
205 +       }\r
206 +    }\r
207 +}\r
208 +\r
209 +static void\r
210 +print_address_string (const search_options_t *o, const char *recipients)\r
211 +{\r
212 +    InternetAddressList *list;\r
213 +\r
214 +    if (recipients == NULL)\r
215 +       return;\r
216 +\r
217 +    list = internet_address_list_parse_string (recipients);\r
218 +    if (list == NULL)\r
219 +       return;\r
220 +\r
221 +    print_address_list (o, list);\r
222 +}\r
223 +\r
224  static int\r
225  do_search_messages (search_options_t *o)\r
226  {\r
227 @@ -266,11 +330,29 @@ do_search_messages (search_options_t *o)\r
228             \r
229             notmuch_filenames_destroy( filenames );\r
230  \r
231 -       } else { /* output == OUTPUT_MESSAGES */\r
232 +       } else if (o->output == OUTPUT_MESSAGES) {\r
233             format->set_prefix (format, "id");\r
234             format->string (format,\r
235                             notmuch_message_get_message_id (message));\r
236             format->separator (format);\r
237 +       } else {\r
238 +           if (o->output & OUTPUT_SENDER) {\r
239 +               const char *addrs;\r
240 +\r
241 +               addrs = notmuch_message_get_header (message, "from");\r
242 +               print_address_string (o, addrs);\r
243 +           }\r
244 +\r
245 +           if (o->output & OUTPUT_RECIPIENTS) {\r
246 +               const char *hdrs[] = { "to", "cc", "bcc" };\r
247 +               const char *addrs;\r
248 +               size_t j;\r
249 +\r
250 +               for (j = 0; j < ARRAY_SIZE (hdrs); j++) {\r
251 +                   addrs = notmuch_message_get_header (message, hdrs[j]);\r
252 +                   print_address_string (o, addrs);\r
253 +               }\r
254 +           }\r
255         }\r
256  \r
257         notmuch_message_destroy (message);\r
258 @@ -370,6 +452,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
259           (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
260                                   { "threads", OUTPUT_THREADS },\r
261                                   { "messages", OUTPUT_MESSAGES },\r
262 +                                 { "sender", OUTPUT_SENDER },\r
263 +                                 { "recipients", OUTPUT_RECIPIENTS },\r
264 +                                 { "addresses", OUTPUT_ADDRESSES },\r
265                                   { "files", OUTPUT_FILES },\r
266                                   { "tags", OUTPUT_TAGS },\r
267                                   { 0, 0 } } },\r
268 @@ -461,6 +546,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
269         ret = do_search_threads (&o);\r
270         break;\r
271      case OUTPUT_MESSAGES:\r
272 +    case OUTPUT_SENDER:\r
273 +    case OUTPUT_RECIPIENTS:\r
274 +    case OUTPUT_ADDRESSES:\r
275      case OUTPUT_FILES:\r
276         ret = do_search_messages (&o);\r
277         break;\r
278 -- \r
279 2.1.0\r
280 \r