diff mbox series

send-email: Add an option to suppress adding a specific email address

Message ID 87ftp6j9ic.fsf@xmission.com (mailing list archive)
State New, archived
Headers show
Series send-email: Add an option to suppress adding a specific email address | expand

Commit Message

Eric W. Biederman May 23, 2019, 12:32 a.m. UTC
Make it easy to suppress stable@vger.kernel.org.  Long story short it
is desirable to have ``Cc: stable@vger.kernel.org'' on many bug fixes
sent to the linux kernel.  It is not always desirable to actually the
stable maintainer immediately as the patches are still being reviewed
etc.  Actually cc'd the stable maintainers in the linux kernel is not
even really necessary as they will always find the tag after the patch
has been merged in the commit body.

So I am adding yet another suppress command "suppress-addr" that will
take an email address keep that email address from being automatically
added to a destination the email will be sent to.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 Documentation/git-send-email.txt |  5 +++++
 git-send-email.perl              | 20 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 1afe9fc858ea..9833d4dbd9f4 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -346,6 +346,11 @@  Default is the value of `sendemail.suppresscc` configuration value; if
 that is unspecified, default to 'self' if --suppress-from is
 specified, as well as 'body' if --no-signed-off-cc is specified.
 
+--suppress-addr=<address>::
+	Specify an address that should not be automatically copied
+	on any email.
+	Default is the value of `sendemail.suppressaddr`.
+
 --[no-]suppress-from::
 	If this is set, do not add the From: address to the cc: list.
 	Default is the value of `sendemail.suppressFrom` configuration
diff --git a/git-send-email.perl b/git-send-email.perl
index 8eb63b5a2f8d..2ac0985f3f00 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -98,6 +98,7 @@  sub usage {
     --to-cmd                <str>  * Email To: via `<str> \$patch_path`
     --cc-cmd                <str>  * Email Cc: via `<str> \$patch_path`
     --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, misc-by, all.
+    --suppress-addr         <str>  * Don't automatically add the specified address
     --[no-]cc-cover                * Email Cc: addresses in the cover letter.
     --[no-]to-cover                * Email To: addresses in the cover letter.
     --[no-]signed-off-by-cc        * Send to Signed-off-by: addresses. Default on.
@@ -237,6 +238,7 @@  sub do_edit {
 my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
 my ($validate, $confirm);
 my (@suppress_cc);
+my (@suppress_addr);
 my ($auto_8bit_encoding);
 my ($compose_encoding);
 my $target_xfer_encoding = 'auto';
@@ -274,6 +276,7 @@  sub do_edit {
     "aliasfiletype" => \$aliasfiletype,
     "bcc" => \@bcclist,
     "suppresscc" => \@suppress_cc,
+    "suppressaddr" => \@suppress_addr,
     "envelopesender" => \$envelope_sender,
     "confirm"   => \$confirm,
     "from" => \$sender,
@@ -360,6 +363,7 @@  sub signal_handler {
 		    "suppress-from!" => \$suppress_from,
 		    "no-suppress-from" => sub {$suppress_from = 0},
 		    "suppress-cc=s" => \@suppress_cc,
+		    "suppress-addr=s" => \@suppress_addr,
 		    "signed-off-cc|signed-off-by-cc!" => \$signed_off_by_cc,
 		    "no-signed-off-cc|no-signed-off-by-cc" => sub {$signed_off_by_cc = 0},
 		    "cc-cover|cc-cover!" => \$cover_cc,
@@ -489,6 +493,16 @@  sub read_config {
 	delete $suppress_cc{'body'};
 }
 
+# Set specific suppress addresses
+my (%suppress_addr);
+if (@suppress_addr) {
+	foreach my $addr (@suppress_addr) {
+		my $qaddr = unquote_rfc2047($addr);
+		my $saddr = sanitize_address($qaddr);
+		$suppress_addr{$saddr} = 1;
+	}
+}
+
 # Set confirm's default value
 my $confirm_unconfigured = !defined $confirm;
 if ($confirm_unconfigured) {
@@ -1623,6 +1637,7 @@  sub process_file {
 				$sauthor = sanitize_address($author);
 				next if $suppress_cc{'author'};
 				next if $suppress_cc{'self'} and $sauthor eq $sender;
+				next if ($suppress_addr{$sauthor});
 				printf(__("(mbox) Adding cc: %s from line '%s'\n"),
 					$1, $_) unless $quiet;
 				push @cc, $1;
@@ -1642,6 +1657,7 @@  sub process_file {
 						next if ($suppress_cc{'self'});
 					} else {
 						next if ($suppress_cc{'cc'});
+						next if ($suppress_addr{$saddr});
 					}
 					printf(__("(mbox) Adding cc: %s from line '%s'\n"),
 						$addr, $_) unless $quiet;
@@ -1681,7 +1697,7 @@  sub process_file {
 			# line 2 = subject
 			# So let's support that, too.
 			$input_format = 'lots';
-			if (@cc == 0 && !$suppress_cc{'cc'}) {
+			if (@cc == 0 && !$suppress_cc{'cc'} && !$suppress_addr{$_}) {
 				printf(__("(non-mbox) Adding cc: %s from line '%s'\n"),
 					$_, $_) unless $quiet;
 				push @cc, $_;
@@ -1700,6 +1716,7 @@  sub process_file {
 			$c = strip_garbage_one_address($c);
 			# sanitize a bit more to decide whether to suppress the address:
 			my $sc = sanitize_address($c);
+			next if ($suppress_addr{$sc});
 			if ($sc eq $sender) {
 				next if ($suppress_cc{'self'});
 			} else {
@@ -1833,6 +1850,7 @@  sub recipients_cmd {
 		$address =~ s/^\s*//g;
 		$address =~ s/\s*$//g;
 		$address = sanitize_address($address);
+		next if ($suppress_addr{$address});
 		next if ($address eq $sender and $suppress_cc{'self'});
 		push @addresses, $address;
 		printf(__("(%s) Adding %s: %s from: '%s'\n"),