[PATCH 12/14] lib: Support empty header values in database
authorAustin Clements <amdragon@MIT.EDU>
Sun, 27 Jul 2014 03:52:51 +0000 (23:52 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:03:53 +0000 (10:03 -0800)
27/bf5b689b518935729b752e0f642d626aa29d45 [new file with mode: 0644]

diff --git a/27/bf5b689b518935729b752e0f642d626aa29d45 b/27/bf5b689b518935729b752e0f642d626aa29d45
new file mode 100644 (file)
index 0000000..ac562ee
--- /dev/null
@@ -0,0 +1,155 @@
+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 11453431FC7\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:32 -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 Sbjh1W7WjSco for <notmuch@notmuchmail.org>;\r
+       Sat, 26 Jul 2014 20:53:26 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+       [18.7.68.37])\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 B5A3E431FCF\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:08 -0700 (PDT)\r
+X-AuditID: 12074425-f79766d000006da8-c5-53d477a1f1d2\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       (using TLS with cipher AES256-SHA (256/256 bits))\r
+       (Client did not present a certificate)\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id F0.5E.28072.1A774D35; Sat, 26 Jul 2014 23:53:05 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s6R3r2xj004147; \r
+       Sat, 26 Jul 2014 23:53:02 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (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 s6R3r0Se016410\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 26 Jul 2014 23:53:01 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1XBFW8-00051e-Fw; Sat, 26 Jul 2014 23:53:00 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 12/14] lib: Support empty header values in database\r
+Date: Sat, 26 Jul 2014 23:52:51 -0400\r
+Message-Id: <1406433173-19169-13-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <1406433173-19169-1-git-send-email-amdragon@mit.edu>\r
+References: <1406433173-19169-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrbuw/EqwwZJpEhbXb85kdmD0eLbq\r
+       FnMAYxSXTUpqTmZZapG+XQJXxt2zT5gKXotXnF2wk7mBsV24i5GTQ0LARGLf5g5GCFtM4sK9\r
+       9WxdjFwcQgKzmSQWL/4KlhAS2MgoMWdjHUTiDpPEgXPfmSGcuYwSJ54dYAGpYhPQkNi2fzlY\r
+       h4iAtMTOu7NZuxg5OJgF1CT+dKmAhIUFnCW2HukAK2cRUJV40HGHGcTmFXCUeL38CivEFXIS\r
+       DTc+sYHYnEDx489OsIGMERJwkLh1KXECI/8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealFuhZ6\r
+       uZkleqkppZsYQSHD7qK6g3HCIaVDjAIcjEo8vAIsV4KFWBPLiitzDzFKcjApifLuNwMK8SXl\r
+       p1RmJBZnxBeV5qQWH2KU4GBWEuEVKgbK8aYkVlalFuXDpKQ5WJTEed9aWwULCaQnlqRmp6YW\r
+       pBbBZGU4OJQkeL+WAjUKFqWmp1akZeaUIKSZODhBhvMADd8AUsNbXJCYW5yZDpE/xagoJc77\r
+       CyQhAJLIKM2D64XF9CtGcaBXhHlZy4CqeIDpAK77FdBgJqDBLP6XQQaXJCKkpBoYYwxv5k0y\r
+       WjN/vvAphUfTLLbcd1onGnOEvZZJxt2xkeN/nuyMV0G/GLVWnE9/q6Bld21h3poGK1UhH8tF\r
+       st0mckdenRX88+K/V/6Lnmtcn55uC8kRW3zsc30ts1tfw7UrK07WLNX9f8XTqO7uFr6DDsoJ\r
+       wrVMb8qSFBJmnHh6d1UFj0mXUclmJZbijERDLeai4kQAc0HKvMQCAAA=\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: Sun, 27 Jul 2014 03:53:32 -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