]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-send-email.perl
Makefile: Remove git-fsck and git-verify-pack from PROGRAMS
[thirdparty/git.git] / git-send-email.perl
index e4fe8965bbb305bcf569d354d3d8cc4f9fc084a3..eb876f88ddec315991c2634a976eca8e5b99a1ba 100755 (executable)
@@ -79,6 +79,8 @@ Options:
 
    --dry-run     Do everything except actually send the emails.
 
+   --envelope-sender   Specify the envelope sender used to send the emails.
+
 EOT
        exit(1);
 }
@@ -139,6 +141,7 @@ my (@to,@cc,@initial_cc,@bcclist,@xh,
 my ($chain_reply_to, $quiet, $suppress_from, $no_signed_off_cc,
        $dry_run) = (1, 0, 0, 0, 0);
 my $smtp_server;
+my $envelope_sender;
 
 # Example reply to:
 #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
@@ -151,8 +154,8 @@ if ($@) {
        $term = new FakeTerm "$@: going non-interactive";
 }
 
-my $def_chain = $repo->config_boolean('sendemail.chainreplyto');
-if ($def_chain and $def_chain eq 'false') {
+my $def_chain = $repo->config_bool('sendemail.chainreplyto');
+if (defined $def_chain and not $def_chain) {
     $chain_reply_to = 0;
 }
 
@@ -177,6 +180,7 @@ my $rc = GetOptions("from=s" => \$from,
                    "suppress-from" => \$suppress_from,
                    "no-signed-off-cc|no-signed-off-by-cc" => \$no_signed_off_cc,
                    "dry-run" => \$dry_run,
+                   "envelope-sender=s" => \$envelope_sender,
         );
 
 unless ($rc) {
@@ -208,7 +212,7 @@ my $aliasfiletype = $repo->config('sendemail.aliasfiletype');
 my %parse_alias = (
        # multiline formats can be supported in the future
        mutt => sub { my $fh = shift; while (<$fh>) {
-               if (/^alias\s+(\S+)\s+(.*)$/) {
+               if (/^\s*alias\s+(\S+)\s+(.*)$/) {
                        my ($alias, $addr) = ($1, $2);
                        $addr =~ s/#.*$//; # mutt allows # comments
                         # commas delimit multiple addresses
@@ -270,6 +274,7 @@ sub expand_aliases {
 }
 
 @to = expand_aliases(@to);
+@to = (map { sanitize_address_rfc822($_) } @to);
 @initial_cc = expand_aliases(@initial_cc);
 @bcclist = expand_aliases(@bcclist);
 
@@ -449,6 +454,7 @@ sub send_message
        @cc = (map { sanitize_address_rfc822($_) } @cc);
        my $to = join (",\n\t", @recipients);
        @recipients = unique_email_list(@recipients,@cc,@bcclist);
+       @recipients = (map { extract_valid_address($_) } @recipients);
        my $date = format_2822_time($time++);
        my $gitversion = '@@GIT_VERSION@@';
        if ($gitversion =~ m/..GIT_VERSION../) {
@@ -456,10 +462,13 @@ sub send_message
        }
 
        my $cc = join(", ", unique_email_list(@cc));
+       my $ccline = "";
+       if ($cc ne '') {
+               $ccline = "\nCc: $cc";
+       }
        $from = sanitize_address_rfc822($from);
        my $header = "From: $from
-To: $to
-Cc: $cc
+To: $to${ccline}
 Subject: $subject
 Date: $date
 Message-Id: $message_id
@@ -474,7 +483,12 @@ X-Mailer: git-send-email $gitversion
                $header .= join("\n", @xh) . "\n";
        }
 
-       my @sendmail_parameters = ('-i', map { extract_valid_address($_) } @recipients);
+       my @sendmail_parameters = ('-i', @recipients);
+       my $raw_from = $from;
+       $raw_from = $envelope_sender if (defined $envelope_sender);
+       $raw_from = extract_valid_address($raw_from);
+       unshift (@sendmail_parameters,
+                       '-f', $raw_from) if(defined $envelope_sender);
 
        if ($dry_run) {
                # We don't want to send the email.
@@ -489,7 +503,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( $raw_from ) 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;
@@ -500,10 +514,10 @@ X-Mailer: git-send-email $gitversion
                printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject);
        } else {
                print (($dry_run ? "Dry-" : "")."OK. Log says:\nDate: $date\n");
-               if ($smtp) {
+               if ($smtp_server !~ m#^/#) {
                        print "Server: $smtp_server\n";
-                       print "MAIL FROM: $from\n";
-                       print "RCPT TO: ".join(',',@recipients)."\n";
+                       print "MAIL FROM:<$raw_from>\n";
+                       print "RCPT TO:".join(',',(map { "<$_>" } @recipients))."\n";
                } else {
                        print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n";
                }