Re: [Patch v7 06/14] notmuch-restore: move query handling for batch restore to parser
authorJani Nikula <jani@nikula.org>
Sat, 15 Dec 2012 23:04:17 +0000 (01:04 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:21 +0000 (09:52 -0800)
50/35aef6a6ef4a19d4eaf09970de6465cb2f2a17 [new file with mode: 0644]

diff --git a/50/35aef6a6ef4a19d4eaf09970de6465cb2f2a17 b/50/35aef6a6ef4a19d4eaf09970de6465cb2f2a17
new file mode 100644 (file)
index 0000000..f2e3e71
--- /dev/null
@@ -0,0 +1,226 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 37B90431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:04:23 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id G-Ei8KC+YenN for <notmuch@notmuchmail.org>;\r
+       Sat, 15 Dec 2012 15:04:22 -0800 (PST)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 245EC431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:04:21 -0800 (PST)\r
+Received: by mail-lb0-f181.google.com with SMTP id ge1so3673115lbb.26\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:04:20 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+       :message-id:mime-version:content-type:x-gm-message-state;\r
+       bh=dSE00KTRCDMypaLFoiYsbbD6j+ynuW0qktf2QZ2UKuI=;\r
+       b=Wuk+6xPntwbaFN10NUMFADmBpCjYiLLhWgqbUAvTjWgtFDfFnGI2fvrYOL34V1NJgL\r
+       oDApPh/4RrvGtTqF8bxvbVO4ZiJdXaRZpuffo5ZeH6C3A0TWKT71Rahf93JfM9ZAT0KE\r
+       9D3kTRNoZdu0Bk8GIWuH9NYQFgZgRJ+syKSMIaVxuR89bCcG9I8ligJ4ZtTOEoi1jNxb\r
+       qCFZ9miRnV4VYilsMwwUcamQSI+36+2ltcpyVEjlkHZOS0y6NRe4Y+Gf4H1T3qY5Ebr2\r
+       hbcx39dwkANXxX5gZGPnHV7ZW7xeXSRmCwcL6R8fDsi3zJzAMhn0BBE7h69QW1fdeORJ\r
+       +u9Q==\r
+Received: by 10.112.11.33 with SMTP id n1mr4120732lbb.18.1355612660546;\r
+       Sat, 15 Dec 2012 15:04:20 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id er8sm3274601lbb.9.2012.12.15.15.04.18\r
+       (version=SSLv3 cipher=OTHER); Sat, 15 Dec 2012 15:04:19 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: david@tethera.net, notmuch@notmuchmail.org\r
+Subject: Re: [Patch v7 06/14] notmuch-restore: move query handling for batch\r
+       restore to parser\r
+In-Reply-To: <1355492062-7546-7-git-send-email-david@tethera.net>\r
+References: <1355492062-7546-1-git-send-email-david@tethera.net>\r
+       <1355492062-7546-7-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1\r
+       (i686-pc-linux-gnu)\r
+Date: Sun, 16 Dec 2012 01:04:17 +0200\r
+Message-ID: <87vcc2q5n2.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQlmkEtCMvMzHRLTDsHeT71XJjDsXmLmi5n7kAtEziatui3xTZQhIrKfr1X+A/9pnsghwaHL\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 15 Dec 2012 23:04:23 -0000\r
+\r
+On Fri, 14 Dec 2012, david@tethera.net wrote:\r
+> From: David Bremner <bremner@debian.org>\r
+>\r
+> We are able to detect more errors by looking at the string before it\r
+> is hex-decoded. We also need this to avoid the query quoting for more\r
+> general queries (to be written) that will mess up raw message-ids.\r
+> ---\r
+>  notmuch-restore.c |   18 +-----------------\r
+>  tag-util.c        |   26 ++++++++++++++++++++------\r
+>  tag-util.h        |    5 ++++-\r
+>  test/dump-restore |    5 ++---\r
+>  4 files changed, 27 insertions(+), 27 deletions(-)\r
+>\r
+> diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+> index 40596a8..112f2f3 100644\r
+> --- a/notmuch-restore.c\r
+> +++ b/notmuch-restore.c\r
+> @@ -208,24 +208,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+>      if (input_format == DUMP_FORMAT_SUP) {\r
+>          ret = parse_sup_line (ctx, line, &query_string, tag_ops);\r
+>      } else {\r
+> -        ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS,\r
+> +        ret = parse_tag_line (ctx, line, TAG_FLAG_BE_GENEROUS | TAG_FLAG_ID_ONLY,\r
+>                                &query_string, tag_ops);\r
+\r
+I realize that we've screwed up a bit here already in the restore\r
+series. parse_sup_line() allocates query_string for each input line, but\r
+doesn't free it during parsing. parse_tag_line() sets query_string to\r
+point to the query string within line. And now it gets worse when\r
+query_string is allocated vs. set to point to another buffer depending\r
+on TAG_FLAG_ID_ONLY, so it's not an easy interface to use.\r
+\r
+> -\r
+> -        if (ret == 0) {\r
+> -            if (strncmp ("id:", query_string, 3) != 0) {\r
+> -                fprintf (stderr, "Warning: unsupported query: %s\n", query_string);\r
+> -                continue;\r
+> -            }\r
+> -            /* delete id: from front of string; tag_message\r
+> -             * expects a raw message-id.\r
+> -             *\r
+> -             * XXX: Note that query string id:foo and bar will be\r
+> -             * interpreted as a message id "foo and bar". This\r
+> -             * should eventually be fixed to give a better error\r
+> -             * message.\r
+> -             */\r
+> -            query_string = query_string + 3;\r
+> -        }\r
+\r
+\r
+\r
+>      }\r
+>  \r
+>      if (ret > 0)\r
+> diff --git a/tag-util.c b/tag-util.c\r
+> index e1181f8..8fea76c 100644\r
+> --- a/tag-util.c\r
+> +++ b/tag-util.c\r
+> @@ -201,14 +201,28 @@ parse_tag_line (void *ctx, char *line,\r
+>      }\r
+>  \r
+>      /* tok now points to the query string */\r
+> -    if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
+> -    ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
+> -                      "hex decoding of query %s failed", tok);\r
+> -    goto DONE;\r
+> +    if (flags & TAG_FLAG_ID_ONLY) {\r
+> +    /* this is under the assumption that any whitespace in the\r
+> +     * message-id must be hex-encoded. The check is probably not\r
+> +     * perfect for exotic unicode whitespace; as fallback the\r
+> +     * search for strange message-ids will fail */\r
+> +    if ((strncmp ("id:", tok, 3) != 0) ||\r
+\r
+The current wording is, "Any characters in <tag> and <search-term> MAY\r
+be hex encoded with %NN...", but the above no longer matches that, as\r
+"id:" must not be encoded. In the interest of keeping the documentation\r
+concise, I think you should move the above check after\r
+hex_decode_inplace(), but keep the below check here. That should do it,\r
+right?\r
+\r
+> +        (strcspn (tok, " \t") < strlen (tok))) {\r
+> +        ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
+> +                          "query '%s' is not 'id:<message-id>'", tok);\r
+> +        goto DONE;\r
+> +    }\r
+> +    if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
+> +        ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
+> +                          "hex decoding of query %s failed", tok);\r
+> +        goto DONE;\r
+> +    }\r
+> +    /* skip 'id:' */\r
+> +    *query_string = tok + 3;\r
+> +    } else {\r
+> +    ret = quote_and_decode_query (ctx, tok, line_for_error, query_string);\r
+>      }\r
+\r
+It's not pretty that query_string gets allocated or not depending on a\r
+flag that doesn't seem to have anything to do with that. I don't have a\r
+good suggestion now, though, and I'd like to keep the restore path like\r
+it is, without allocation.\r
+\r
+>  \r
+> -    *query_string = tok;\r
+> -\r
+>    DONE:\r
+>      talloc_free (line_for_error);\r
+>      return ret;\r
+> diff --git a/tag-util.h b/tag-util.h\r
+> index 2889736..7674051 100644\r
+> --- a/tag-util.h\r
+> +++ b/tag-util.h\r
+> @@ -26,7 +26,10 @@ typedef enum {\r
+>      /* Accept strange tags that might be user error;\r
+>       * intended for use by notmuch-restore.\r
+>       */\r
+> -    TAG_FLAG_BE_GENEROUS = (1 << 3)\r
+> +    TAG_FLAG_BE_GENEROUS = (1 << 3),\r
+> +\r
+> +    /* Query consists of a single id:$message-id */\r
+> +    TAG_FLAG_ID_ONLY = (1 << 4)\r
+>  \r
+>  } tag_op_flag_t;\r
+>  \r
+> diff --git a/test/dump-restore b/test/dump-restore\r
+> index 6a989b6..eb7933a 100755\r
+> --- a/test/dump-restore\r
+> +++ b/test/dump-restore\r
+> @@ -199,19 +199,18 @@ a\r
+>  # the next non-comment line should report an an empty tag error for\r
+>  # batch tagging, but not for restore\r
+>  + +e -- id:20091117232137.GA7669@griffis1.net\r
+> -# highlight the sketchy id parsing; this should be last\r
+>  +g -- id:foo and bar\r
+>  EOF\r
+>  \r
+>  cat <<EOF > EXPECTED\r
+> -Warning: unsupported query: a\r
+> +Warning: query 'a' is not 'id:<message-id>' [a]\r
+>  Warning: no query string [+0]\r
+>  Warning: no query string [+a +b]\r
+>  Warning: missing query string [+a +b ]\r
+>  Warning: no query string after -- [+c +d --]\r
+>  Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]\r
+>  Warning: hex decoding of query id:%yy failed [+e +f id:%yy]\r
+> -Warning: cannot apply tags to missing message: foo and bar\r
+> +Warning: query 'id:foo and bar' is not 'id:<message-id>' [+g -- id:foo and bar]\r
+>  EOF\r
+>  \r
+>  test_expect_equal_file EXPECTED OUTPUT\r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r