[PATCH] Make envelope-sender fully configurable.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Robin H. Johnson <robbat2@xxxxxxxxxx>

This patch makes envelope sender fully configurable, and also allows it to be
use with Net::SMTP instead of just the sendmail binary.

Signed-off-by: Robin H. Johnson <robbat2@xxxxxxxxxx>
---
 git-send-email.perl |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 2436aec..133a844 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -76,6 +76,8 @@ Options:
    --quiet	  Make git-send-email less verbose.  One line per email
                   should be all that is output.
 
+   --envelope-sender Specify the sender address used for the email envelope.
+
 EOT
 	exit(1);
 }
@@ -130,7 +132,8 @@ my $compose_filename = ".msg.$$";
 
 # Variables we fill in automatically, or via prompting:
 my (@to,@cc,@initial_cc,@bcclist,@xh,
-	$initial_reply_to,$initial_subject,@files,$from,$compose,$time);
+	$initial_reply_to,$initial_subject,@files,$from,$compose,$time,
+	$envelope_sender);
 
 # Behavior modification variables
 my ($chain_reply_to, $quiet, $suppress_from, $no_signed_off_cc,
@@ -169,6 +172,7 @@ my $rc = GetOptions("from=s" => \$from,
 		    "bcc=s" => \@bcclist,
 		    "chain-reply-to!" => \$chain_reply_to,
 		    "smtp-server=s" => \$smtp_server,
+		    "envelope-sender=s" => \$envelope_sender,
 		    "compose" => \$compose,
 		    "quiet" => \$quiet,
 		    "suppress-from" => \$suppress_from,
@@ -445,7 +449,10 @@ sub send_message
 		my ($name, $addr) = ($from =~ /^(.*?)(\s+<.*)/);
 		$from = "\"$name\"$addr";
 	}
-	my ($author_addr) = ($from =~ /^.*?\s+<(.*?)>/);
+	if(!defined $envelope_sender or -z $envelope_sender) {
+		$from =~ /^.*?\s+<(.*?)>/;
+		$envelope_sender = $1;
+	}
 	my $header = "From: $from
 To: $to
 Cc: $cc
@@ -463,9 +470,10 @@ X-Mailer: git-send-email $gitversion
 		$header .= join("\n", @xh) . "\n";
 	}
 	
-	my @sendmail_args = ('-f',$author_addr,'-i', map { extract_valid_address($_) } @recipients);
+	my @sendmail_args = ('-f',$envelope_sender,'-i', map { extract_valid_address($_) } @recipients);
 	if ($dry_run) {
 		# We don't want to send the email.
+		$smtp = !($smtp_server =~  m#^/#);
 	} elsif ($smtp_server =~ m#^/#) {
 		my $pid = open my $sm, '|-';
 		defined $pid or die $!;
@@ -477,7 +485,7 @@ X-Mailer: git-send-email $gitversion
 	} else {
 		require Net::SMTP;
 		$smtp ||= Net::SMTP->new( $smtp_server );
-		$smtp->mail( $from ) or die $smtp->message;
+		$smtp->mail( $envelope_sender ) or die $smtp->message;
 		$smtp->to( @recipients ) or die $smtp->message;
 		$smtp->data or die $smtp->message;
 		$smtp->datasend("$header\n$message") or die $smtp->message;
@@ -489,17 +497,15 @@ X-Mailer: git-send-email $gitversion
 	} else {
 		print "OK. Log says:\nDate: $date\n";
 		if ($smtp) {
-			print "Server: $smtp_server\n";
+			print "SMTP Server: $smtp_server\n";
+			print "SMTP MAIL FROM: $envelope_sender\n";
+			print "SMTP RCPT TO: ".join(', ',@recipients)."\n";
 		} else {
 			print "Sendmail: $smtp_server\n";
-			my $s = "";
-			foreach my $a (@sendmail_args) {
-				$s .= " \'".$a."\'";
-			}
-			print "Args:$s\n";
+			print "Args: '".join("' '",@sendmail_args)."'\n";
 		}
 		print "From: $from\nSubject: $subject\nCc: $cc\nTo: $to\n\n";
-		if ($smtp) {
+		if ($smtp and not $dry_run) {
 			print "Result: ", $smtp->code, ' ',
 				($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
 		} else {
@@ -616,7 +622,7 @@ sub cleanup_compose_files() {
 
 }
 
-$smtp->quit if $smtp;
+$smtp->quit if ($smtp and not $dry_run);
 
 sub unique_email_list(@) {
 	my %seen;
-- 
1.5.1

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]