From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A2B0A431FDE for ; Fri, 21 Dec 2012 05:08:41 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DqgjqU9D1Ljw for ; Fri, 21 Dec 2012 05:08:40 -0800 (PST) Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2E585431FBD for ; Fri, 21 Dec 2012 05:08:39 -0800 (PST) Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net ([156.34.82.78] helo=zancas.localnet) by tesseract.cs.unb.ca with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Tm2L6-0005de-VT; Fri, 21 Dec 2012 09:08:37 -0400 Received: from bremner by zancas.localnet with local (Exim 4.80) (envelope-from ) id 1Tm2L1-0005ym-GU; Fri, 21 Dec 2012 09:08:31 -0400 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [Patch v8 08/18] notmuch-restore: move query handling for batch restore to parser Date: Fri, 21 Dec 2012 09:08:17 -0400 Message-Id: <1356095307-22895-8-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1356095307-22895-1-git-send-email-david@tethera.net> References: <1356095307-22895-1-git-send-email-david@tethera.net> X-Spam_bar: - Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Dec 2012 13:08:42 -0000 From: David Bremner We are able to detect more errors by looking at the string before it is hex-decoded. We also need this to avoid the query quoting for more general queries (to be written) that will mess up raw message-ids. --- notmuch-restore.c | 18 +----------------- tag-util.c | 26 ++++++++++++++++++++------ tag-util.h | 7 ++++++- test/dump-restore | 5 ++--- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/notmuch-restore.c b/notmuch-restore.c index 40596a8..1b66e76 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -208,24 +208,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) if (input_format == DUMP_FORMAT_SUP) { ret = parse_sup_line (ctx, line, &query_string, tag_ops); } else { - ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS, + ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS | TAG_FLAG_ID_DIRECT, &query_string, tag_ops); - - if (ret == 0) { - if (strncmp ("id:", query_string, 3) != 0) { - fprintf (stderr, "Warning: unsupported query: %s\n", query_string); - continue; - } - /* delete id: from front of string; tag_message - * expects a raw message-id. - * - * XXX: Note that query string id:foo and bar will be - * interpreted as a message id "foo and bar". This - * should eventually be fixed to give a better error - * message. - */ - query_string = query_string + 3; - } } if (ret > 0) diff --git a/tag-util.c b/tag-util.c index 46aab4e..b0a846b 100644 --- a/tag-util.c +++ b/tag-util.c @@ -232,14 +232,28 @@ parse_tag_line (void *ctx, char *line, } /* tok now points to the query string */ - if (hex_decode_inplace (tok) != HEX_SUCCESS) { - ret = line_error (TAG_PARSE_INVALID, line_for_error, - "hex decoding of query %s failed", tok); - goto DONE; + if (flags & TAG_FLAG_ID_DIRECT) { + /* this is under the assumption that any whitespace in the + * message-id must be hex-encoded. The check is probably not + * perfect for exotic unicode whitespace; as fallback the + * search for strange message-ids will fail */ + if ((strncmp ("id:", tok, 3) != 0) || + (strcspn (tok, " \t") < strlen (tok))) { + ret = line_error (TAG_PARSE_INVALID, line_for_error, + "query '%s' is not 'id:'", tok); + goto DONE; + } + if (hex_decode_inplace (tok) != HEX_SUCCESS) { + ret = line_error (TAG_PARSE_INVALID, line_for_error, + "hex decoding of query %s failed", tok); + goto DONE; + } + /* skip 'id:' */ + *query_string = tok + 3; + } else { + ret = unhex_and_quote (ctx, tok, line_for_error, query_string); } - *query_string = tok; - DONE: talloc_free (line_for_error); return ret; diff --git a/tag-util.h b/tag-util.h index 2889736..eec00cf 100644 --- a/tag-util.h +++ b/tag-util.h @@ -26,7 +26,12 @@ typedef enum { /* Accept strange tags that might be user error; * intended for use by notmuch-restore. */ - TAG_FLAG_BE_GENEROUS = (1 << 3) + TAG_FLAG_BE_GENEROUS = (1 << 3), + + /* Directly look up messages by hex-decoded message-id, rather + * than parsing a general query. The query MUST be of the form + * id:$message-id. */ + TAG_FLAG_ID_DIRECT = (1 << 4) } tag_op_flag_t; diff --git a/test/dump-restore b/test/dump-restore index 6a989b6..eb7933a 100755 --- a/test/dump-restore +++ b/test/dump-restore @@ -199,19 +199,18 @@ a # the next non-comment line should report an an empty tag error for # batch tagging, but not for restore + +e -- id:20091117232137.GA7669@griffis1.net -# highlight the sketchy id parsing; this should be last +g -- id:foo and bar EOF cat < EXPECTED -Warning: unsupported query: a +Warning: query 'a' is not 'id:' [a] Warning: no query string [+0] Warning: no query string [+a +b] Warning: missing query string [+a +b ] Warning: no query string after -- [+c +d --] Warning: hex decoding of tag %zz failed [+%zz -- id:whatever] Warning: hex decoding of query id:%yy failed [+e +f id:%yy] -Warning: cannot apply tags to missing message: foo and bar +Warning: query 'id:foo and bar' is not 'id:' [+g -- id:foo and bar] EOF test_expect_equal_file EXPECTED OUTPUT -- 1.7.10.4