--- /dev/null
+Return-Path: <amthrax@awakening.csail.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 C1C5E431FAE\r
+ for <notmuch@notmuchmail.org>; Mon, 26 Mar 2012 18:37:23 -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 nqfAl0cNnm2X for <notmuch@notmuchmail.org>;\r
+ Mon, 26 Mar 2012 18:37:22 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+ [18.7.68.35])\r
+ by olra.theworths.org (Postfix) with ESMTP id D3BE3431FB6\r
+ for <notmuch@notmuchmail.org>; Mon, 26 Mar 2012 18:37:21 -0700 (PDT)\r
+X-AuditID: 12074423-b7f9c6d0000008c3-b9-4f7119d1d2eb\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 55.F8.02243.1D9117F4; Mon, 26 Mar 2012 21:37:21 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q2R1bKOU013590; \r
+ Mon, 26 Mar 2012 21:37:20 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q2R1bJ5u004575\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Mon, 26 Mar 2012 21:37:20 -0400 (EDT)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amthrax@awakening.csail.mit.edu>)\r
+ id 1SCLLa-0005Kf-Na; Mon, 26 Mar 2012 21:37:18 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] emacs: Escape all message ID queries\r
+Date: Mon, 26 Mar 2012 21:37:16 -0400\r
+Message-Id: <1332812236-20387-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.7.2\r
+In-Reply-To: <1332812236-20387-1-git-send-email-amdragon@mit.edu>\r
+References: <1332812236-20387-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrPIsWRmVeSWpSXmKPExsUixCmqrHtRstDfYOIKTovrN2cyOzB6PFt1\r
+ izmAMYrLJiU1J7MstUjfLoEro/nJMpaCE6oVqxtmMDYwHpPrYuTkkBAwkWh7eoEdwhaTuHBv\r
+ PRuILSSwj1GiZZlrFyMXkL2BUeLLzSXMEImTTBLzTotCJDYzSpy5uQWsg01AQ2Lb/uWMILaI\r
+ gLTEzruzWbsYOTiYBdQk/nSpgJjCApYSX6e4gFSwCKhK7Fn7iQXE5hVwkPh7+SkbxA0KEjOm\r
+ XGEEKecUcJRY+C4UYquDxPM1e5knMPIvYGRYxSibklulm5uYmVOcmqxbnJyYl5dapGuml5tZ\r
+ opeaUrqJERQu7C7KOxj/HFQ6xCjAwajEw2s4vcBfiDWxrLgy9xCjJAeTkigvLzDYhPiS8lMq\r
+ MxKLM+KLSnNSiw8xSnAwK4nw3jwJVM6bklhZlVqUD5OS5mBREufV0HrnJySQnliSmp2aWpBa\r
+ BJOV4eBQkuDlARkqWJSanlqRlplTgpBm4uAEGc4DNFwHpIa3uCAxtzgzHSJ/ilFRSpyXESQh\r
+ AJLIKM2D64XF8ytGcaBXhHllQap4gKkArvsV0GAmoMFLjuSDDC5JREhJNTAaPf7lZL/PdG34\r
+ /qznSxbO02Ld2fOiQWF9sOAR/bcps7Ybpkz49ecq0+Xr/1UX8BYV3L4Wyv+8sP9Vz9euXa2L\r
+ 5+6Mk7SYlv2oPI9j812hsxvrU4p/NUt8N5Lpv7vq1+FCORmj2fNfuPbUX730JXmlpuM+a73a\r
+ 9+0RQeyvD5bqTZpTOcXH4vZaJZbijERDLeai4kQACC8H/8ICAAA=\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, 27 Mar 2012 01:37:23 -0000\r
+\r
+This adds a lib function to turn a message ID into a properly escaped\r
+message ID query and uses this function wherever we previously\r
+hand-constructed ID queries. Wherever this new function is used,\r
+documentation has been clarified to refer to "id: queries" instead of\r
+"message IDs".\r
+\r
+This fixes the broken test introduced by the previous patch.\r
+---\r
+ emacs/notmuch-lib.el | 6 +++++-\r
+ emacs/notmuch-message.el | 2 +-\r
+ emacs/notmuch-show.el | 14 +++++++-------\r
+ test/emacs | 1 -\r
+ 4 files changed, 13 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index c146748..2e367b5 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -144,6 +144,10 @@ the user hasn't set this variable with the old or new value."\r
+ "[No Subject]"\r
+ subject)))\r
+ \r
++(defun notmuch-id-to-query (id)\r
++ "Return a query that matches the message with id ID."\r
++ (concat "id:\"" (replace-regexp-in-string "\"" "\"\"" id t t) "\""))\r
++\r
+ ;;\r
+ \r
+ (defun notmuch-common-do-stash (text)\r
+@@ -230,7 +234,7 @@ the given type."\r
+ \r
+ (defun notmuch-get-bodypart-content (msg part nth process-crypto)\r
+ (or (plist-get part :content)\r
+- (notmuch-get-bodypart-internal (concat "id:" (plist-get msg :id)) nth process-crypto)))\r
++ (notmuch-get-bodypart-internal (notmuch-id-to-query (plist-get msg :id)) nth process-crypto)))\r
+ \r
+ (defun notmuch-plist-to-alist (plist)\r
+ (loop for (key value . rest) on plist by #'cddr\r
+diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el\r
+index 264a5b9..3010281 100644\r
+--- a/emacs/notmuch-message.el\r
++++ b/emacs/notmuch-message.el\r
+@@ -44,7 +44,7 @@ the \"inbox\" and \"todo\", you would set\r
+ (concat "+" str)\r
+ str))\r
+ notmuch-message-replied-tags)))\r
+- (apply 'notmuch-tag (concat "id:" (car (car rep))) tags)))))\r
++ (apply 'notmuch-tag (notmuch-id-to-query (car (car rep))) tags)))))\r
+ \r
+ (add-hook 'message-send-hook 'notmuch-message-mark-replied)\r
+ \r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 0cd7d82..6d3fe62 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -613,7 +613,7 @@ current buffer, if possible."\r
+ ;; times (hundreds!), which results in many calls to\r
+ ;; `notmuch part'.\r
+ (unless content\r
+- (setq content (notmuch-get-bodypart-internal (concat "id:" message-id)\r
++ (setq content (notmuch-get-bodypart-internal (notmuch-id-to-query message-id)\r
+ part-number notmuch-show-process-crypto))\r
+ (with-current-buffer w3m-current-buffer\r
+ (notmuch-show-w3m-cid-store-internal url\r
+@@ -1325,16 +1325,16 @@ Some useful entries are:\r
+ (plist-get props prop)))\r
+ \r
+ (defun notmuch-show-get-message-id (&optional bare)\r
+- "Return the Message-Id of the current message.\r
++ "Return an id: query for the Message-Id of the current message.\r
+ \r
+ If optional argument BARE is non-nil, return\r
+-the Message-Id without prefix and quotes."\r
++the Message-Id without id: prefix and escaping."\r
+ (if bare\r
+ (notmuch-show-get-prop :id)\r
+- (concat "id:\"" (notmuch-show-get-prop :id) "\"")))\r
++ (notmuch-id-to-query (notmuch-show-get-prop :id))))\r
+ \r
+ (defun notmuch-show-get-messages-ids ()\r
+- "Return all message ids of messages in the current thread."\r
++ "Return all id: queries of messages in the current thread."\r
+ (let ((message-ids))\r
+ (notmuch-show-mapc\r
+ (lambda () (push (notmuch-show-get-message-id) message-ids)))\r
+@@ -1401,7 +1401,7 @@ current thread."\r
+ ;; thread.\r
+ \r
+ (defun notmuch-show-get-message-ids-for-open-messages ()\r
+- "Return a list of all message IDs for open messages in the current thread."\r
++ "Return a list of all id: queries for open messages in the current thread."\r
+ (save-excursion\r
+ (let (message-ids done)\r
+ (goto-char (point-min))\r
+@@ -1805,7 +1805,7 @@ thread from search."\r
+ (notmuch-common-do-stash (notmuch-show-get-from)))\r
+ \r
+ (defun notmuch-show-stash-message-id ()\r
+- "Copy message ID of current message to kill-ring."\r
++ "Copy id: query matching the current message to kill-ring."\r
+ (interactive)\r
+ (notmuch-common-do-stash (notmuch-show-get-message-id)))\r
+ \r
+diff --git a/test/emacs b/test/emacs\r
+index 62eaedb..8b92d0a 100755\r
+--- a/test/emacs\r
++++ b/test/emacs\r
+@@ -140,7 +140,6 @@ output=$(notmuch search 'id:"123..456@example"' | notmuch_search_sanitize)\r
+ test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Message with .. in Message-Id (inbox search-add show-add)"\r
+ \r
+ test_begin_subtest "Message with quote in Message-Id:"\r
+-test_subtest_known_broken\r
+ add_message '[id]="\"quote\"@example"' '[subject]="Message with quote in Message-Id"'\r
+ test_emacs '(notmuch-search "subject:\"Message with quote\"")\r
+ (notmuch-test-wait)\r
+-- \r
+1.7.7.2\r
+\r