From 66316a2ef4b3cb35801b8597b810dcef8f9076c3 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 30 Jul 2014 12:48:10 +2000 Subject: [PATCH] [PATCH v2 12/14] lib: Support empty header values in database --- f9/4cd8d7ece97a4b62437b9d4782515eef4455ef | 154 ++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 f9/4cd8d7ece97a4b62437b9d4782515eef4455ef diff --git a/f9/4cd8d7ece97a4b62437b9d4782515eef4455ef b/f9/4cd8d7ece97a4b62437b9d4782515eef4455ef new file mode 100644 index 000000000..dc4af99ea --- /dev/null +++ b/f9/4cd8d7ece97a4b62437b9d4782515eef4455ef @@ -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 69C9A431FC3 + for ; Tue, 29 Jul 2014 09:48:41 -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 NsQeoCcZFoHC for ; + Tue, 29 Jul 2014 09:48:36 -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 550FC431FC4 + for ; Tue, 29 Jul 2014 09:48:21 -0700 (PDT) +X-AuditID: 12074423-f79bf6d000007580-20-53d7d054c28a +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 7C.C9.30080.450D7D35; Tue, 29 Jul 2014 12:48:20 -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 s6TGmIun002609; + Tue, 29 Jul 2014 12:48:18 -0400 +Received: from drake.dyndns.org (31-33-71.wireless.csail.mit.edu + [128.31.33.71]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s6TGmF8T030272 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Tue, 29 Jul 2014 12:48:17 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XCAZT-0007H8-0D; Tue, 29 Jul 2014 12:48:15 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 12/14] lib: Support empty header values in database +Date: Tue, 29 Jul 2014 12:48:10 -0400 +Message-Id: <1406652492-27803-13-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1406652492-27803-1-git-send-email-amdragon@mit.edu> +References: <1406652492-27803-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixG6nrhty4Xqwwf3lMhar5/JYXL85k9mB + yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyrh79glTwWvxirMLdjI3MLYLdzFyckgImEjc + nX+JEcIWk7hwbz1bFyMXh5DAbCaJdav+sEA4GxklJp68ygrhHGOS2PLzNCOEM5dRovfLdbB+ + NgENiW37l4PZIgLSEjvvzmYFsZkFHCU+71/EBmILC7hJLPn9DyjOwcEioCpx4IIYSJgXqOTD + v2NQZ8hJNNz4BFbOCRS/de8uE4gtJOAgcWjWZpYJjPwLGBlWMcqm5Fbp5iZm5hSnJusWJyfm + 5aUW6Zrp5WaW6KWmlG5iBAeSi/IOxj8HlQ4xCnAwKvHwbph7LViINbGsuDL3EKMkB5OSKK/e + vuvBQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4+c4C5XhTEiurUovyYVLSHCxK4rxvra2ChQTS + E0tSs1NTC1KLYLIyHBxKErxG54EaBYtS01Mr0jJzShDSTBycIMN5gIY3g9TwFhck5hZnpkPk + TzEqSonzZp8DSgiAJDJK8+B6YZH+ilEc6BVh3jaQdh5gkoDrfgU0mAloMKsL2OCSRISUVAPj + 6V+zZ33Ofs5+xMm95J+px4ovSmGJj1ftmNnhvivsAptUKM8Xk+Sp+mJFKqVuPDPK7olqbS9W + UVnz69J/szdBh16tS/qV5LickeXM7ZVPEmW9i9pU3vlOOl5+pt2+yrbo7puy7KyD8b+3L/ue + YatzN8qo8r3v+U97XqRd32LLedtk1lGuuL2sSizFGYmGWsxFxYkAJMRJs88CAAA= +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: Tue, 29 Jul 2014 16:48:41 -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 + -- 2.26.2