[PATCH v4 09/11] lib: Support empty header values in database
authorAustin Clements <amdragon@mit.edu>
Mon, 25 Aug 2014 17:26:07 +0000 (13:26 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:04:19 +0000 (10:04 -0800)
51/14c7c0e56b316f3f4163deac8836ca5a0fc3b5 [new file with mode: 0644]

diff --git a/51/14c7c0e56b316f3f4163deac8836ca5a0fc3b5 b/51/14c7c0e56b316f3f4163deac8836ca5a0fc3b5
new file mode 100644 (file)
index 0000000..c08a535
--- /dev/null
@@ -0,0 +1,154 @@
+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 0A026431FC4\r
+       for <notmuch@notmuchmail.org>; Mon, 25 Aug 2014 10:28:53 -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 WglD7fCPHLrQ for <notmuch@notmuchmail.org>;\r
+       Mon, 25 Aug 2014 10:28:45 -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 08E0F431FBD\r
+       for <notmuch@notmuchmail.org>; Mon, 25 Aug 2014 10:28:17 -0700 (PDT)\r
+X-AuditID: 12074423-f799d6d00000337c-49-53fb72318a65\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 CB.C0.13180.1327BF35; Mon, 25 Aug 2014 13:28:17 -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 s7PHQE77001074; \r
+       Mon, 25 Aug 2014 13:26:15 -0400\r
+Received: from drake.dyndns.org (31-35-14.wireless.csail.mit.edu\r
+       [128.31.35.14]) (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 s7PHQCAH029621\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Mon, 25 Aug 2014 13:26:13 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1XLy20-0003jh-1n; Mon, 25 Aug 2014 13:26:12 -0400\r
+From: Austin Clements <amdragon@mit.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 09/11] lib: Support empty header values in database\r
+Date: Mon, 25 Aug 2014 13:26:07 -0400\r
+Message-Id: <1408987569-14146-10-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <1408987569-14146-1-git-send-email-amdragon@mit.edu>\r
+References: <1408987569-14146-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixG6nrmtY9DvYoL3b3OJGazejRdN0Z4vr\r
+       N2cyOzB73Lr/mt3j2apbzB5bDr1nDmCO4rJJSc3JLEst0rdL4Mp48esjW8Fr8YrnJ7ayNDC2\r
+       C3cxcnJICJhIvF5/gw3CFpO4cG89kM3FISQwm0liUcM9FghnI6PEia9fGSGcY0wS/YsaoJy5\r
+       jBLLrnxnBOlnE9CQ+H1rMROILSIgLbHz7mxWEJtZwEti2YV+IJuDQ1jATaLlTQJImEVAVWLO\r
+       u91grbwCjhLvZz2GOkNOouHGJzCbEyg+feFssJFCAg4S3y+fZ57AyL+AkWEVo2xKbpVubmJm\r
+       TnFqsm5xcmJeXmqRrplebmaJXmpK6SZGcHC5KO9g/HNQ6RCjAAejEg/vjfjfwUKsiWXFlbmH\r
+       GCU5mJREeaflA4X4kvJTKjMSizPii0pzUosPMUpwMCuJ8DaD5HhTEiurUovyYVLSHCxK4rxv\r
+       ra2ChQTSE0tSs1NTC1KLYLIyHBxKEry5BUCNgkWp6akVaZk5JQhpJg5OkOE8QMPjQWp4iwsS\r
+       c4sz0yHypxgVpcR514JsFQBJZJTmwfXCov8VozjQK8K8R0HaeYCJA677FdBgJqDBpj0/QQaX\r
+       JCKkpBoYJa7ota8qWsK3MTvwTvH/Ek+u93t9zh6tMq/yf3TSTmJFIrtgRu/Zt82p5zYEys3Z\r
+       cFVBWodPUu/DQzMFUU2XFZHbl26YP3FyttBFp5e/lW/z606sclP5fVex+ob+jrtXA1IdgjxV\r
+       jGVS9eYxxDCYTuRb/dHqBtutjhMOndsbCx2tjsaIHnijxFKckWioxVxUnAgAarTD89kCAAA=\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: Mon, 25 Aug 2014 17:28:53 -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 3f93426..ed8c59e 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -414,26 +414,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