From 1a0ced47bc0b87d30eab6096dfe9496b5de4971d Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sun, 16 Dec 2012 01:04:17 +0200 Subject: [PATCH] Re: [Patch v7 06/14] notmuch-restore: move query handling for batch restore to parser --- 50/35aef6a6ef4a19d4eaf09970de6465cb2f2a17 | 226 ++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 50/35aef6a6ef4a19d4eaf09970de6465cb2f2a17 diff --git a/50/35aef6a6ef4a19d4eaf09970de6465cb2f2a17 b/50/35aef6a6ef4a19d4eaf09970de6465cb2f2a17 new file mode 100644 index 000000000..f2e3e716a --- /dev/null +++ b/50/35aef6a6ef4a19d4eaf09970de6465cb2f2a17 @@ -0,0 +1,226 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 37B90431FBC + for ; Sat, 15 Dec 2012 15:04:23 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 G-Ei8KC+YenN for ; + Sat, 15 Dec 2012 15:04:22 -0800 (PST) +Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com + [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 245EC431FB6 + for ; Sat, 15 Dec 2012 15:04:21 -0800 (PST) +Received: by mail-lb0-f181.google.com with SMTP id ge1so3673115lbb.26 + for ; Sat, 15 Dec 2012 15:04:20 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=from:to:cc:subject:in-reply-to:references:user-agent:date + :message-id:mime-version:content-type:x-gm-message-state; + bh=dSE00KTRCDMypaLFoiYsbbD6j+ynuW0qktf2QZ2UKuI=; + b=Wuk+6xPntwbaFN10NUMFADmBpCjYiLLhWgqbUAvTjWgtFDfFnGI2fvrYOL34V1NJgL + oDApPh/4RrvGtTqF8bxvbVO4ZiJdXaRZpuffo5ZeH6C3A0TWKT71Rahf93JfM9ZAT0KE + 9D3kTRNoZdu0Bk8GIWuH9NYQFgZgRJ+syKSMIaVxuR89bCcG9I8ligJ4ZtTOEoi1jNxb + qCFZ9miRnV4VYilsMwwUcamQSI+36+2ltcpyVEjlkHZOS0y6NRe4Y+Gf4H1T3qY5Ebr2 + hbcx39dwkANXxX5gZGPnHV7ZW7xeXSRmCwcL6R8fDsi3zJzAMhn0BBE7h69QW1fdeORJ + +u9Q== +Received: by 10.112.11.33 with SMTP id n1mr4120732lbb.18.1355612660546; + Sat, 15 Dec 2012 15:04:20 -0800 (PST) +Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. + [80.223.81.27]) + by mx.google.com with ESMTPS id er8sm3274601lbb.9.2012.12.15.15.04.18 + (version=SSLv3 cipher=OTHER); Sat, 15 Dec 2012 15:04:19 -0800 (PST) +From: Jani Nikula +To: david@tethera.net, notmuch@notmuchmail.org +Subject: Re: [Patch v7 06/14] notmuch-restore: move query handling for batch + restore to parser +In-Reply-To: <1355492062-7546-7-git-send-email-david@tethera.net> +References: <1355492062-7546-1-git-send-email-david@tethera.net> + <1355492062-7546-7-git-send-email-david@tethera.net> +User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1 + (i686-pc-linux-gnu) +Date: Sun, 16 Dec 2012 01:04:17 +0200 +Message-ID: <87vcc2q5n2.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Gm-Message-State: + ALoCoQlmkEtCMvMzHRLTDsHeT71XJjDsXmLmi5n7kAtEziatui3xTZQhIrKfr1X+A/9pnsghwaHL +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: Sat, 15 Dec 2012 23:04:23 -0000 + +On Fri, 14 Dec 2012, david@tethera.net wrote: +> 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 | 5 ++++- +> test/dump-restore | 5 ++--- +> 4 files changed, 27 insertions(+), 27 deletions(-) +> +> diff --git a/notmuch-restore.c b/notmuch-restore.c +> index 40596a8..112f2f3 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_ONLY, +> &query_string, tag_ops); + +I realize that we've screwed up a bit here already in the restore +series. parse_sup_line() allocates query_string for each input line, but +doesn't free it during parsing. parse_tag_line() sets query_string to +point to the query string within line. And now it gets worse when +query_string is allocated vs. set to point to another buffer depending +on TAG_FLAG_ID_ONLY, so it's not an easy interface to use. + +> - +> - 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 e1181f8..8fea76c 100644 +> --- a/tag-util.c +> +++ b/tag-util.c +> @@ -201,14 +201,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_ONLY) { +> + /* 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) || + +The current wording is, "Any characters in and MAY +be hex encoded with %NN...", but the above no longer matches that, as +"id:" must not be encoded. In the interest of keeping the documentation +concise, I think you should move the above check after +hex_decode_inplace(), but keep the below check here. That should do it, +right? + +> + (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 = quote_and_decode_query (ctx, tok, line_for_error, query_string); +> } + +It's not pretty that query_string gets allocated or not depending on a +flag that doesn't seem to have anything to do with that. I don't have a +good suggestion now, though, and I'd like to keep the restore path like +it is, without allocation. + +> +> - *query_string = tok; +> - +> DONE: +> talloc_free (line_for_error); +> return ret; +> diff --git a/tag-util.h b/tag-util.h +> index 2889736..7674051 100644 +> --- a/tag-util.h +> +++ b/tag-util.h +> @@ -26,7 +26,10 @@ 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), +> + +> + /* Query consists of a single id:$message-id */ +> + TAG_FLAG_ID_ONLY = (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 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2