--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\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 4FFF3429E27\r
+ for <notmuch@notmuchmail.org>; Sun, 17 Nov 2013 04:30:17 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ 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 Hx300YzknYyk for <notmuch@notmuchmail.org>;\r
+ Sun, 17 Nov 2013 04:30:09 -0800 (PST)\r
+Received: from mail-we0-f171.google.com (mail-we0-f171.google.com\r
+ [74.125.82.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 7356B431FC2\r
+ for <notmuch@notmuchmail.org>; Sun, 17 Nov 2013 04:30:09 -0800 (PST)\r
+Received: by mail-we0-f171.google.com with SMTP id t61so5167424wes.16\r
+ for <notmuch@notmuchmail.org>; Sun, 17 Nov 2013 04:30:06 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id;\r
+ bh=h0VBZhAQSoHcXo6DL89bHzfeo2i7gVJPbNr1cpbjtks=;\r
+ b=ggu46yxTqfHilio4YA/A8Kv6zGWGeBJigTMOgSvrLNia2c+Yd0rbrAfZVlHMXZNLJu\r
+ xFKwCTsxw2pLsrG0bpNHmt/mSdYBSUhX38c3clzFUpyBzJT5IFy+iyOz0oUf9Eu2KO5h\r
+ ORCH91AB5zbmkzUw0FL1iVxfwOcYcMqkIbSlXChSadD90LawYMAHV5rZtgkrkXXIUlhF\r
+ 1GrC0sSyIORomhzCoumumYIp8heeBhutNy/bQS0tzhyQvo7KvLQP9ugcTdS+zvrJASWV\r
+ nM2DUxNk5L22IDq5LVJDm7F9R17pBFdz5MEtbdcN4TAGT5pPG/EAUuBDcXGqtDciK8/z\r
+ dCaw==\r
+X-Received: by 10.194.11.38 with SMTP id n6mr13155088wjb.25.1384689852871;\r
+ Sun, 17 Nov 2013 04:04:12 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPSA id\r
+ ll10sm13573758wic.9.2013.11.17.04.04.11 for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 17 Nov 2013 04:04:12 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: do not put quoted reply in primary selection\r
+Date: Sun, 17 Nov 2013 12:04:09 +0000\r
+Message-Id: <1384689849-9388-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\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, 17 Nov 2013 12:30:17 -0000\r
+\r
+In current emacs (24.3) select-active-regions is set to t by\r
+default. The reply insertion code sets the region to the quoted\r
+message to make it easy to delete (kill-region or C-w). These two\r
+things combine to put the quoted message in the primary selection.\r
+\r
+This is not what the user wanted and is a privacy risk (accidental\r
+pasting of the quoted message). We can avoid some of the problems\r
+by let-binding select-active-regions to nil. This fixes if the\r
+primary selection was previously in a non-emacs window but not if\r
+it was in an emacs window. To avoid the problem in the latter case\r
+we deactivate mark.\r
+\r
+One key test (which fails under many simpler "fixes") is: open emacs\r
+24.3 with notmuch, open 2 windows (viewing different notmuch buffers),\r
+highlight some text in one, and then reply to a message in the\r
+other. In many of my earlier attempts to fix this big this test fails.\r
+---\r
+\r
+This problem was first discussed in the thread starting with jrollins\r
+bug report in id:87vc1y6fbr.fsf@servo.finestructure.net. I couldn't\r
+persuade the fixes mentioned in id:87hadh934c.fsf@qmul.ac.uk to work\r
+in all cases.\r
+\r
+The most difficult case to fix was when emacs already had a\r
+highlighted section. The simpler fixes mentioned did fix the case when\r
+the primary selection was in some non-emacs window (eg an xterm).\r
+\r
+Unfortunately there are lots of cases that need checking: differnent\r
+versions of emacs (at least 23 and 24), the various settings of\r
+select-active-regions (nil, t, 'only), does cutting the quoted message\r
+work, and possibly the various setting affecting whether cut text goes\r
+in the primary-selction or the clipboard.\r
+\r
+I have tested on emacs 23.4 and 24.3 on debian stable (ish) with all\r
+three possibilities for select-active-regions (note 'only was\r
+introduced in emacs 24 so is not relevant for emacs 23)\r
+\r
+Anyway, this is the best I can manage!\r
+\r
+Finally, note that I normally use emacs23 and this bug is not present\r
+there (unless the user has customised select-active-regions to t) so I\r
+have not given this patch a lot of testing.\r
+\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+ emacs/notmuch-mua.el | 19 +++++++++++++++++--\r
+ 1 files changed, 17 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index 53802d2..00cd980 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -346,10 +346,25 @@ the From: address first."\r
+ If PROMPT-FOR-SENDER is non-nil, the user will be prompted for\r
+ the From: address first. If REPLY-ALL is non-nil, the message\r
+ will be addressed to all recipients of the source message."\r
++\r
++;; In current emacs (24.3) select-active-regions is set to t by\r
++;; default. The reply insertion code sets the region to the quoted\r
++;; message to make it easy to delete (kill-region or C-w). These two\r
++;; things combine to put the quoted message in the primary selection.\r
++;;\r
++;; This is not what the user wanted and is a privacy risk (accidental\r
++;; pasting of the quoted message). We can avoid some of the problems\r
++;; by let-binding select-active-regions to nil. This fixes if the\r
++;; primary selection was previously in a non-emacs window but not if\r
++;; it was in an emacs window. To avoid the problem in the latter case\r
++;; we deactivate mark.\r
++\r
+ (let ((sender\r
+ (when prompt-for-sender\r
+- (notmuch-mua-prompt-for-sender))))\r
+- (notmuch-mua-reply query-string sender reply-all)))\r
++ (notmuch-mua-prompt-for-sender)))\r
++ (select-active-regions nil))\r
++ (notmuch-mua-reply query-string sender reply-all)\r
++ (deactivate-mark)))\r
+ \r
+ (defun notmuch-mua-send-and-exit (&optional arg)\r
+ (interactive "P")\r
+-- \r
+1.7.9.1\r
+\r