--- /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 1B7DC431FDA\r
+ for <notmuch@notmuchmail.org>; Tue, 11 Mar 2014 15:20:19 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 aQuQ3lyH0dvs for <notmuch@notmuchmail.org>;\r
+ Tue, 11 Mar 2014 15:20:15 -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 560E8431FBF\r
+ for <notmuch@notmuchmail.org>; Tue, 11 Mar 2014 15:20:15 -0700 (PDT)\r
+X-AuditID: 12074425-f79906d000000cf9-eb-531f8c1b37d9\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\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 12.8F.03321.B1C8F135; Tue, 11 Mar 2014 18:20:11 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s2BMK9Pm028026; \r
+ Tue, 11 Mar 2014 18:20:10 -0400\r
+Received: from drake.dyndns.org (31-33-67.wireless.csail.mit.edu\r
+ [128.31.33.67]) (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 s2BMK86j024800\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Tue, 11 Mar 2014 18:20:09 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1WNV1r-0003Ma-Mb; Tue, 11 Mar 2014 18:20:07 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] emacs: Use whitelist instead of blacklist for term\r
+ escaping\r
+Date: Tue, 11 Mar 2014 18:19:54 -0400\r
+Message-Id: <1394576394-12816-2-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+In-Reply-To: <1394576394-12816-1-git-send-email-amdragon@mit.edu>\r
+References: <1394576394-12816-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrHIsWRmVeSWpSXmKPExsUixG6noivdIx9sMGW7pcX1mzOZHRg9nq26\r
+ xRzAGMVlk5Kak1mWWqRvl8CV0XxDs+AET8XF+fsYGxgXc3UxcnJICJhIzFqwiB3CFpO4cG89\r
+ G4gtJDCbSeLyM/0uRi4geyOjRPujiYwQzjEmiR/zZjBDOHMZJf5+28sM0sImoCGxbf9yRhBb\r
+ REBaYufd2axdjBwczAJqEn+6VEBMYYEAiSkn1EAqWARUJc7/XMoCEuYVcJA4s18d4gYliYWn\r
+ trGC2JwCjhLT5k5jBikRAiqZudhuAiP/AkaGVYyyKblVurmJmTnFqcm6xcmJeXmpRboWermZ\r
+ JXqpKaWbGMHB4qK6g3HCIaVDjAIcjEo8vA4K8sFCrIllxZW5hxglOZiURHlndwCF+JLyUyoz\r
+ Eosz4otKc1KLDzFKcDArifB+1ATK8aYkVlalFuXDpKQ5WJTEefvOSgQLCaQnlqRmp6YWpBbB\r
+ ZGU4OJQkeJd3ATUKFqWmp1akZeaUIKSZODhBhvMADWfoBhleXJCYW5yZDpE/xagoJc67EKRZ\r
+ ACSRUZoH1wuL5leM4kCvCPNGgVTxABMBXPcroMFMQIN/BIANLklESEk1MGaoqXiejjzxQ/Sg\r
+ tdMB7sPL3/N1Htu+ozQj4YHaQ67ebxxuuZka75+0tm2rvNXqVPGD71982Y9d7mdEim7mrbSW\r
+ +7kxiNHZcdGaQsVZ6u9VM+a0lH0pfZrO+7fh09XDP4VqF7QeuOWS+K2B9Tmr387ic4UM5/NL\r
+ zlv7zq2Uvcp4b0rUlDSPnUosxRmJhlrMRcWJACcPjBPBAgAA\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, 11 Mar 2014 22:20:19 -0000\r
+\r
+Previously, the term escaper used a blacklist of characters that\r
+needed escaping. This blacklist turned out to be somewhat incomplete;\r
+for example, it did not contain non-whitespace ASCII control\r
+characters or Unicode "fancy quotes", both of which do require the\r
+term to be escaped.\r
+\r
+Switch to a whitelist of characters that are definitely safe to leave\r
+unquoted. This fixes the broken test introduced by the previous\r
+patch.\r
+---\r
+ emacs/notmuch-lib.el | 5 ++++-\r
+ test/T310-emacs.sh | 1 -\r
+ 2 files changed, 4 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 2fefdad..b071b2f 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -426,7 +426,10 @@ user-friendly queries."\r
+ \r
+ (save-match-data\r
+ (if (or (equal term "")\r
+- (string-match "[ ()]\\|^\"" term))\r
++ ;; To be pessimistic, only pass through terms composed\r
++ ;; entirely of ASCII printing characters other than ", (,\r
++ ;; and ).\r
++ (string-match "[^!#-'*-~]" term))\r
+ ;; Requires escaping\r
+ (concat "\"" (replace-regexp-in-string "\"" "\"\"" term t t) "\"")\r
+ term)))\r
+diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh\r
+index 6c18bbd..ac966e5 100755\r
+--- a/test/T310-emacs.sh\r
++++ b/test/T310-emacs.sh\r
+@@ -954,7 +954,6 @@ output=$(notmuch search --output=messages 'tag:search-global-race-tag')\r
+ test_expect_equal "$output" "id:$gen_msg_id_1"\r
+ \r
+ test_begin_subtest "Term escaping"\r
+-test_subtest_known_broken\r
+ output=$(test_emacs "(mapcar 'notmuch-escape-boolean-term (list\r
+ \"\"\r
+ \"abc\`~\!@#\$%^&*-=_+123\"\r
+-- \r
+1.8.4.rc3\r
+\r