Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 3a / a6e863d0d7b618c6a999d4af94995a2b249ec8
1 Return-Path: <bremner@tethera.net>\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 CE3DD431FDE\r
6         for <notmuch@notmuchmail.org>; Fri, 21 Dec 2012 05:08:40 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 yFxlFkBB5X5D for <notmuch@notmuchmail.org>;\r
16         Fri, 21 Dec 2012 05:08:39 -0800 (PST)\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 2A004431FBC\r
21         for <notmuch@notmuchmail.org>; Fri, 21 Dec 2012 05:08:39 -0800 (PST)\r
22 Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net\r
23         ([156.34.82.78] helo=zancas.localnet)\r
24         by tesseract.cs.unb.ca with esmtpsa\r
25         (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
26         (envelope-from <bremner@tethera.net>)\r
27         id 1Tm2L6-0005dd-RX; Fri, 21 Dec 2012 09:08:37 -0400\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1Tm2L1-0005yh-9F; Fri, 21 Dec 2012 09:08:31 -0400\r
31 From: david@tethera.net\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [Patch v8 07/18] unhex_and_quote: new function to quote hex-decoded\r
34         queries\r
35 Date: Fri, 21 Dec 2012 09:08:16 -0400\r
36 Message-Id: <1356095307-22895-7-git-send-email-david@tethera.net>\r
37 X-Mailer: git-send-email 1.7.10.4\r
38 In-Reply-To: <1356095307-22895-1-git-send-email-david@tethera.net>\r
39 References: <1356095307-22895-1-git-send-email-david@tethera.net>\r
40 X-Spam_bar: -\r
41 Cc: David Bremner <bremner@debian.org>\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Fri, 21 Dec 2012 13:08:41 -0000\r
55 \r
56 From: David Bremner <bremner@debian.org>\r
57 \r
58 Space delimited tokens are hex decoded and then quoted according to\r
59 Xapian rules. Prefixes and '*' are passed through unquoted, as is\r
60 anything that hex-decoding would not change.\r
61 ---\r
62  tag-util.c |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
63  1 file changed, 81 insertions(+)\r
64 \r
65 diff --git a/tag-util.c b/tag-util.c\r
66 index f89669a..46aab4e 100644\r
67 --- a/tag-util.c\r
68 +++ b/tag-util.c\r
69 @@ -56,6 +56,87 @@ illegal_tag (const char *tag, notmuch_bool_t remove)\r
70      return NULL;\r
71  }\r
72  \r
73 +/* Input is a hex encoded string, presumed to be a query for Xapian.\r
74 + *\r
75 + * Space delimited tokens are decoded and quoted, with '*' and prefixes\r
76 + * of the form "foo:" passed through unquoted.\r
77 + */\r
78 +static tag_parse_status_t\r
79 +unhex_and_quote (void *ctx, char *encoded, const char *line_for_error,\r
80 +                char **query_string)\r
81 +{\r
82 +    char *tok = encoded;\r
83 +    size_t tok_len = 0;\r
84 +    char *buf = NULL;\r
85 +    size_t buf_len = 0;\r
86 +    tag_parse_status_t ret = TAG_PARSE_SUCCESS;\r
87 +\r
88 +    *query_string = talloc_strdup (ctx, "");\r
89 +\r
90 +    while ((tok = strtok_len (tok + tok_len, " ", &tok_len)) != NULL) {\r
91 +\r
92 +       size_t prefix_len;\r
93 +       char delim = *(tok + tok_len);\r
94 +\r
95 +       *(tok + tok_len++) = '\0';\r
96 +\r
97 +       prefix_len = hex_invariant (tok, tok_len);\r
98 +\r
99 +       if ((strcmp (tok, "*") == 0) || prefix_len >= tok_len - 1) {\r
100 +\r
101 +           /* pass some things through without quoting or decoding.\r
102 +            * Note for '*' this is mandatory.\r
103 +            */\r
104 +\r
105 +           if (! (*query_string = talloc_asprintf_append_buffer (\r
106 +                      *query_string, "%s%c", tok, delim))) {\r
107 +\r
108 +               ret = line_error (TAG_PARSE_OUT_OF_MEMORY,\r
109 +                                 line_for_error, "aborting");\r
110 +               goto DONE;\r
111 +           }\r
112 +\r
113 +       } else {\r
114 +           /* potential prefix: one for ':', then something after */\r
115 +           if ((tok_len - prefix_len > 2) && *(tok + prefix_len) == ':') {\r
116 +               if (! (*query_string = talloc_strndup_append (*query_string,\r
117 +                                                             tok,\r
118 +                                                             prefix_len + 1))) {\r
119 +                   ret = line_error (TAG_PARSE_OUT_OF_MEMORY,\r
120 +                                     line_for_error, "aborting");\r
121 +                   goto DONE;\r
122 +               }\r
123 +               tok += prefix_len + 1;\r
124 +               tok_len -= prefix_len + 1;\r
125 +           }\r
126 +\r
127 +           if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
128 +               ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
129 +                                 "hex decoding of token '%s' failed", tok);\r
130 +               goto DONE;\r
131 +           }\r
132 +\r
133 +           if (double_quote_str (ctx, tok, &buf, &buf_len)) {\r
134 +               ret = line_error (TAG_PARSE_OUT_OF_MEMORY,\r
135 +                                 line_for_error, "aborting");\r
136 +               goto DONE;\r
137 +           }\r
138 +\r
139 +           if (! (*query_string = talloc_asprintf_append_buffer (\r
140 +                      *query_string, "%s%c", buf, delim))) {\r
141 +               ret = line_error (TAG_PARSE_OUT_OF_MEMORY,\r
142 +                                 line_for_error, "aborting");\r
143 +               goto DONE;\r
144 +           }\r
145 +       }\r
146 +    }\r
147 +\r
148 +  DONE:\r
149 +    if (ret != TAG_PARSE_SUCCESS && *query_string)\r
150 +       talloc_free (*query_string);\r
151 +    return ret;\r
152 +}\r
153 +\r
154  tag_parse_status_t\r
155  parse_tag_line (void *ctx, char *line,\r
156                 tag_op_flag_t flags,\r
157 -- \r
158 1.7.10.4\r
159 \r