From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kCJbC1NZoWLSOgEAbAwnHQ (envelope-from ) for ; Thu, 09 Jun 2022 04:22:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id gBRCC1NZoWLP/wAA9RJhRA (envelope-from ) for ; Thu, 09 Jun 2022 04:22:11 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3B19322EA1 for ; Thu, 9 Jun 2022 04:22:10 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 5E2095F767; Thu, 9 Jun 2022 02:12:08 +0000 (UTC) Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by mail.notmuchmail.org (Postfix) with ESMTPS id 922F15F6B6 for ; Thu, 9 Jun 2022 02:12:05 +0000 (UTC) Received: from fencepost.gnu.org ([2001:470:142:3::e]:46504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nz7eU-0004RW-Sp; Wed, 08 Jun 2022 22:12:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=5Ran6JJ/uDOm68VYoSD3c5BUyE+y50W6by2xlHWn1uw=; b=mT9Xb6+vzRNX65 0AjMn68VC/flcyXZdXBrbLL2CEqUx9C+4rCGppN1TYv8ckfprdbI6KUhBFMzKQrbVvY/ksd8WnGYO IRksNs5ANMCYAKKmczURy5TNyN4cBE9yi4593pVR1g2jpW3zBL7EvL2PD5uqHR4tBl+1COQnfIgFv 55Tc4/FtooT8lH284+rVYlZ6f6ce3zDuU0WLJ6M/Rqdx820kRBadTI2KStF3WuWoxZ+6hStDene8B u9jlcdBuZKX9+YPBG/A5nS6SiMeh7sDbtNjErITllYVca/KrcY1tax/LbcfpUrBAnF8TrJAq/MfYa FSOISrI6aHRtSw+B7eEA==; Received: from cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net ([92.233.85.247]:45160 helo=rivendell.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nz7eU-0004Lg-En; Wed, 08 Jun 2022 22:12:02 -0400 From: jao To: notmuch@notmuchmail.org Subject: [PATCH v3] emacs: use message-dont-reply-to-names when composing replies Date: Thu, 9 Jun 2022 03:11:45 +0100 Message-Id: <20220609021145.323294-1-jao@gnu.org> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Message-ID-Hash: 5ZUKPPUU2D5PL23J75J5UK6RW3P3PCM6 X-Message-ID-Hash: 5ZUKPPUU2D5PL23J75J5UK6RW3P3PCM6 X-MailFrom: jao@gnu.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: jao X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1654741330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=rWRDzLEeFxWxfCfFG/VvnKfWhCNeKjCo6yjQYiuhpYw=; b=rqLVZ15PXMNPefOJjE/DvMIfz8tLK331kybcGvvlTLES54pXCJyFGV5nNbioiW/Ua61oZt d0CSRiuW36nfmSdTUXxX/yjwQlGrSbmDQF+IXH85OZ/UePePq0sKWVlWbihNuvWbet7/9p qZm0TmoTznPij8t3u8yuQzNK0fQVvgFO1ezxUvvmA2tBGMEpKKcqRnLdMwJZPTzI5svsOS S4btf6BT9kTMmsUKWRFPYwRTlIfLPZRaIWwdk5Vz17HHJL6Q26yicXX6EOnhhNvMKJZ8VU 4tJFCyy7A261T2AdBhlaacy0dHL304oGeGtLuQasfwXSo8Ex5xtMUXTOU8tKwg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654741330; a=rsa-sha256; cv=none; b=twaFFjBnN8yYLniwE7lthozsTIVzhSWycDbJ1d9y2Mhtn4V/ZJDjvUsjmrM9Im1O4yI00t DpUV/hbkwvnXBDBFw8DY/1rB26LaIzN1UsiL2b7JyIMrIRghBzzA6I8Y1gGVy0XWWkLwIc yiDqXQ74caeI6CH3/vO1Y6U4GeXFc1+lbGIF7N9vFmvvHbY9OFvKL0PiwYiWWjrAEkkXtJ frMVIn2x4vDXs2RFOqgvJh/sPlCZUGQ9yBg569eS1CFOa/QildgvKlbEK4pNbxExoRrlZ5 b9RcfPzJ5gsTyI7Qdnn5TiXi/U8QSunHDCc5PIkbnzodk1swB4XZF4RqgTntpw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=mT9Xb6+v; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 7.00 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=mT9Xb6+v; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 3B19322EA1 X-Spam-Score: 7.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: 5J1B2sc+dQhO notmuch-mua functions for replies now use the built-in customizable variable message-dont-reply-to-names with the same semantics as message-mode. --- This version of the patch addresses stylistic issues according to review Signed-off-by: jao --- doc/notmuch-emacs.rst | 9 ++++ emacs/notmuch-mua.el | 19 ++++++++ test/T454-emacs-dont-reply-names.sh | 76 +++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100755 test/T454-emacs-dont-reply-names.sh diff --git a/doc/notmuch-emacs.rst b/doc/notmuch-emacs.rst index 78528785..970cd7b7 100644 --- a/doc/notmuch-emacs.rst +++ b/doc/notmuch-emacs.rst @@ -493,6 +493,15 @@ Sending Mail :code:`compose-mail`. To use ``notmuch`` for this, customize this variable to the symbol :code:`notmuch-user-agent`. +:index:`message-dont-reply-to-names` + + When composing mail replies, Emacs's message mode uses the + variable :code:`message-dont-reply-to-names` to exclude + recipients matching a given collection of regular expressions + or satisfying an arbitrary predicate. Notmuch's MUA inherits + this standard mechanism and will honour your customization of + this variable. + Init File --------- diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index 0ae33127..0f9ef3c2 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -21,7 +21,10 @@ ;;; Code: +(eval-when-compile (require 'subr-x)) + (require 'message) +(require 'gmm-utils) (require 'mm-view) (require 'format-spec) @@ -382,6 +385,21 @@ instead of `message-mode' and SWITCH-FUNCTION is mandatory." (erase-buffer) (notmuch-message-mode))) +(defun notmuch-mua--remove-dont-reply-to-names () + (when-let* ((nr (if (functionp message-dont-reply-to-names) + message-dont-reply-to-names + (gmm-regexp-concat message-dont-reply-to-names))) + (nr-filter + (if (functionp nr) + (lambda (mail) (and (not (funcall nr mail)) mail)) + (lambda (mail) (and (not (string-match-p nr mail)) mail))))) + (dolist (header '("To" "Cc")) + (when-let ((v (message-fetch-field header))) + (let* ((tokens (mapcar #'string-trim (message-tokenize-header v))) + (good-tokens (delq nil (mapcar nr-filter tokens))) + (addr (and good-tokens (mapconcat #'identity good-tokens ", ")))) + (message-replace-header header addr)))))) + (defun notmuch-mua-mail (&optional to subject other-headers _continue switch-function yank-action send-actions return-action &rest ignored) @@ -422,6 +440,7 @@ moved to the \"To:\" header." (message-this-is-mail t)) (message-setup-1 headers yank-action send-actions return-action)) (notmuch-fcc-header-setup) + (notmuch-mua--remove-dont-reply-to-names) (message-sort-headers) (message-hide-headers) (set-buffer-modified-p nil) diff --git a/test/T454-emacs-dont-reply-names.sh b/test/T454-emacs-dont-reply-names.sh new file mode 100755 index 00000000..3a770177 --- /dev/null +++ b/test/T454-emacs-dont-reply-names.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +test_description="message-dont-reply-to-names in emacs replies" +. $(dirname "$0")/test-lib.sh || exit 1 +. $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1 + +EXPECTED=$NOTMUCH_SRCDIR/test/emacs-show.expected-output + +test_require_emacs + +add_email_corpus default + +test_begin_subtest "regular expression" +test_emacs '(let ((message-dont-reply-to-names "notmuchmail\\|noreply\\|harvard")) + (notmuch-mua-new-reply + "id:20091117203301.GV3165@dottiness.seas.harvard.edu" nil t) + (test-visible-output "OUTPUT-FULL.raw"))' + +notmuch_dir_sanitize < OUTPUT-FULL.raw > OUTPUT-FULL +head -6 OUTPUT-FULL > OUTPUT + +cat < EXPECTED +From: Notmuch Test Suite +To: Mikhail Gusarov +Subject: Re: [notmuch] Working with Maildir storage? +In-Reply-To: <20091117203301.GV3165@dottiness.seas.harvard.edu> +Fcc: MAIL_DIR/sent +--text follows this line-- +EOF + +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "predicate" +test_emacs '(let ((message-dont-reply-to-names + (lambda (m) (string-prefix-p "Mikhail" m)))) + (notmuch-mua-new-reply + "id:20091117203301.GV3165@dottiness.seas.harvard.edu" nil t) + (test-visible-output "OUTPUT-FULL-PRED.raw"))' + +notmuch_dir_sanitize < OUTPUT-FULL-PRED.raw > OUTPUT-FULL-PRED +head -7 OUTPUT-FULL-PRED > OUTPUT-PRED + +cat < EXPECTED-PRED +From: Notmuch Test Suite +To: Lars Kellogg-Stedman +Cc: notmuch@notmuchmail.org +Subject: Re: [notmuch] Working with Maildir storage? +In-Reply-To: <20091117203301.GV3165@dottiness.seas.harvard.edu> +Fcc: MAIL_DIR/sent +--text follows this line-- +EOF + +test_expect_equal_file EXPECTED-PRED OUTPUT-PRED + +test_begin_subtest "nil value" +test_emacs '(let ((message-dont-reply-to-names nil)) + (notmuch-mua-new-reply + "id:20091117203301.GV3165@dottiness.seas.harvard.edu" nil t) + (test-visible-output "OUTPUT-FULL-NIL.raw"))' + +notmuch_dir_sanitize < OUTPUT-FULL-NIL.raw > OUTPUT-FULL-NIL +head -7 OUTPUT-FULL-NIL > OUTPUT-NIL + +cat < EXPECTED-NIL +From: Notmuch Test Suite +To: Lars Kellogg-Stedman , Mikhail Gusarov +Cc: notmuch@notmuchmail.org +Subject: Re: [notmuch] Working with Maildir storage? +In-Reply-To: <20091117203301.GV3165@dottiness.seas.harvard.edu> +Fcc: MAIL_DIR/sent +--text follows this line-- +EOF + +test_expect_equal_file EXPECTED-NIL OUTPUT-NIL + +test_done -- 2.36.1