From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 063846DE0962 for ; Sun, 13 Nov 2016 06:09:03 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.059 X-Spam-Level: X-Spam-Status: No, score=0.059 tagged_above=-999 required=5 tests=[AWL=-0.071, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZTssVj1v4yOR for ; Sun, 13 Nov 2016 06:09:02 -0800 (PST) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by arlo.cworth.org (Postfix) with ESMTPS id 639A56DE0318 for ; Sun, 13 Nov 2016 06:08:58 -0800 (PST) Received: by mail-wm0-f67.google.com with SMTP id g23so8471526wme.1 for ; Sun, 13 Nov 2016 06:08:58 -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:in-reply-to:references; bh=q9y5ygDZnkNJBj5GtPPYh6ZLIGTAWigCPe+2omtbFVg=; b=EyKv4r+3z9D3y8YQf6pBpyiMIWhczZirkU/tHu852vVKpMAKMxzzs/S2uQpH9F6zj5 VjYWiIEYhQSCThRXjb+IcKyjRnyoIOBJDOl/vDk6fLAxCugudqIrToYx43BBStIsHkw/ DG/yuWOZDeuLsGo/VOdYEvDoiSN58Ys1lXrmv56HpyeajGoLsDmQ5r/Z8yysMaNLLLAy khzJojmCgoASN63RTLoRYJ6cHME0O4X1Vhxk4p0t9mcMPAK1ZhB4gdVw645X1dZWlcj0 V2SYnj571UldmbaVenIXoByuGn29XhjrSX4NewNRPcOQNdzLMKIw1N/qmzPGgHb54W98 epVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q9y5ygDZnkNJBj5GtPPYh6ZLIGTAWigCPe+2omtbFVg=; b=FJZwagaNVdbqUCjZkMYOr/S7C7npwT0xMMzO5KDu6QlNZfBJo/E686YjV8iAb++/dS V3QCcrHdZAHcZ+Q6TNSa/uGBd06GcmxwoMF6Wrtul2tt2ATyRuc7hMO7/wlW8I8WB5F2 4eoEhaTG1it20yGSNVRi1lePKS1Qz8XH+0EX6qOLL/GstRKG/QMJBlTWa/ymy7fikpbZ VkKHvjI6IJaQnNxjzXi/Fgt2ssKcl66VkXBT3hmfENInLLgnxeFrKPjAWnldRUBl4lg/ /7GWG0Q/qXrLXUWgASkBmqb41Zdvgjv7tJzwlDoOn5cYf3K96d64jEpI1Zf9bsjjlqAo aasA== X-Gm-Message-State: ABUngverepNEj3OTDRQEW9NdHwlT5wyKcXoQacZTeGGCW5zpoZOG+NdUWa5oXw6F/Xql3Q== X-Received: by 10.28.39.193 with SMTP id n184mr5809695wmn.72.1479046136799; Sun, 13 Nov 2016 06:08:56 -0800 (PST) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by smtp.gmail.com with ESMTPSA id u81sm22216720wmu.10.2016.11.13.06.08.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Nov 2016 06:08:56 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v7 3/4] emacs: check drafts for encryption tags before saving Date: Sun, 13 Nov 2016 14:08:49 +0000 Message-Id: <1479046130-2716-4-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1479046130-2716-1-git-send-email-markwalters1009@gmail.com> References: <1479046130-2716-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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, 13 Nov 2016 14:09:03 -0000 From: David Bremner In general the user may not want to save plaintext copies of messages that they are sending encrypted, so give them a chance to abort. --- emacs/notmuch-draft.el | 39 +++++++++++++++++++++++++++++++++++++++ test/T630-emacs-draft.sh | 13 +++++++++++++ 2 files changed, 52 insertions(+) diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el index b8a5e67..1fb049a 100644 --- a/emacs/notmuch-draft.el +++ b/emacs/notmuch-draft.el @@ -71,6 +71,21 @@ postponing and resuming a message." :type '(repeat string) :group 'notmuch-send) +(defcustom notmuch-draft-save-plaintext 'ask + "Should notmuch save/postpone in plaintext messages that seem + like they are intended to be sent encrypted +(i.e with an mml encryption tag in it)." + :type '(radio + (const :tag "Never" nil) + (const :tag "Ask every time" ask) + (const :tag "Always" t)) + :group 'notmuch-draft + :group 'notmuch-crypto) + +(defvar notmuch-draft-encryption-tag-regex + "<#\\(part encrypt\\|secure.*mode=.*encrypt>\\)" + "Regular expression matching mml tags indicating encryption of part or message") + (defvar notmuch-draft-id nil "Message-id of the most recent saved draft of this message") (make-variable-buffer-local 'notmuch-draft-id) @@ -103,6 +118,28 @@ Used when a new version is saved, or the message is sent." (goto-char (+ (match-beginning 0) 2)) (insert "!")))))) +(defun notmuch-draft--has-encryption-tag () + "Returns t if there is an mml secure tag." + (save-excursion + (message-goto-body) + (re-search-forward notmuch-draft-encryption-tag-regex nil 't))) + +(defun notmuch-draft--query-encryption () + "Checks if we should save a message that should be encrypted. + +`notmuch-draft-save-plaintext' controls the behaviour." + (case notmuch-draft-save-plaintext + ((ask) + (notmuch-draft--query-encryption) + (unless (yes-or-no-p "(Customize `notmuch-draft-save-plaintext' to avoid this warning) +This message contains mml tags that suggest it is intended to be encrypted. +Really save and index an unencrypted copy? ") + (error "Save aborted"))) + ((nil) + (error "Refusing to save draft with encryption tags (see `notmuch-draft-save-plaintext')")) + ((t) + (ignore)))) + (defun notmuch-draft--make-message-id () ;; message-make-message-id gives the id inside a "<" ">" pair, ;; but notmuch doesn't want that form, so remove them. @@ -115,6 +152,8 @@ This saves the current message in the database with tags `notmuch-draft-tags` (in addition to any default tags applied to newly inserted messages)." (interactive) + (when (notmuch-draft--has-encryption-tag) + (notmuch-draft--query-encryption)) (let ((id (notmuch-draft--make-message-id))) (with-temporary-notmuch-message-buffer ;; We insert a Date header and a Message-ID header, the former diff --git a/test/T630-emacs-draft.sh b/test/T630-emacs-draft.sh index e39690c..689ccfb 100755 --- a/test/T630-emacs-draft.sh +++ b/test/T630-emacs-draft.sh @@ -39,4 +39,17 @@ header_count=$(notmuch show --format=raw subject:draft-test-0003 | grep -c ^X-No body_count=$(notmuch notmuch show --format=raw subject:draft-test-0003 | grep -c '^\<#secure') test_expect_equal "$header_count,$body_count" "1,0" +test_begin_subtest "Refusing to save an encrypted draft" +test_emacs '(notmuch-mua-mail) + (message-goto-subject) + (insert "draft-test-0004") + (mml-secure-message-sign-encrypt) + (let ((notmuch-draft-save-plaintext nil)) + (notmuch-draft-save)) + (test-output)' +count1=$(notmuch count tag:draft) +count2=$(notmuch count subject:draft-test-0004) + +test_expect_equal "$count1,$count2" "3,0" + test_done -- 2.1.4