From: Austin Clements Date: Mon, 25 Aug 2014 17:26:07 +0000 (+2000) Subject: [PATCH v4 09/11] lib: Support empty header values in database X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=99ab5161cb3aac3e687ee07e1a487a2742892659;p=notmuch-archives.git [PATCH v4 09/11] lib: Support empty header values in database --- diff --git a/51/14c7c0e56b316f3f4163deac8836ca5a0fc3b5 b/51/14c7c0e56b316f3f4163deac8836ca5a0fc3b5 new file mode 100644 index 000000000..c08a53506 --- /dev/null +++ b/51/14c7c0e56b316f3f4163deac8836ca5a0fc3b5 @@ -0,0 +1,154 @@ +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 0A026431FC4 + for ; Mon, 25 Aug 2014 10:28:53 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[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 WglD7fCPHLrQ for ; + Mon, 25 Aug 2014 10:28:45 -0700 (PDT) +Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu + [18.7.68.35]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 08E0F431FBD + for ; Mon, 25 Aug 2014 10:28:17 -0700 (PDT) +X-AuditID: 12074423-f799d6d00000337c-49-53fb72318a65 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP + id CB.C0.13180.1327BF35; Mon, 25 Aug 2014 13:28:17 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s7PHQE77001074; + Mon, 25 Aug 2014 13:26:15 -0400 +Received: from drake.dyndns.org (31-35-14.wireless.csail.mit.edu + [128.31.35.14]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s7PHQCAH029621 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Mon, 25 Aug 2014 13:26:13 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XLy20-0003jh-1n; Mon, 25 Aug 2014 13:26:12 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v4 09/11] lib: Support empty header values in database +Date: Mon, 25 Aug 2014 13:26:07 -0400 +Message-Id: <1408987569-14146-10-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1408987569-14146-1-git-send-email-amdragon@mit.edu> +References: <1408987569-14146-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixG6nrmtY9DvYoL3b3OJGazejRdN0Z4vr + N2cyOzB73Lr/mt3j2apbzB5bDr1nDmCO4rJJSc3JLEst0rdL4Mp48esjW8Fr8YrnJ7ayNDC2 + C3cxcnJICJhIvF5/gw3CFpO4cG89kM3FISQwm0liUcM9FghnI6PEia9fGSGcY0wS/YsaoJy5 + jBLLrnxnBOlnE9CQ+H1rMROILSIgLbHz7mxWEJtZwEti2YV+IJuDQ1jATaLlTQJImEVAVWLO + u91grbwCjhLvZz2GOkNOouHGJzCbEyg+feFssJFCAg4S3y+fZ57AyL+AkWEVo2xKbpVubmJm + TnFqsm5xcmJeXmqRrplebmaJXmpK6SZGcHC5KO9g/HNQ6RCjAAejEg/vjfjfwUKsiWXFlbmH + GCU5mJREeaflA4X4kvJTKjMSizPii0pzUosPMUpwMCuJ8DaD5HhTEiurUovyYVLSHCxK4rxv + ra2ChQTSE0tSs1NTC1KLYLIyHBxKEry5BUCNgkWp6akVaZk5JQhpJg5OkOE8QMPjQWp4iwsS + c4sz0yHypxgVpcR514JsFQBJZJTmwfXCov8VozjQK8K8R0HaeYCJA677FdBgJqDBpj0/QQaX + JCKkpBoYJa7ota8qWsK3MTvwTvH/Ek+u93t9zh6tMq/yf3TSTmJFIrtgRu/Zt82p5zYEys3Z + cFVBWodPUu/DQzMFUU2XFZHbl26YP3FyttBFp5e/lW/z606sclP5fVex+ob+jrtXA1IdgjxV + jGVS9eYxxDCYTuRb/dHqBtutjhMOndsbCx2tjsaIHnijxFKckWioxVxUnAgAarTD89kCAAA= +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: Mon, 25 Aug 2014 17:28:53 -0000 + +Commit 567bcbc2 introduced support for storing various headers in +document values. However, doing so in a backwards-compatible way +meant that genuinely empty header values could not be distinguished +from the old behavior of not storing the headers at all, so these +required parsing the original message. + +Now that we have database features, new databases can declare that all +messages have header values, so if we have this feature flag, we can +use the stored header value even if it's the empty string. + +This requires slight cleanup to notmuch_message_get_header, since the +code previously couldn't distinguish between empty headers and headers +that are never stored in the database (previously this distinction +didn't matter). +--- + lib/message.cc | 45 +++++++++++++++++++++++++++------------------ + 1 file changed, 27 insertions(+), 18 deletions(-) + +diff --git a/lib/message.cc b/lib/message.cc +index 3f93426..ed8c59e 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -414,26 +414,35 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message) + const char * + notmuch_message_get_header (notmuch_message_t *message, const char *header) + { +- try { +- std::string value; +- +- /* Fetch header from the appropriate xapian value field if +- * available */ +- if (strcasecmp (header, "from") == 0) +- value = message->doc.get_value (NOTMUCH_VALUE_FROM); +- else if (strcasecmp (header, "subject") == 0) +- value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT); +- else if (strcasecmp (header, "message-id") == 0) +- value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID); +- +- if (!value.empty()) ++ Xapian::valueno slot = Xapian::BAD_VALUENO; ++ ++ /* Fetch header from the appropriate xapian value field if ++ * available */ ++ if (strcasecmp (header, "from") == 0) ++ slot = NOTMUCH_VALUE_FROM; ++ else if (strcasecmp (header, "subject") == 0) ++ slot = NOTMUCH_VALUE_SUBJECT; ++ else if (strcasecmp (header, "message-id") == 0) ++ slot = NOTMUCH_VALUE_MESSAGE_ID; ++ ++ if (slot != Xapian::BAD_VALUENO) { ++ try { ++ std::string value = message->doc.get_value (slot); ++ ++ /* If we have NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, then ++ * empty values indicate empty headers. If we don't, then ++ * it could just mean we didn't record the header. */ ++ if ((message->notmuch->features & ++ NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES) || ++ ! value.empty()) + return talloc_strdup (message, value.c_str ()); + +- } catch (Xapian::Error &error) { +- fprintf (stderr, "A Xapian exception occurred when reading header: %s\n", +- error.get_msg().c_str()); +- message->notmuch->exception_reported = TRUE; +- return NULL; ++ } catch (Xapian::Error &error) { ++ fprintf (stderr, "A Xapian exception occurred when reading header: %s\n", ++ error.get_msg().c_str()); ++ message->notmuch->exception_reported = TRUE; ++ return NULL; ++ } + } + + /* Otherwise fall back to parsing the file */ +-- +2.0.0 +