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 4D7E3431FAF for ; Fri, 4 Jan 2013 05:55:56 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.098 X-Spam-Level: X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 e1Yd0mtt9-SA for ; Fri, 4 Jan 2013 05:55:55 -0800 (PST) Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 91A16431FAE for ; Fri, 4 Jan 2013 05:55:55 -0800 (PST) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1Tr7kY-0002Ze-12; Fri, 04 Jan 2013 13:55:54 +0000 Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1Tr7kX-0002Vc-HT; Fri, 04 Jan 2013 13:55:53 +0000 From: Mark Walters To: notmuch@notmuchmail.org Subject: Xapian Quote tags User-Agent: Notmuch/0.14+236~g1d0044f (http://notmuchmail.org) Emacs/23.4.1 (x86_64-pc-linux-gnu) Date: Fri, 04 Jan 2013 13:55:52 +0000 Message-ID: <878v89hx1z.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Sender-Host-Address: 93.97.24.31 X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: 2da5113837db2c5d4ff5b044120fdc9b (of first 20000 bytes) X-SpamAssassin-Score: -1.8 X-SpamAssassin-SpamBar: - X-SpamAssassin-Report: The QM spam filters have analysed this message to determine if it is spam. We require at least 5.0 points to mark a message as spam. This message scored -1.8 points. Summary of the scoring: * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, * medium trust * [138.37.6.40 listed in list.dnswl.org] * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) * 0.5 AWL AWL: From: address is in the auto white-list X-QM-Scan-Virus: ClamAV says the message is clean 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, 04 Jan 2013 13:55:56 -0000 Hello I would like to suggest that we Xapian quote the tags for notmuch dump/restore. The general view on irc is that we probably want to do this in the long term and I think it would be nice if we can avoid changing the dump format a second time. One problem is that our current line based parsing cannot cope with Xapian quoted newlines (which stay newlines). So allow a line to start with % which means hex-decode the whole line before passing to the main parser. Thus the query tags etc still need to be Xapian encoded. I attach a patch to show roughly what I mean. This is not complete: the dump routine does not hex encode lines with newlines yet, tests man pages etc are not updated and it is significantly unpolished. Also there should be some consolidation between parse_boolean_term and the xapian_decode routine. Despite the above caveats it broadly seems to work. Best wishes Mark >From d518e2be27ff7243ddc156699c2bfc38dec78b43 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Fri, 4 Jan 2013 13:37:42 +0000 Subject: [PATCH] notmuch dump: xapian quote tags --- notmuch-dump.c | 6 +++--- tag-util.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/notmuch-dump.c b/notmuch-dump.c index bf01a39..e94d870 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -120,9 +120,9 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) if (output_format == DUMP_FORMAT_SUP) { fputs (tag_str, output); } else { - if (hex_encode (notmuch, tag_str, - &buffer, &buffer_size) != HEX_SUCCESS) { - fprintf (stderr, "Error: failed to hex-encode tag %s\n", + if (make_boolean_term (notmuch, NULL, tag_str, + &buffer, &buffer_size)) { + fprintf (stderr, "Error: failed to xapian-encode tag %s\n", tag_str); return 1; } diff --git a/tag-util.c b/tag-util.c index ca12b3b..7384afa 100644 --- a/tag-util.c +++ b/tag-util.c @@ -31,6 +31,38 @@ line_error (tag_parse_status_t status, return status; } +static int +xapian_decode_tag_inplace (char *str, char* tok, size_t *tok_len) +{ + char *pos = str; + char *out = str; + + if (*pos == '"') { + int closed = 0; + /* Skip the opening quote, find the closing quote, and + * un-double doubled internal quotes. */ + for (++pos; *pos; ) { + if (*pos == '"') { + ++pos; + if (*pos != '"') { + /* Found the closing quote. */ + closed = 1; + break; + } + } + *out++ = *pos++; + } + if (! closed || *pos != ' ') + return HEX_SYNTAX_ERROR; + *tok_len = pos - tok; + } else { + out = tok + (*tok_len)++; + } + /* Terminate token */ + *out = '\0'; + return HEX_SUCCESS; +} + tag_parse_status_t parse_tag_line (void *ctx, char *line, tag_op_flag_t flags, @@ -60,6 +92,15 @@ parse_tag_line (void *ctx, char *line, goto DONE; } + if (*tok == '%') { + tok++; + if (hex_decode_inplace (tok) != HEX_SUCCESS) { + ret = line_error (TAG_PARSE_INVALID, line_for_error, + "hex decoding of line failed", ""); + goto DONE; + } + } + tag_op_list_reset (tag_ops); /* Parse tags. */ @@ -89,23 +130,21 @@ parse_tag_line (void *ctx, char *line, goto DONE; } - /* Terminate, and start next token after terminator. */ - *(tok + tok_len++) = '\0'; - remove = (*tok == '-'); tag = tok + 1; - /* Maybe refuse empty tags. */ + /* Maybe refuse empty tags. Note a quoted empty tag is allowed. */ if (! (flags & TAG_FLAG_BE_GENEROUS) && *tag == '\0') { ret = line_error (TAG_PARSE_INVALID, line_for_error, "empty tag"); goto DONE; } - /* Decode tag. */ - if (hex_decode_inplace (tag) != HEX_SUCCESS) { + /* Find real (quoted) end, terminate, and start next token + * after terminator. */ + if (xapian_decode_tag_inplace (tag, tok, &tok_len) != HEX_SUCCESS) { ret = line_error (TAG_PARSE_INVALID, line_for_error, - "hex decoding of tag %s failed", tag); + "xapian decoding of tag %s failed", tag); goto DONE; } -- 1.7.9.1