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