]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-send-email.perl
Merge branch 'tz/send-email-helpfix'
[thirdparty/git.git] / git-send-email.perl
index 2adaa359386c3b39190b2197399d47bc9c6fd93a..d24e981d611116aa2fabac09697a4532c8081c00 100755 (executable)
@@ -28,8 +28,8 @@ Getopt::Long::Configure qw/ pass_through /;
 
 sub usage {
        print <<EOT;
-git send-email' [<options>] <file|directory>
-git send-email' [<options>] <format-patch options>
+git send-email [<options>] <file|directory>
+git send-email [<options>] <format-patch options>
 git send-email --dump-aliases
 
   Composing:
@@ -799,30 +799,6 @@ $sender = sanitize_address($sender);
 
 $time = time - scalar $#files;
 
-if ($validate) {
-       # FIFOs can only be read once, exclude them from validation.
-       my @real_files = ();
-       foreach my $f (@files) {
-               unless (-p $f) {
-                       push(@real_files, $f);
-               }
-       }
-
-       # Run the loop once again to avoid gaps in the counter due to FIFO
-       # arguments provided by the user.
-       my $num = 1;
-       my $num_files = scalar @real_files;
-       $ENV{GIT_SENDEMAIL_FILE_TOTAL} = "$num_files";
-       foreach my $r (@real_files) {
-               $ENV{GIT_SENDEMAIL_FILE_COUNTER} = "$num";
-               pre_process_file($r, 1);
-               validate_patch($r, $target_xfer_encoding);
-               $num += 1;
-       }
-       delete $ENV{GIT_SENDEMAIL_FILE_COUNTER};
-       delete $ENV{GIT_SENDEMAIL_FILE_TOTAL};
-}
-
 @files = handle_backup_files(@files);
 
 if (@files) {
@@ -861,6 +837,9 @@ if ($compose) {
        my $tpl_subject = $initial_subject || '';
        my $tpl_in_reply_to = $initial_in_reply_to || '';
        my $tpl_reply_to = $reply_to || '';
+       my $tpl_to = join(',', @initial_to);
+       my $tpl_cc = join(',', @initial_cc);
+       my $tpl_bcc = join(', ', @initial_bcc);
 
        print $c <<EOT1, Git::prefix_lines("GIT: ", __(<<EOT2)), <<EOT3;
 From $tpl_sender # This line is ignored.
@@ -872,6 +851,9 @@ for the patch you are writing.
 Clear the body content if you don't wish to send a summary.
 EOT2
 From: $tpl_sender
+To: $tpl_to
+Cc: $tpl_cc
+Bcc: $tpl_bcc
 Reply-To: $tpl_reply_to
 Subject: $tpl_subject
 In-Reply-To: $tpl_in_reply_to
@@ -928,8 +910,14 @@ EOT3
                } elsif (/^From:\s*(.+)\s*$/i) {
                        $sender = $1;
                        next;
-               } elsif (/^(?:To|Cc|Bcc):/i) {
-                       print __("To/Cc/Bcc fields are not interpreted yet, they have been ignored\n");
+               } elsif (/^To:\s*(.+)\s*$/i) {
+                       @initial_to = parse_address_line($1);
+                       next;
+               } elsif (/^Cc:\s*(.+)\s*$/i) {
+                       @initial_cc = parse_address_line($1);
+                       next;
+               } elsif (/^Bcc:/i) {
+                       @initial_bcc = parse_address_line($1);
                        next;
                }
                print $c2 $_;
@@ -1126,10 +1114,10 @@ sub extract_valid_address {
 
 sub extract_valid_address_or_die {
        my $address = shift;
-       $address = extract_valid_address($address);
+       my $valid_address = extract_valid_address($address);
        die sprintf(__("error: unable to extract a valid address from: %s\n"), $address)
-               if !$address;
-       return $address;
+               if !$valid_address;
+       return $valid_address;
 }
 
 sub validate_address {
@@ -1714,10 +1702,6 @@ EOF
        return 1;
 }
 
-$in_reply_to = $initial_in_reply_to;
-$references = $initial_in_reply_to || '';
-$message_num = 0;
-
 sub pre_process_file {
        my ($t, $quiet) = @_;
 
@@ -1983,6 +1967,38 @@ sub process_file {
        return 1;
 }
 
+sub initialize_modified_loop_vars {
+       $in_reply_to = $initial_in_reply_to;
+       $references = $initial_in_reply_to || '';
+       $message_num = 0;
+}
+
+if ($validate) {
+       # FIFOs can only be read once, exclude them from validation.
+       my @real_files = ();
+       foreach my $f (@files) {
+               unless (-p $f) {
+                       push(@real_files, $f);
+               }
+       }
+
+       # Run the loop once again to avoid gaps in the counter due to FIFO
+       # arguments provided by the user.
+       my $num = 1;
+       my $num_files = scalar @real_files;
+       $ENV{GIT_SENDEMAIL_FILE_TOTAL} = "$num_files";
+       initialize_modified_loop_vars();
+       foreach my $r (@real_files) {
+               $ENV{GIT_SENDEMAIL_FILE_COUNTER} = "$num";
+               pre_process_file($r, 1);
+               validate_patch($r, $target_xfer_encoding);
+               $num += 1;
+       }
+       delete $ENV{GIT_SENDEMAIL_FILE_COUNTER};
+       delete $ENV{GIT_SENDEMAIL_FILE_TOTAL};
+}
+
+initialize_modified_loop_vars();
 foreach my $t (@files) {
        while (!process_file($t)) {
                # user edited the file