git-svn: t/t91??-*: optimize the tests a bit
[gitweb.git] / git-send-email.perl
index 04c89422523a9272bd1ba9c3020cb12db0018cfa..ba39d393843733b46f309deb105c90cabcee2cb1 100755 (executable)
@@ -83,7 +83,7 @@ sub format_2822_time {
 my $compose_filename = ".msg.$$";
 
 # Variables we fill in automatically, or via prompting:
-my (@to,@cc,@initial_cc,@bcclist,
+my (@to,@cc,@initial_cc,@bcclist,@xh,
        $initial_reply_to,$initial_subject,@files,$from,$compose,$time);
 
 # Behavior modification variables
@@ -178,11 +178,10 @@ sub format_2822_time {
 if (!defined $from) {
        $from = $author || $committer;
        do {
-               $_ = $term->readline("Who should the emails appear to be from? ",
-                       $from);
+               $_ = $term->readline("Who should the emails appear to be from? [$from] ");
        } while (!defined $_);
 
-       $from = $_;
+       $from = $_ if ($_);
        print "Emails will be sent from: ", $from, "\n";
        $prompting++;
 }
@@ -230,6 +229,9 @@ sub expand_aliases {
        $initial_reply_to =~ s/(^\s+|\s+$)//g;
 }
 
+if (!$smtp_server) {
+       $smtp_server = $repo->config('sendemail.smtpserver');
+}
 if (!$smtp_server) {
        foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {
                if (-x $_) {
@@ -411,6 +413,11 @@ sub send_message
            $gitversion = Git::version();
        }
 
+       my ($author_name) = ($from =~ /^(.*?)\s+</);
+       if ($author_name && $author_name =~ /\./ && $author_name !~ /^".*"$/) {
+               my ($name, $addr) = ($from =~ /^(.*?)(\s+<.*)/);
+               $from = "\"$name\"$addr";
+       }
        my $header = "From: $from
 To: $to
 Cc: $cc
@@ -424,6 +431,9 @@ sub send_message
                $header .= "In-Reply-To: $reply_to\n";
                $header .= "References: $references\n";
        }
+       if (@xh) {
+               $header .= join("\n", @xh) . "\n";
+       }
 
        if ($dry_run) {
                # We don't want to send the email.
@@ -476,15 +486,22 @@ sub send_message
 
        my $author_not_sender = undef;
        @cc = @initial_cc;
-       my $found_mbox = 0;
+       @xh = ();
+       my $input_format = undef;
        my $header_done = 0;
        $message = "";
        while(<F>) {
                if (!$header_done) {
-                       $found_mbox = 1, next if (/^From /);
+                       if (/^From /) {
+                               $input_format = 'mbox';
+                               next;
+                       }
                        chomp;
+                       if (!defined $input_format && /^[-A-Za-z]+:\s/) {
+                               $input_format = 'mbox';
+                       }
 
-                       if ($found_mbox) {
+                       if (defined $input_format && $input_format eq 'mbox') {
                                if (/^Subject:\s+(.*)$/) {
                                        $subject = $1;
 
@@ -499,6 +516,9 @@ sub send_message
                                                $2, $_) unless $quiet;
                                        push @cc, $2;
                                }
+                               elsif (!/^Date:\s/ && /^[-A-Za-z]+:\s+\S/) {
+                                       push @xh, $_;
+                               }
 
                        } else {
                                # In the traditional
@@ -506,6 +526,7 @@ sub send_message
                                # line 1 = cc
                                # line 2 = subject
                                # So let's support that, too.
+                               $input_format = 'lots';
                                if (@cc == 0) {
                                        printf("(non-mbox) Adding cc: %s from line '%s'\n",
                                                $_, $_) unless $quiet;