Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / fd / 1e4f4b3e2af565bf361cd788aeaafd4373597f
1 Return-Path: <m.walters@qmul.ac.uk>\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 7614C431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 26 May 2012 02:25:52 -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.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id 9Zq92mnC86tJ for <notmuch@notmuchmail.org>;\r
17         Sat, 26 May 2012 02:25:50 -0700 (PDT)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 37828431FB6\r
22         for <notmuch@notmuchmail.org>; Sat, 26 May 2012 02:25:50 -0700 (PDT)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1SYDFo-0005Bz-PL; Sat, 26 May 2012 10:25:45 +0100\r
27 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
28         helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1SYDFo-00036t-Dp; Sat, 26 May 2012 10:25:44 +0100\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org\r
34 Subject: Re: [PATCH v4 2/4] cli: make --entire-thread=false work for\r
35         format=json.\r
36 In-Reply-To: <20120526121556.GA2328@hili.localdomain>\r
37 References: <1335258675-29439-1-git-send-email-markwalters1009@gmail.com>\r
38         <1335258675-29439-3-git-send-email-markwalters1009@gmail.com>\r
39         <20120526121556.GA2328@hili.localdomain>\r
40 User-Agent: Notmuch/0.13+38~g35cb1c9 (http://notmuchmail.org) Emacs/23.3.1\r
41         (x86_64-pc-linux-gnu)\r
42 Date: Sat, 26 May 2012 09:28:20 +0100\r
43 Message-ID: <87txz3cpnf.fsf@qmul.ac.uk>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=us-ascii\r
46 X-Sender-Host-Address: 94.192.233.223\r
47 X-QM-SPAM-Info: Sender has good ham record.  :)\r
48 X-QM-Body-MD5: 8e0b804157069eb4539fffdf6b43ef77 (of first 20000 bytes)\r
49 X-SpamAssassin-Score: -1.8\r
50 X-SpamAssassin-SpamBar: -\r
51 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
52         determine if it is\r
53         spam. We require at least 5.0 points to mark a message as spam.\r
54         This message scored -1.8 points.\r
55         Summary of the scoring: \r
56         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
57         *      medium trust\r
58         *      [138.37.6.40 listed in list.dnswl.org]\r
59         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
60         provider *      (markwalters1009[at]gmail.com)\r
61         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
62         *      domain\r
63         *  0.5 AWL AWL: From: address is in the auto white-list\r
64 X-QM-Scan-Virus: ClamAV says the message is clean\r
65 X-BeenThere: notmuch@notmuchmail.org\r
66 X-Mailman-Version: 2.1.13\r
67 Precedence: list\r
68 List-Id: "Use and development of the notmuch mail system."\r
69         <notmuch.notmuchmail.org>\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
73 List-Post: <mailto:notmuch@notmuchmail.org>\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
77 X-List-Received-Date: Sat, 26 May 2012 09:25:52 -0000\r
78 \r
79 \r
80 On Sat, 26 May 2012, Peter Wang <novalazy@gmail.com> wrote:\r
81 > On Tue, 24 Apr 2012 10:11:13 +0100, Mark Walters <markwalters1009@gmail.com> wrote:\r
82 >> The --entire-thread option in notmuch-show.c defaults to true when\r
83 >> format=json. Previously there was no way to turn this off. This patch\r
84 >> makes it respect --entire-thread=false.\r
85 >> \r
86 >> The one subtlety is that we initialise a notmuch_bool_t to -1 to\r
87 >> indicate that the option parsing has not set it. This allows the code\r
88 >> to distinguish between the option being omitted from the command line,\r
89 >> and the option being set to false on the command line.\r
90 >> ---\r
91 >>  notmuch-show.c |   16 ++++++++++++++--\r
92 >>  1 files changed, 14 insertions(+), 2 deletions(-)\r
93 >> \r
94 >> diff --git a/notmuch-show.c b/notmuch-show.c\r
95 >> index 0d21f1a..48551bb 100644\r
96 >> --- a/notmuch-show.c\r
97 >> +++ b/notmuch-show.c\r
98 >> @@ -996,7 +996,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
99 >>      char *query_string;\r
100 >>      int opt_index, ret;\r
101 >>      const notmuch_show_format_t *format = &format_text;\r
102 >> -    notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE };\r
103 >> +\r
104 >> +    /* We abuse the notmuch_bool_t variable params.entire-thread by\r
105 >> +     * setting it to -1 to denote that the command line parsing has\r
106 >> +     * not set it. We ensure it is set to TRUE or FALSE before passing\r
107 >> +     * it to any other function.*/\r
108 >> +    notmuch_show_params_t params = { .part = -1, .entire_thread = -1 };\r
109 >> +\r
110 >>      int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
111 >>      notmuch_bool_t verify = FALSE;\r
112 >>      int exclude = EXCLUDE_TRUE;\r
113 >\r
114 > Hi Mark,\r
115 >\r
116 > As an alternative to the abuse, could you just treat it as with exclude,\r
117 > using an enum with three values (TRUE|FALSE|DEFAULT)?\r
118 > Then set params.entire_thread afterwards.\r
119 \r
120 The reason I haven't done this is that the current command line parser\r
121 does not allow keyword options to take default values: in other words\r
122 --entire-thread without an "=<something>" would not be allowed.\r
123 \r
124 It is easy to change the keyword parsing code to allow this: I include a\r
125 first draft of such a patch below. This would allow the solution you\r
126 suggest and thus avoid the hack/abuse.  What do people think?\r
127 \r
128 Best wishes\r
129 \r
130 Mark\r
131 \r
132 \r
133 ---\r
134  command-line-arguments.c |   13 ++++++++++---\r
135  1 files changed, 10 insertions(+), 3 deletions(-)\r
136 \r
137 diff --git a/command-line-arguments.c b/command-line-arguments.c\r
138 index 76b185f..d40c7e6 100644\r
139 --- a/command-line-arguments.c\r
140 +++ b/command-line-arguments.c\r
141 @@ -11,10 +11,16 @@\r
142  */\r
143  \r
144  static notmuch_bool_t\r
145 -_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {\r
146 +_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {\r
147  \r
148      const notmuch_keyword_t *keywords = arg_desc->keywords;\r
149  \r
150 +    if (next == 0) {\r
151 +/* No keyword given so return first option as default */\r
152 +       *((int *)arg_desc->output_var) = keywords->value;\r
153 +       return TRUE;\r
154 +    }\r
155 +\r
156      while (keywords->name) {\r
157         if (strcmp (arg_str, keywords->name) == 0) {\r
158             if (arg_desc->output_var) {\r
159 @@ -99,7 +105,8 @@ parse_option (const char *arg,\r
160              */\r
161             if (next != '=' && next != ':' && next != 0) return FALSE;\r
162             if (next == 0) {\r
163 -               if (try->opt_type != NOTMUCH_OPT_BOOLEAN)\r
164 +               if (try->opt_type != NOTMUCH_OPT_BOOLEAN &&\r
165 +                   try->opt_type != NOTMUCH_OPT_KEYWORD)\r
166                     return FALSE;\r
167             } else {\r
168                 if (value[0] == 0) return FALSE;\r
169 @@ -110,7 +117,7 @@ parse_option (const char *arg,\r
170  \r
171             switch (try->opt_type) {\r
172             case NOTMUCH_OPT_KEYWORD:\r
173 -               return _process_keyword_arg (try, value);\r
174 +               return _process_keyword_arg (try, next, value);\r
175                 break;\r
176             case NOTMUCH_OPT_BOOLEAN:\r
177                 return _process_boolean_arg (try, next, value);\r
178 -- \r
179 1.7.9.1\r
180 \r