Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 50 / 35aef6a6ef4a19d4eaf09970de6465cb2f2a17
1 Return-Path: <jani@nikula.org>\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 37B90431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:04:23 -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 G-Ei8KC+YenN for <notmuch@notmuchmail.org>;\r
16         Sat, 15 Dec 2012 15:04:22 -0800 (PST)\r
17 Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
18         [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 245EC431FB6\r
21         for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:04:21 -0800 (PST)\r
22 Received: by mail-lb0-f181.google.com with SMTP id ge1so3673115lbb.26\r
23         for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:04:20 -0800 (PST)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=google.com; s=20120113;\r
26         h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
27         :message-id:mime-version:content-type:x-gm-message-state;\r
28         bh=dSE00KTRCDMypaLFoiYsbbD6j+ynuW0qktf2QZ2UKuI=;\r
29         b=Wuk+6xPntwbaFN10NUMFADmBpCjYiLLhWgqbUAvTjWgtFDfFnGI2fvrYOL34V1NJgL\r
30         oDApPh/4RrvGtTqF8bxvbVO4ZiJdXaRZpuffo5ZeH6C3A0TWKT71Rahf93JfM9ZAT0KE\r
31         9D3kTRNoZdu0Bk8GIWuH9NYQFgZgRJ+syKSMIaVxuR89bCcG9I8ligJ4ZtTOEoi1jNxb\r
32         qCFZ9miRnV4VYilsMwwUcamQSI+36+2ltcpyVEjlkHZOS0y6NRe4Y+Gf4H1T3qY5Ebr2\r
33         hbcx39dwkANXxX5gZGPnHV7ZW7xeXSRmCwcL6R8fDsi3zJzAMhn0BBE7h69QW1fdeORJ\r
34         +u9Q==\r
35 Received: by 10.112.11.33 with SMTP id n1mr4120732lbb.18.1355612660546;\r
36         Sat, 15 Dec 2012 15:04:20 -0800 (PST)\r
37 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
38         [80.223.81.27])\r
39         by mx.google.com with ESMTPS id er8sm3274601lbb.9.2012.12.15.15.04.18\r
40         (version=SSLv3 cipher=OTHER); Sat, 15 Dec 2012 15:04:19 -0800 (PST)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: david@tethera.net, notmuch@notmuchmail.org\r
43 Subject: Re: [Patch v7 06/14] notmuch-restore: move query handling for batch\r
44         restore to parser\r
45 In-Reply-To: <1355492062-7546-7-git-send-email-david@tethera.net>\r
46 References: <1355492062-7546-1-git-send-email-david@tethera.net>\r
47         <1355492062-7546-7-git-send-email-david@tethera.net>\r
48 User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1\r
49         (i686-pc-linux-gnu)\r
50 Date: Sun, 16 Dec 2012 01:04:17 +0200\r
51 Message-ID: <87vcc2q5n2.fsf@nikula.org>\r
52 MIME-Version: 1.0\r
53 Content-Type: text/plain; charset=us-ascii\r
54 X-Gm-Message-State:\r
55  ALoCoQlmkEtCMvMzHRLTDsHeT71XJjDsXmLmi5n7kAtEziatui3xTZQhIrKfr1X+A/9pnsghwaHL\r
56 Cc: David Bremner <bremner@debian.org>\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Sat, 15 Dec 2012 23:04:23 -0000\r
70 \r
71 On Fri, 14 Dec 2012, david@tethera.net wrote:\r
72 > From: David Bremner <bremner@debian.org>\r
73 >\r
74 > We are able to detect more errors by looking at the string before it\r
75 > is hex-decoded. We also need this to avoid the query quoting for more\r
76 > general queries (to be written) that will mess up raw message-ids.\r
77 > ---\r
78 >  notmuch-restore.c |   18 +-----------------\r
79 >  tag-util.c        |   26 ++++++++++++++++++++------\r
80 >  tag-util.h        |    5 ++++-\r
81 >  test/dump-restore |    5 ++---\r
82 >  4 files changed, 27 insertions(+), 27 deletions(-)\r
83 >\r
84 > diff --git a/notmuch-restore.c b/notmuch-restore.c\r
85 > index 40596a8..112f2f3 100644\r
86 > --- a/notmuch-restore.c\r
87 > +++ b/notmuch-restore.c\r
88 > @@ -208,24 +208,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
89 >       if (input_format == DUMP_FORMAT_SUP) {\r
90 >           ret = parse_sup_line (ctx, line, &query_string, tag_ops);\r
91 >       } else {\r
92 > -         ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS,\r
93 > +         ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS | TAG_FLAG_ID_ONLY,\r
94 >                                 &query_string, tag_ops);\r
95 \r
96 I realize that we've screwed up a bit here already in the restore\r
97 series. parse_sup_line() allocates query_string for each input line, but\r
98 doesn't free it during parsing. parse_tag_line() sets query_string to\r
99 point to the query string within line. And now it gets worse when\r
100 query_string is allocated vs. set to point to another buffer depending\r
101 on TAG_FLAG_ID_ONLY, so it's not an easy interface to use.\r
102 \r
103 > -\r
104 > -         if (ret == 0) {\r
105 > -             if (strncmp ("id:", query_string, 3) != 0) {\r
106 > -                 fprintf (stderr, "Warning: unsupported query: %s\n", query_string);\r
107 > -                 continue;\r
108 > -             }\r
109 > -             /* delete id: from front of string; tag_message\r
110 > -              * expects a raw message-id.\r
111 > -              *\r
112 > -              * XXX: Note that query string id:foo and bar will be\r
113 > -              * interpreted as a message id "foo and bar". This\r
114 > -              * should eventually be fixed to give a better error\r
115 > -              * message.\r
116 > -              */\r
117 > -             query_string = query_string + 3;\r
118 > -         }\r
119 \r
120 \r
121 \r
122 >       }\r
123 >  \r
124 >       if (ret > 0)\r
125 > diff --git a/tag-util.c b/tag-util.c\r
126 > index e1181f8..8fea76c 100644\r
127 > --- a/tag-util.c\r
128 > +++ b/tag-util.c\r
129 > @@ -201,14 +201,28 @@ parse_tag_line (void *ctx, char *line,\r
130 >      }\r
131 >  \r
132 >      /* tok now points to the query string */\r
133 > -    if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
134 > -     ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
135 > -                       "hex decoding of query %s failed", tok);\r
136 > -     goto DONE;\r
137 > +    if (flags & TAG_FLAG_ID_ONLY) {\r
138 > +     /* this is under the assumption that any whitespace in the\r
139 > +      * message-id must be hex-encoded. The check is probably not\r
140 > +      * perfect for exotic unicode whitespace; as fallback the\r
141 > +      * search for strange message-ids will fail */\r
142 > +     if ((strncmp ("id:", tok, 3) != 0) ||\r
143 \r
144 The current wording is, "Any characters in <tag> and <search-term> MAY\r
145 be hex encoded with %NN...", but the above no longer matches that, as\r
146 "id:" must not be encoded. In the interest of keeping the documentation\r
147 concise, I think you should move the above check after\r
148 hex_decode_inplace(), but keep the below check here. That should do it,\r
149 right?\r
150 \r
151 > +         (strcspn (tok, " \t") < strlen (tok))) {\r
152 > +         ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
153 > +                           "query '%s' is not 'id:<message-id>'", tok);\r
154 > +         goto DONE;\r
155 > +     }\r
156 > +     if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
157 > +         ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
158 > +                           "hex decoding of query %s failed", tok);\r
159 > +         goto DONE;\r
160 > +     }\r
161 > +     /* skip 'id:' */\r
162 > +     *query_string = tok + 3;\r
163 > +    } else {\r
164 > +     ret = quote_and_decode_query (ctx, tok, line_for_error, query_string);\r
165 >      }\r
166 \r
167 It's not pretty that query_string gets allocated or not depending on a\r
168 flag that doesn't seem to have anything to do with that. I don't have a\r
169 good suggestion now, though, and I'd like to keep the restore path like\r
170 it is, without allocation.\r
171 \r
172 >  \r
173 > -    *query_string = tok;\r
174 > -\r
175 >    DONE:\r
176 >      talloc_free (line_for_error);\r
177 >      return ret;\r
178 > diff --git a/tag-util.h b/tag-util.h\r
179 > index 2889736..7674051 100644\r
180 > --- a/tag-util.h\r
181 > +++ b/tag-util.h\r
182 > @@ -26,7 +26,10 @@ typedef enum {\r
183 >      /* Accept strange tags that might be user error;\r
184 >       * intended for use by notmuch-restore.\r
185 >       */\r
186 > -    TAG_FLAG_BE_GENEROUS = (1 << 3)\r
187 > +    TAG_FLAG_BE_GENEROUS = (1 << 3),\r
188 > +\r
189 > +    /* Query consists of a single id:$message-id */\r
190 > +    TAG_FLAG_ID_ONLY = (1 << 4)\r
191 >  \r
192 >  } tag_op_flag_t;\r
193 >  \r
194 > diff --git a/test/dump-restore b/test/dump-restore\r
195 > index 6a989b6..eb7933a 100755\r
196 > --- a/test/dump-restore\r
197 > +++ b/test/dump-restore\r
198 > @@ -199,19 +199,18 @@ a\r
199 >  # the next non-comment line should report an an empty tag error for\r
200 >  # batch tagging, but not for restore\r
201 >  + +e -- id:20091117232137.GA7669@griffis1.net\r
202 > -# highlight the sketchy id parsing; this should be last\r
203 >  +g -- id:foo and bar\r
204 >  EOF\r
205 >  \r
206 >  cat <<EOF > EXPECTED\r
207 > -Warning: unsupported query: a\r
208 > +Warning: query 'a' is not 'id:<message-id>' [a]\r
209 >  Warning: no query string [+0]\r
210 >  Warning: no query string [+a +b]\r
211 >  Warning: missing query string [+a +b ]\r
212 >  Warning: no query string after -- [+c +d --]\r
213 >  Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]\r
214 >  Warning: hex decoding of query id:%yy failed [+e +f id:%yy]\r
215 > -Warning: cannot apply tags to missing message: foo and bar\r
216 > +Warning: query 'id:foo and bar' is not 'id:<message-id>' [+g -- id:foo and bar]\r
217 >  EOF\r
218 >  \r
219 >  test_expect_equal_file EXPECTED OUTPUT\r
220 > -- \r
221 > 1.7.10.4\r
222 >\r
223 > _______________________________________________\r
224 > notmuch mailing list\r
225 > notmuch@notmuchmail.org\r
226 > http://notmuchmail.org/mailman/listinfo/notmuch\r