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