Re: correct way to search for only PDF attachments
[notmuch-archives.git] / 11 / 0c7a88166e21c28fba071cf7be0dd6eb06fa79
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 05988431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 09:54:24 -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: -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 gud32u2idbBc for <notmuch@notmuchmail.org>;\r
17         Sat, 15 Dec 2012 09:54:21 -0800 (PST)\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 BA7BE431FB6\r
22         for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 09:54:20 -0800 (PST)\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 1TjvwH-0005eT-00; Sat, 15 Dec 2012 17:54:19 +0000\r
27 Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)\r
28         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
29         (envelope-from <m.walters@qmul.ac.uk>)\r
30         id 1TjvwG-00006z-JJ; Sat, 15 Dec 2012 17:54:16 +0000\r
31 From: Mark Walters <markwalters1009@gmail.com>\r
32 To: david@tethera.net, notmuch@notmuchmail.org\r
33 Subject: Re: [Patch v7 06/14] notmuch-restore: move query handling for batch\r
34         restore to parser\r
35 In-Reply-To: <1355492062-7546-7-git-send-email-david@tethera.net>\r
36 References: <1355492062-7546-1-git-send-email-david@tethera.net>\r
37         <1355492062-7546-7-git-send-email-david@tethera.net>\r
38 User-Agent: Notmuch/0.14+155~g7edfdc3 (http://notmuchmail.org) Emacs/23.4.1\r
39         (x86_64-pc-linux-gnu)\r
40 Date: Sat, 15 Dec 2012 17:54:18 +0000\r
41 Message-ID: <87wqwj8alx.fsf@qmul.ac.uk>\r
42 MIME-Version: 1.0\r
43 Content-Type: text/plain; charset=us-ascii\r
44 X-Sender-Host-Address: 93.97.24.31\r
45 X-QM-SPAM-Info: Sender has good ham record.  :)\r
46 X-QM-Body-MD5: 8037058b0ecd4dac9122cab8000d295f (of first 20000 bytes)\r
47 X-SpamAssassin-Score: -1.8\r
48 X-SpamAssassin-SpamBar: -\r
49 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
50         determine if it is\r
51         spam. We require at least 5.0 points to mark a message as spam.\r
52         This message scored -1.8 points.\r
53         Summary of the scoring: \r
54         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
55         *      medium trust\r
56         *      [138.37.6.40 listed in list.dnswl.org]\r
57         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
58         provider *      (markwalters1009[at]gmail.com)\r
59         *  0.5 AWL AWL: From: address is in the auto white-list\r
60 X-QM-Scan-Virus: ClamAV says the message is clean\r
61 Cc: David Bremner <bremner@debian.org>\r
62 X-BeenThere: notmuch@notmuchmail.org\r
63 X-Mailman-Version: 2.1.13\r
64 Precedence: list\r
65 List-Id: "Use and development of the notmuch mail system."\r
66         <notmuch.notmuchmail.org>\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
70 List-Post: <mailto:notmuch@notmuchmail.org>\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
73         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
74 X-List-Received-Date: Sat, 15 Dec 2012 17:54:33 -0000\r
75 \r
76 On Fri, 14 Dec 2012, david@tethera.net wrote:\r
77 > From: David Bremner <bremner@debian.org>\r
78 >\r
79 > We are able to detect more errors by looking at the string before it\r
80 > is hex-decoded. We also need this to avoid the query quoting for more\r
81 > general queries (to be written) that will mess up raw message-ids.\r
82 > ---\r
83 >  notmuch-restore.c |   18 +-----------------\r
84 >  tag-util.c        |   26 ++++++++++++++++++++------\r
85 >  tag-util.h        |    5 ++++-\r
86 >  test/dump-restore |    5 ++---\r
87 >  4 files changed, 27 insertions(+), 27 deletions(-)\r
88 >\r
89 > diff --git a/notmuch-restore.c b/notmuch-restore.c\r
90 > index 40596a8..112f2f3 100644\r
91 > --- a/notmuch-restore.c\r
92 > +++ b/notmuch-restore.c\r
93 > @@ -208,24 +208,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
94 >       if (input_format == DUMP_FORMAT_SUP) {\r
95 >           ret = parse_sup_line (ctx, line, &query_string, tag_ops);\r
96 >       } else {\r
97 > -         ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS,\r
98 > +         ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS | TAG_FLAG_ID_ONLY,\r
99 >                                 &query_string, tag_ops);\r
100 > -\r
101 > -         if (ret == 0) {\r
102 > -             if (strncmp ("id:", query_string, 3) != 0) {\r
103 > -                 fprintf (stderr, "Warning: unsupported query: %s\n", query_string);\r
104 > -                 continue;\r
105 > -             }\r
106 > -             /* delete id: from front of string; tag_message\r
107 > -              * expects a raw message-id.\r
108 > -              *\r
109 > -              * XXX: Note that query string id:foo and bar will be\r
110 > -              * interpreted as a message id "foo and bar". This\r
111 > -              * should eventually be fixed to give a better error\r
112 > -              * message.\r
113 > -              */\r
114 > -             query_string = query_string + 3;\r
115 > -         }\r
116 >       }\r
117 >  \r
118 >       if (ret > 0)\r
119 > diff --git a/tag-util.c b/tag-util.c\r
120 > index e1181f8..8fea76c 100644\r
121 > --- a/tag-util.c\r
122 > +++ b/tag-util.c\r
123 > @@ -201,14 +201,28 @@ parse_tag_line (void *ctx, char *line,\r
124 >      }\r
125 >  \r
126 >      /* tok now points to the query string */\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 query %s failed", tok);\r
130 > -     goto DONE;\r
131 > +    if (flags & TAG_FLAG_ID_ONLY) {\r
132 > +     /* this is under the assumption that any whitespace in the\r
133 > +      * message-id must be hex-encoded. The check is probably not\r
134 > +      * perfect for exotic unicode whitespace; as fallback the\r
135 > +      * search for strange message-ids will fail */\r
136 > +     if ((strncmp ("id:", tok, 3) != 0) ||\r
137 > +         (strcspn (tok, " \t") < strlen (tok))) {\r
138 > +         ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
139 > +                           "query '%s' is not 'id:<message-id>'", tok);\r
140 > +         goto DONE;\r
141 > +     }\r
142 > +     if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
143 > +         ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
144 > +                           "hex decoding of query %s failed", tok);\r
145 > +         goto DONE;\r
146 > +     }\r
147 > +     /* skip 'id:' */\r
148 > +     *query_string = tok + 3;\r
149 \r
150 This looks like it doesn't double_quote the query_string in this (the\r
151 TAG_FLAG_ID_ONLY) case. Is that deliberate?\r
152 \r
153 Best wishes\r
154 \r
155 Mark\r
156 \r
157 > +    } else {\r
158 > +     ret = quote_and_decode_query (ctx, tok, line_for_error, query_string);\r
159 >      }\r
160 >  \r
161 > -    *query_string = tok;\r
162 > -\r
163 >    DONE:\r
164 >      talloc_free (line_for_error);\r
165 >      return ret;\r
166 > diff --git a/tag-util.h b/tag-util.h\r
167 > index 2889736..7674051 100644\r
168 > --- a/tag-util.h\r
169 > +++ b/tag-util.h\r
170 > @@ -26,7 +26,10 @@ typedef enum {\r
171 >      /* Accept strange tags that might be user error;\r
172 >       * intended for use by notmuch-restore.\r
173 >       */\r
174 > -    TAG_FLAG_BE_GENEROUS = (1 << 3)\r
175 > +    TAG_FLAG_BE_GENEROUS = (1 << 3),\r
176 > +\r
177 > +    /* Query consists of a single id:$message-id */\r
178 > +    TAG_FLAG_ID_ONLY = (1 << 4)\r
179 >  \r
180 >  } tag_op_flag_t;\r
181 >  \r
182 > diff --git a/test/dump-restore b/test/dump-restore\r
183 > index 6a989b6..eb7933a 100755\r
184 > --- a/test/dump-restore\r
185 > +++ b/test/dump-restore\r
186 > @@ -199,19 +199,18 @@ a\r
187 >  # the next non-comment line should report an an empty tag error for\r
188 >  # batch tagging, but not for restore\r
189 >  + +e -- id:20091117232137.GA7669@griffis1.net\r
190 > -# highlight the sketchy id parsing; this should be last\r
191 >  +g -- id:foo and bar\r
192 >  EOF\r
193 >  \r
194 >  cat <<EOF > EXPECTED\r
195 > -Warning: unsupported query: a\r
196 > +Warning: query 'a' is not 'id:<message-id>' [a]\r
197 >  Warning: no query string [+0]\r
198 >  Warning: no query string [+a +b]\r
199 >  Warning: missing query string [+a +b ]\r
200 >  Warning: no query string after -- [+c +d --]\r
201 >  Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]\r
202 >  Warning: hex decoding of query id:%yy failed [+e +f id:%yy]\r
203 > -Warning: cannot apply tags to missing message: foo and bar\r
204 > +Warning: query 'id:foo and bar' is not 'id:<message-id>' [+g -- id:foo and bar]\r
205 >  EOF\r
206 >  \r
207 >  test_expect_equal_file EXPECTED OUTPUT\r
208 > -- \r
209 > 1.7.10.4\r
210 >\r
211 > _______________________________________________\r
212 > notmuch mailing list\r
213 > notmuch@notmuchmail.org\r
214 > http://notmuchmail.org/mailman/listinfo/notmuch\r