[PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 6e / b389e0073c0afa5b4389573f48ca0a954a1461
1 Return-Path: <amdragon@mit.edu>\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 703E0418C2B\r
6         for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 20:57:37 -0800 (PST)\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 ne0xO-GaVN9o for <notmuch@notmuchmail.org>;\r
16         Mon, 30 Jan 2012 20:57:35 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
18         [18.7.68.36])\r
19         by olra.theworths.org (Postfix) with ESMTP id E94CA414B92\r
20         for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 20:57:18 -0800 (PST)\r
21 X-AuditID: 12074424-b7fae6d000000906-c8-4f2774ae5b89\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 0B.3A.02310.EA4772F4; Mon, 30 Jan 2012 23:57:18 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0V4vHXW004252; \r
27         Mon, 30 Jan 2012 23:57:18 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0V4vGYZ002133\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Mon, 30 Jan 2012 23:57:17 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Rs5lZ-0002nY-0A; Mon, 30 Jan 2012 23:56:25 -0500\r
37 Date: Mon, 30 Jan 2012 23:56:24 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Mark Walters <markwalters1009@gmail.com>\r
40 Subject: Re: [PATCH 5/7] cli: Make notmuch-show respect excludes.\r
41 Message-ID: <20120131045624.GB17991@mit.edu>\r
42 References: <8762fu4aqt.fsf@qmul.ac.uk>\r
43         <1327862394-14334-5-git-send-email-markwalters1009@gmail.com>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=us-ascii\r
46 Content-Disposition: inline\r
47 In-Reply-To: <1327862394-14334-5-git-send-email-markwalters1009@gmail.com>\r
48 User-Agent: Mutt/1.5.21 (2010-09-15)\r
49 X-Brightmail-Tracker:\r
50  H4sIAAAAAAAAA+NgFmpkleLIzCtJLcpLzFFi42IR4hTV1l1Xou5vcGi6osXquTwW12/OZHZg\r
51         8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mqaf38RWMEOj4tamHywNjL/kuxg5OSQETCTm\r
52         P5/GDmGLSVy4t56ti5GLQ0hgH6NE286tzBDOBkaJPc9OQTknmSQa106AcpYwStxbPJ+li5GD\r
53         g0VAVeL+JUWQUWwCGhLb9i9nBLFFBHQkbh9aALaCWUBa4tvvZiYQW1jAUeJo02KwGl6gmhPn\r
54         v4CNERJIl5g3zwAiLChxcuYTFohWLYkb/14ygZSAjFn+jwMkzCngJXH86k5WEFtUQEViyslt\r
55         bBMYhWYh6Z6FpHsWQvcCRuZVjLIpuVW6uYmZOcWpybrFyYl5ealFuuZ6uZkleqkppZsYQSHN\r
56         7qKyg7H5kNIhRgEORiUeXqFPav5CrIllxZW5hxglOZiURHnnFKj7C/El5adUZiQWZ8QXleak\r
57         Fh9ilOBgVhLhfbMaqJw3JbGyKrUoHyYlzcGiJM6rofXOD+jdxJLU7NTUgtQimKwMB4eSBO+b\r
58         YqChgkWp6akVaZk5JQhpJg5OkOE8QMPXgtTwFhck5hZnpkPkTzEqSonzHgNJCIAkMkrz4Hph\r
59         KecVozjQK8K8R0CqeIDpCq77FdBgJqDBzxlUQQaXJCKkpBoY2+/2fxF3WjnToP4h//9za/ov\r
60         zci6zDF34n6H3sCEYwvlt1e9yfYpVf07Q3zbOT3pzW4vDzwUtltkdOz+pAbXuCcdequ/J5W/\r
61         sJPcdOjinLUfprGk6VRxrLpkZrl5q9N3sa0tvXbb8+ZcWNir/359TYzDoS2fClbeXp10rEL6\r
62         wwkBvtNnpC6JViuxFGckGmoxFxUnAgDo5J8sFAMAAA==\r
63 Cc: notmuch@notmuchmail.org\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Tue, 31 Jan 2012 04:57:37 -0000\r
77 \r
78 Quoth Mark Walters on Jan 29 at  6:39 pm:\r
79 > This adds the excludes to notmuch-show.c. We do not exclude when only\r
80 > a single message (or part) is requested. notmuch-show will output the\r
81 > exclude information when either text or json format is requested. As\r
82 > this changes the output from notmuch-show it breaks many tests (in a\r
83 > trivial and expected fashion).\r
84 > ---\r
85 >  notmuch-show.c |   26 +++++++++++++++++++++-----\r
86 >  1 files changed, 21 insertions(+), 5 deletions(-)\r
87\r
88 > diff --git a/notmuch-show.c b/notmuch-show.c\r
89 > index dec799c..681827f 100644\r
90 > --- a/notmuch-show.c\r
91 > +++ b/notmuch-show.c\r
92 > @@ -193,10 +193,12 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)\r
93 >  static void\r
94 >  format_message_text (unused (const void *ctx), notmuch_message_t *message, int indent)\r
95 >  {\r
96 > -    printf ("id:%s depth:%d match:%d filename:%s\n",\r
97 > +    /* Could changing this could break users ? */\r
98 \r
99 I don't think anybody seriously tries to parse the text format, so I\r
100 wouldn't worry about breaking anything.\r
101 \r
102 > +    printf ("id:%s depth:%d match:%d excluded:%d filename:%s\n",\r
103 >           notmuch_message_get_message_id (message),\r
104 >           indent,\r
105 > -         notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH),\r
106 > +         notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? 1 : 0,\r
107 > +         notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0,\r
108 >           notmuch_message_get_filename (message));\r
109 >  }\r
110 >  \r
111 > @@ -212,9 +214,10 @@ format_message_json (const void *ctx, notmuch_message_t *message, unused (int in\r
112 >      date = notmuch_message_get_date (message);\r
113 >      relative_date = notmuch_time_relative_date (ctx, date);\r
114 >  \r
115 > -    printf ("\"id\": %s, \"match\": %s, \"filename\": %s, \"timestamp\": %ld, \"date_relative\": \"%s\", \"tags\": [",\r
116 > +    printf ("\"id\": %s, \"match\": %s, \"excluded\": %s, \"filename\": %s, \"timestamp\": %ld, \"date_relative\": \"%s\", \"tags\": [",\r
117 \r
118 I wonder if it would be better to switch to an array of flag names...\r
119 That obviously would break consumers, but it's worth thinking about in\r
120 the longer term.\r
121 \r
122 >           json_quote_str (ctx_quote, notmuch_message_get_message_id (message)),\r
123 >           notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? "true" : "false",\r
124 > +         notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? "true" : "false",\r
125 >           json_quote_str (ctx_quote, notmuch_message_get_filename (message)),\r
126 >           date, relative_date);\r
127 >  \r
128 > @@ -1059,9 +1062,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
129 >      char *opt;\r
130 >      const notmuch_show_format_t *format = &format_text;\r
131 >      notmuch_show_params_t params;\r
132 > +    const char **search_exclude_tags;\r
133 > +    size_t search_exclude_tags_length;\r
134 >      int mbox = 0;\r
135 >      int format_specified = 0;\r
136 >      int i;\r
137 > +    notmuch_bool_t do_not_exclude = FALSE;\r
138 > +    unsigned int j;\r
139 >  \r
140 >      params.entire_thread = 0;\r
141 >      params.raw = 0;\r
142 > @@ -1098,6 +1105,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
143 >           params.part = atoi(argv[i] + sizeof ("--part=") - 1);\r
144 >       } else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {\r
145 >           params.entire_thread = 1;\r
146 > +     } else if (STRNCMP_LITERAL (argv[i], "--do-not-exclude") == 0) {\r
147 > +         do_not_exclude = TRUE;\r
148 \r
149 "no-exclude" if you change the others.\r
150 \r
151 >       } else if ((STRNCMP_LITERAL (argv[i], "--verify") == 0) ||\r
152 >                  (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {\r
153 >           if (params.cryptoctx == NULL) {\r
154 > @@ -1105,7 +1114,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
155 >               /* TODO: GMimePasswordRequestFunc */\r
156 >               if (NULL == (params.cryptoctx = g_mime_gpg_context_new(NULL, "gpg")))\r
157 >  #else\r
158 > -             GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);\r
159 > +                 GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);\r
160 \r
161 Accidental reindent?\r
162 \r
163 >               if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg")))\r
164 >  #endif\r
165 >                   fprintf (stderr, "Failed to construct gpg context.\n");\r
166 > @@ -1167,10 +1176,17 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
167 >      if (params.raw && params.part < 0)\r
168 >       params.part = 0;\r
169 >  \r
170 > +    /* if a single message is requested we do not use search_excludes */\r
171 \r
172 Capital and period.\r
173 \r
174 >      if (params.part >= 0)\r
175 >       return do_show_single (ctx, query, format, &params);\r
176 >      else\r
177 > -     return do_show (ctx, query, format, &params);\r
178 > +     if (!do_not_exclude) {\r
179 > +         search_exclude_tags = notmuch_config_get_search_exclude_tags\r
180 > +             (config, &search_exclude_tags_length);\r
181 > +         for (j = 0; j < search_exclude_tags_length; j++)\r
182 > +             notmuch_query_add_tag_exclude (query, search_exclude_tags[j]);\r
183 > +         return do_show (ctx, query, format, &params);\r
184 > +     }\r
185 \r
186 I don't think this is the control flow you meant.  With\r
187 --do-not-exclude, there won't be any output.\r
188 \r
189 >  \r
190 >      notmuch_query_destroy (query);\r
191 >      notmuch_database_close (notmuch);\r
192 \r
193 Cool.  That was easy!\r