--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 69C9A431FC3\r
+ for <notmuch@notmuchmail.org>; Tue, 29 Jul 2014 09:48:41 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] 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 NsQeoCcZFoHC for <notmuch@notmuchmail.org>;\r
+ Tue, 29 Jul 2014 09:48:36 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
+ [18.7.68.35])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 550FC431FC4\r
+ for <notmuch@notmuchmail.org>; Tue, 29 Jul 2014 09:48:21 -0700 (PDT)\r
+X-AuditID: 12074423-f79bf6d000007580-20-53d7d054c28a\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 7C.C9.30080.450D7D35; Tue, 29 Jul 2014 12:48:20 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s6TGmIun002609; \r
+ Tue, 29 Jul 2014 12:48:18 -0400\r
+Received: from drake.dyndns.org (31-33-71.wireless.csail.mit.edu\r
+ [128.31.33.71]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s6TGmF8T030272\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Tue, 29 Jul 2014 12:48:17 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1XCAZT-0007H8-0D; Tue, 29 Jul 2014 12:48:15 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 12/14] lib: Support empty header values in database\r
+Date: Tue, 29 Jul 2014 12:48:10 -0400\r
+Message-Id: <1406652492-27803-13-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <1406652492-27803-1-git-send-email-amdragon@mit.edu>\r
+References: <1406652492-27803-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixG6nrhty4Xqwwf3lMhar5/JYXL85k9mB\r
+ yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyrh79glTwWvxirMLdjI3MLYLdzFyckgImEjc\r
+ nX+JEcIWk7hwbz1bFyMXh5DAbCaJdav+sEA4GxklJp68ygrhHGOS2PLzNCOEM5dRovfLdbB+\r
+ NgENiW37l4PZIgLSEjvvzmYFsZkFHCU+71/EBmILC7hJLPn9DyjOwcEioCpx4IIYSJgXqOTD\r
+ v2NQZ8hJNNz4BFbOCRS/de8uE4gtJOAgcWjWZpYJjPwLGBlWMcqm5Fbp5iZm5hSnJusWJyfm\r
+ 5aUW6Zrp5WaW6KWmlG5iBAeSi/IOxj8HlQ4xCnAwKvHwbph7LViINbGsuDL3EKMkB5OSKK/e\r
+ vuvBQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4+c4C5XhTEiurUovyYVLSHCxK4rxvra2ChQTS\r
+ E0tSs1NTC1KLYLIyHBxKErxG54EaBYtS01Mr0jJzShDSTBycIMN5gIY3g9TwFhck5hZnpkPk\r
+ TzEqSonzZp8DSgiAJDJK8+B6YZH+ilEc6BVh3jaQdh5gkoDrfgU0mAloMKsL2OCSRISUVAPj\r
+ 6V+zZ33Ofs5+xMm95J+px4ovSmGJj1ftmNnhvivsAptUKM8Xk+Sp+mJFKqVuPDPK7olqbS9W\r
+ UVnz69J/szdBh16tS/qV5LickeXM7ZVPEmW9i9pU3vlOOl5+pt2+yrbo7puy7KyD8b+3L/ue\r
+ YatzN8qo8r3v+U97XqRd32LLedtk1lGuuL2sSizFGYmGWsxFxYkAJMRJs88CAAA=\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: Tue, 29 Jul 2014 16:48:41 -0000\r
+\r
+Commit 567bcbc2 introduced support for storing various headers in\r
+document values. However, doing so in a backwards-compatible way\r
+meant that genuinely empty header values could not be distinguished\r
+from the old behavior of not storing the headers at all, so these\r
+required parsing the original message.\r
+\r
+Now that we have database features, new databases can declare that all\r
+messages have header values, so if we have this feature flag, we can\r
+use the stored header value even if it's the empty string.\r
+\r
+This requires slight cleanup to notmuch_message_get_header, since the\r
+code previously couldn't distinguish between empty headers and headers\r
+that are never stored in the database (previously this distinction\r
+didn't matter).\r
+---\r
+ lib/message.cc | 45 +++++++++++++++++++++++++++------------------\r
+ 1 file changed, 27 insertions(+), 18 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index e6a5a5a..4fc427f 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -412,26 +412,35 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)\r
+ const char *\r
+ notmuch_message_get_header (notmuch_message_t *message, const char *header)\r
+ {\r
+- try {\r
+- std::string value;\r
+-\r
+- /* Fetch header from the appropriate xapian value field if\r
+- * available */\r
+- if (strcasecmp (header, "from") == 0)\r
+- value = message->doc.get_value (NOTMUCH_VALUE_FROM);\r
+- else if (strcasecmp (header, "subject") == 0)\r
+- value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT);\r
+- else if (strcasecmp (header, "message-id") == 0)\r
+- value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID);\r
+-\r
+- if (!value.empty())\r
++ Xapian::valueno slot = Xapian::BAD_VALUENO;\r
++\r
++ /* Fetch header from the appropriate xapian value field if\r
++ * available */\r
++ if (strcasecmp (header, "from") == 0)\r
++ slot = NOTMUCH_VALUE_FROM;\r
++ else if (strcasecmp (header, "subject") == 0)\r
++ slot = NOTMUCH_VALUE_SUBJECT;\r
++ else if (strcasecmp (header, "message-id") == 0)\r
++ slot = NOTMUCH_VALUE_MESSAGE_ID;\r
++\r
++ if (slot != Xapian::BAD_VALUENO) {\r
++ try {\r
++ std::string value = message->doc.get_value (slot);\r
++\r
++ /* If we have NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, then\r
++ * empty values indicate empty headers. If we don't, then\r
++ * it could just mean we didn't record the header. */\r
++ if ((message->notmuch->features &\r
++ NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES) ||\r
++ ! value.empty())\r
+ return talloc_strdup (message, value.c_str ());\r
+ \r
+- } catch (Xapian::Error &error) {\r
+- fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",\r
+- error.get_msg().c_str());\r
+- message->notmuch->exception_reported = TRUE;\r
+- return NULL;\r
++ } catch (Xapian::Error &error) {\r
++ fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",\r
++ error.get_msg().c_str());\r
++ message->notmuch->exception_reported = TRUE;\r
++ return NULL;\r
++ }\r
+ }\r
+ \r
+ /* Otherwise fall back to parsing the file */\r
+-- \r
+2.0.0\r
+\r