From: Austin Clements Date: Sun, 27 Jul 2014 03:52:51 +0000 (+2000) Subject: [PATCH 12/14] lib: Support empty header values in database X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=83a12328cdeb25562339e2e3f2f10e04c68e5d73;p=notmuch-archives.git [PATCH 12/14] lib: Support empty header values in database --- diff --git a/27/bf5b689b518935729b752e0f642d626aa29d45 b/27/bf5b689b518935729b752e0f642d626aa29d45 new file mode 100644 index 000000000..ac562ee45 --- /dev/null +++ b/27/bf5b689b518935729b752e0f642d626aa29d45 @@ -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 11453431FC7 + for ; Sat, 26 Jul 2014 20:53:32 -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 Sbjh1W7WjSco for ; + Sat, 26 Jul 2014 20:53:26 -0700 (PDT) +Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu + [18.7.68.37]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id B5A3E431FCF + for ; Sat, 26 Jul 2014 20:53:08 -0700 (PDT) +X-AuditID: 12074425-f79766d000006da8-c5-53d477a1f1d2 +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-8.mit.edu (Symantec Messaging Gateway) with SMTP + id F0.5E.28072.1A774D35; Sat, 26 Jul 2014 23:53:05 -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 s6R3r2xj004147; + Sat, 26 Jul 2014 23:53:02 -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 s6R3r0Se016410 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sat, 26 Jul 2014 23:53:01 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XBFW8-00051e-Fw; Sat, 26 Jul 2014 23:53:00 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 12/14] lib: Support empty header values in database +Date: Sat, 26 Jul 2014 23:52:51 -0400 +Message-Id: <1406433173-19169-13-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1406433173-19169-1-git-send-email-amdragon@mit.edu> +References: <1406433173-19169-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrbuw/EqwwZJpEhbXb85kdmD0eLbq + FnMAYxSXTUpqTmZZapG+XQJXxt2zT5gKXotXnF2wk7mBsV24i5GTQ0LARGLf5g5GCFtM4sK9 + 9WxdjFwcQgKzmSQWL/4KlhAS2MgoMWdjHUTiDpPEgXPfmSGcuYwSJ54dYAGpYhPQkNi2fzlY + h4iAtMTOu7NZuxg5OJgF1CT+dKmAhIUFnCW2HukAK2cRUJV40HGHGcTmFXCUeL38CivEFXIS + DTc+sYHYnEDx489OsIGMERJwkLh1KXECI/8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealFuhZ6 + uZkleqkppZsYQSHD7qK6g3HCIaVDjAIcjEo8vAIsV4KFWBPLiitzDzFKcjApifLuNwMK8SXl + p1RmJBZnxBeV5qQWH2KU4GBWEuEVKgbK8aYkVlalFuXDpKQ5WJTEed9aWwULCaQnlqRmp6YW + pBbBZGU4OJQkeL+WAjUKFqWmp1akZeaUIKSZODhBhvMADd8AUsNbXJCYW5yZDpE/xagoJc77 + CyQhAJLIKM2D64XF9CtGcaBXhHlZy4CqeIDpAK77FdBgJqDBLP6XQQaXJCKkpBoYYwxv5k0y + WjN/vvAphUfTLLbcd1onGnOEvZZJxt2xkeN/nuyMV0G/GLVWnE9/q6Bld21h3poGK1UhH8tF + st0mckdenRX88+K/V/6Lnmtcn55uC8kRW3zsc30ts1tfw7UrK07WLNX9f8XTqO7uFr6DDsoJ + wrVMb8qSFBJmnHh6d1UFj0mXUclmJZbijERDLeai4kQAc0HKvMQCAAA= +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: Sun, 27 Jul 2014 03:53:32 -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 +