From: Austin Clements Date: Fri, 1 Aug 2014 02:10:01 +0000 (+2000) Subject: [PATCH v3 11/13] lib: Support empty header values in database X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=261521270a180b43adf6b172889482f5ca59b4e9;p=notmuch-archives.git [PATCH v3 11/13] lib: Support empty header values in database --- diff --git a/b3/39bb6b67effdfd15a35ef6da309a8935f1f3d5 b/b3/39bb6b67effdfd15a35ef6da309a8935f1f3d5 new file mode 100644 index 000000000..23f80dd80 --- /dev/null +++ b/b3/39bb6b67effdfd15a35ef6da309a8935f1f3d5 @@ -0,0 +1,155 @@ +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 E301E429E32 + for ; Thu, 31 Jul 2014 19:10:36 -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 sSiOIOZ3A1MD for ; + Thu, 31 Jul 2014 19:10:30 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id D3D5D431FC4 + for ; Thu, 31 Jul 2014 19:10:13 -0700 (PDT) +X-AuditID: 1209190e-f79946d000007db1-3b-53daf7036d68 +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 73.DF.32177.307FAD35; Thu, 31 Jul 2014 22:10:11 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s712A8eI008857; + Thu, 31 Jul 2014 22:10:09 -0400 +Received: from drake.dyndns.org + (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [216.15.114.40]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s712A7jO029991 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 31 Jul 2014 22:10:08 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XD2II-00033v-71; Thu, 31 Jul 2014 22:10:06 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v3 11/13] lib: Support empty header values in database +Date: Thu, 31 Jul 2014 22:10:01 -0400 +Message-Id: <1406859003-11561-12-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1406859003-11561-1-git-send-email-amdragon@mit.edu> +References: <1406859003-11561-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixCmqrcv8/VawQetuK4vVc3ksrt+cyezA + 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZdw9+4Sp4LV4xdkFO5kbGNuFuxg5OSQETCRu + LP3DDmGLSVy4t56ti5GLQ0hgNpPEhJ/NzBDORkaJndefskI4d5gkDl3/wQjhzGWUmLlrDQtI + P5uAhsS2/csZQWwRAWmJnXdns4LYzAKOEp/3L2IDsYUF3CRa5h8H28cioCpx4co7oHoODl6g + mi/buSDOkJNouPEJrJwTKPz/3wKwMUICDhKtp7cyT2DkX8DIsIpRNiW3Sjc3MTOnODVZtzg5 + MS8vtUjXWC83s0QvNaV0EyM4kCT5djB+Pah0iFGAg1GJh3dG+K1gIdbEsuLK3EOMkhxMSqK8 + Nh+BQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4X34AyvGmJFZWpRblw6SkOViUxHnfWlsFCwmk + J5akZqemFqQWwWRlODiUJHjPfAVqFCxKTU+tSMvMKUFIM3FwggznARou9A1keHFBYm5xZjpE + /hSjopQ47x6QZgGQREZpHlwvLNJfMYoDvSLM+xCkigeYJOC6XwENZgIa/PzWdZDBJYkIKakG + xph/x5nunzeUicjZXP5pYXrf1L0BMocyf/sv7w45wiHFvHOXfkrDwpLTcf2X2bknZvg3W3x6 + 8DjHtCc0LNxGyXdqpX3n43l/muYEzEly/O/4YPuK1Tvvid9bfMepXFpVwPP2nDftGllr/NIS + ZDJ9/j1aPX+p89lfj86fKLCuvt951WKVdODSRiWW4oxEQy3mouJEACMJbbjPAgAA +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, 01 Aug 2014 02:10:37 -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 e6a5a5a..4fc427f 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -412,26 +412,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 +