Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / e2 / c9fe3ea8340e8e1a2380a49238668f417b43e5
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 A2B0A431FDE\r
6         for <notmuch@notmuchmail.org>; Fri, 21 Dec 2012 05:08:41 -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 DqgjqU9D1Ljw for <notmuch@notmuchmail.org>;\r
16         Fri, 21 Dec 2012 05:08:40 -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 2E585431FBD\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-0005de-VT; 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-0005ym-GU; 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 08/18] notmuch-restore: move query handling for batch\r
34         restore to parser\r
35 Date: Fri, 21 Dec 2012 09:08:17 -0400\r
36 Message-Id: <1356095307-22895-8-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:42 -0000\r
55 \r
56 From: David Bremner <bremner@debian.org>\r
57 \r
58 We are able to detect more errors by looking at the string before it\r
59 is hex-decoded. We also need this to avoid the query quoting for more\r
60 general queries (to be written) that will mess up raw message-ids.\r
61 ---\r
62  notmuch-restore.c |   18 +-----------------\r
63  tag-util.c        |   26 ++++++++++++++++++++------\r
64  tag-util.h        |    7 ++++++-\r
65  test/dump-restore |    5 ++---\r
66  4 files changed, 29 insertions(+), 27 deletions(-)\r
67 \r
68 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
69 index 40596a8..1b66e76 100644\r
70 --- a/notmuch-restore.c\r
71 +++ b/notmuch-restore.c\r
72 @@ -208,24 +208,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
73         if (input_format == DUMP_FORMAT_SUP) {\r
74             ret = parse_sup_line (ctx, line, &query_string, tag_ops);\r
75         } else {\r
76 -           ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS,\r
77 +           ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS | TAG_FLAG_ID_DIRECT,\r
78                                   &query_string, tag_ops);\r
79 -\r
80 -           if (ret == 0) {\r
81 -               if (strncmp ("id:", query_string, 3) != 0) {\r
82 -                   fprintf (stderr, "Warning: unsupported query: %s\n", query_string);\r
83 -                   continue;\r
84 -               }\r
85 -               /* delete id: from front of string; tag_message\r
86 -                * expects a raw message-id.\r
87 -                *\r
88 -                * XXX: Note that query string id:foo and bar will be\r
89 -                * interpreted as a message id "foo and bar". This\r
90 -                * should eventually be fixed to give a better error\r
91 -                * message.\r
92 -                */\r
93 -               query_string = query_string + 3;\r
94 -           }\r
95         }\r
96  \r
97         if (ret > 0)\r
98 diff --git a/tag-util.c b/tag-util.c\r
99 index 46aab4e..b0a846b 100644\r
100 --- a/tag-util.c\r
101 +++ b/tag-util.c\r
102 @@ -232,14 +232,28 @@ parse_tag_line (void *ctx, char *line,\r
103      }\r
104  \r
105      /* tok now points to the query string */\r
106 -    if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
107 -       ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
108 -                         "hex decoding of query %s failed", tok);\r
109 -       goto DONE;\r
110 +    if (flags & TAG_FLAG_ID_DIRECT) {\r
111 +       /* this is under the assumption that any whitespace in the\r
112 +        * message-id must be hex-encoded. The check is probably not\r
113 +        * perfect for exotic unicode whitespace; as fallback the\r
114 +        * search for strange message-ids will fail */\r
115 +       if ((strncmp ("id:", tok, 3) != 0) ||\r
116 +           (strcspn (tok, " \t") < strlen (tok))) {\r
117 +           ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
118 +                             "query '%s' is not 'id:<message-id>'", tok);\r
119 +           goto DONE;\r
120 +       }\r
121 +       if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
122 +           ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
123 +                             "hex decoding of query %s failed", tok);\r
124 +           goto DONE;\r
125 +       }\r
126 +       /* skip 'id:' */\r
127 +       *query_string = tok + 3;\r
128 +    } else {\r
129 +       ret = unhex_and_quote (ctx, tok, line_for_error, query_string);\r
130      }\r
131  \r
132 -    *query_string = tok;\r
133 -\r
134    DONE:\r
135      talloc_free (line_for_error);\r
136      return ret;\r
137 diff --git a/tag-util.h b/tag-util.h\r
138 index 2889736..eec00cf 100644\r
139 --- a/tag-util.h\r
140 +++ b/tag-util.h\r
141 @@ -26,7 +26,12 @@ typedef enum {\r
142      /* Accept strange tags that might be user error;\r
143       * intended for use by notmuch-restore.\r
144       */\r
145 -    TAG_FLAG_BE_GENEROUS = (1 << 3)\r
146 +    TAG_FLAG_BE_GENEROUS = (1 << 3),\r
147 +\r
148 +    /* Directly look up messages by hex-decoded message-id, rather\r
149 +     * than parsing a general query. The query MUST be of the form\r
150 +     * id:$message-id. */\r
151 +    TAG_FLAG_ID_DIRECT = (1 << 4)\r
152  \r
153  } tag_op_flag_t;\r
154  \r
155 diff --git a/test/dump-restore b/test/dump-restore\r
156 index 6a989b6..eb7933a 100755\r
157 --- a/test/dump-restore\r
158 +++ b/test/dump-restore\r
159 @@ -199,19 +199,18 @@ a\r
160  # the next non-comment line should report an an empty tag error for\r
161  # batch tagging, but not for restore\r
162  + +e -- id:20091117232137.GA7669@griffis1.net\r
163 -# highlight the sketchy id parsing; this should be last\r
164  +g -- id:foo and bar\r
165  EOF\r
166  \r
167  cat <<EOF > EXPECTED\r
168 -Warning: unsupported query: a\r
169 +Warning: query 'a' is not 'id:<message-id>' [a]\r
170  Warning: no query string [+0]\r
171  Warning: no query string [+a +b]\r
172  Warning: missing query string [+a +b ]\r
173  Warning: no query string after -- [+c +d --]\r
174  Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]\r
175  Warning: hex decoding of query id:%yy failed [+e +f id:%yy]\r
176 -Warning: cannot apply tags to missing message: foo and bar\r
177 +Warning: query 'id:foo and bar' is not 'id:<message-id>' [+g -- id:foo and bar]\r
178  EOF\r
179  \r
180  test_expect_equal_file EXPECTED OUTPUT\r
181 -- \r
182 1.7.10.4\r
183 \r