@@ -792,7 +792,19 @@ sub is_format_patch_arg {
792
792
@rev_list_opts );
793
793
}
794
794
795
- @files = handle_backup_files(@files );
795
+ if (defined $sender ) {
796
+ $sender =~ s / ^\s +|\s +$// g ;
797
+ ($sender ) = expand_aliases($sender );
798
+ } else {
799
+ $sender = $repoauthor -> () || $repocommitter -> () || ' ' ;
800
+ }
801
+
802
+ # $sender could be an already sanitized address
803
+ # (e.g. sendemail.from could be manually sanitized by user).
804
+ # But it's a no-op to run sanitize_address on an already sanitized address.
805
+ $sender = sanitize_address($sender );
806
+
807
+ $time = time - scalar $#files ;
796
808
797
809
if ($validate ) {
798
810
# FIFOs can only be read once, exclude them from validation.
@@ -810,13 +822,16 @@ sub is_format_patch_arg {
810
822
$ENV {GIT_SENDEMAIL_FILE_TOTAL } = " $num_files " ;
811
823
foreach my $r (@real_files ) {
812
824
$ENV {GIT_SENDEMAIL_FILE_COUNTER } = " $num " ;
825
+ pre_process_file($r , 1);
813
826
validate_patch($r , $target_xfer_encoding );
814
827
$num += 1;
815
828
}
816
829
delete $ENV {GIT_SENDEMAIL_FILE_COUNTER };
817
830
delete $ENV {GIT_SENDEMAIL_FILE_TOTAL };
818
831
}
819
832
833
+ @files = handle_backup_files(@files );
834
+
820
835
if (@files ) {
821
836
unless ($quiet ) {
822
837
print $_ ," \n " for (@files );
@@ -1065,18 +1080,6 @@ sub file_declares_8bit_cte {
1065
1080
}
1066
1081
}
1067
1082
1068
- if (defined $sender) {
1069
- $sender =~ s/^\s+|\s+$//g;
1070
- ($sender) = expand_aliases($sender);
1071
- } else {
1072
- $sender = $repoauthor->() || $repocommitter->() || ' ' ;
1073
- }
1074
-
1075
- # $sender could be an already sanitized address
1076
- # (e.g. sendemail.from could be manually sanitized by user).
1077
- # But it' s a no -op to run sanitize_address on an already sanitized address.
1078
- $sender = sanitize_address($sender );
1079
-
1080
1083
my $to_whom = __("To whom should the emails be sent (if anyone)?");
1081
1084
my $prompting = 0;
1082
1085
if (!@initial_to && !defined $to_cmd) {
@@ -1236,10 +1239,6 @@ sub make_message_id {
1236
1239
# print "new message id = $message_id\n"; # Was useful for debugging
1237
1240
}
1238
1241
1239
-
1240
-
1241
- $time = time - scalar $#files ;
1242
-
1243
1242
sub unquote_rfc2047 {
1244
1243
local ($_ ) = @_ ;
1245
1244
my $charset ;
@@ -1517,16 +1516,7 @@ sub file_name_is_absolute {
1517
1516
return File::Spec::Functions::file_name_is_absolute($path );
1518
1517
}
1519
1518
1520
- # Prepares the email, then asks the user what to do.
1521
- #
1522
- # If the user chooses to send the email, it's sent and 1 is returned.
1523
- # If the user chooses not to send the email, 0 is returned.
1524
- # If the user decides they want to make further edits, -1 is returned and the
1525
- # caller is expected to call send_message again after the edits are performed.
1526
- #
1527
- # If an error occurs sending the email, this just dies.
1528
-
1529
- sub send_message {
1519
+ sub gen_header {
1530
1520
my @recipients = unique_email_list(@to );
1531
1521
@cc = (grep { my $cc = extract_valid_address_or_die($_ );
1532
1522
not grep { $cc eq $_ || $_ =~ / <\Q ${cc} \E >$ / } @recipients
@@ -1568,6 +1558,22 @@ sub send_message {
1568
1558
if (@xh ) {
1569
1559
$header .= join (" \n " , @xh ) . " \n " ;
1570
1560
}
1561
+ my $recipients_ref = \@recipients ;
1562
+ return ($recipients_ref , $to , $date , $gitversion , $cc , $ccline , $header );
1563
+ }
1564
+
1565
+ # Prepares the email, then asks the user what to do.
1566
+ #
1567
+ # If the user chooses to send the email, it's sent and 1 is returned.
1568
+ # If the user chooses not to send the email, 0 is returned.
1569
+ # If the user decides they want to make further edits, -1 is returned and the
1570
+ # caller is expected to call send_message again after the edits are performed.
1571
+ #
1572
+ # If an error occurs sending the email, this just dies.
1573
+
1574
+ sub send_message {
1575
+ my ($recipients_ref , $to , $date , $gitversion , $cc , $ccline , $header ) = gen_header();
1576
+ my @recipients = @$recipients_ref ;
1571
1577
1572
1578
my @sendmail_parameters = (' -i' , @recipients );
1573
1579
my $raw_from = $sender ;
@@ -1757,11 +1763,8 @@ sub send_message {
1757
1763
$references = $initial_in_reply_to || ' ' ;
1758
1764
$message_num = 0;
1759
1765
1760
- # Prepares the email, prompts the user, sends it out
1761
- # Returns 0 if an edit was done and the function should be called again, or 1
1762
- # otherwise.
1763
- sub process_file {
1764
- my ($t ) = @_ ;
1766
+ sub pre_process_file {
1767
+ my ($t , $quiet ) = @_ ;
1765
1768
1766
1769
open my $fh , " <" , $t or die sprintf (__(" can't open file %s " ), $t );
1767
1770
@@ -1915,9 +1918,9 @@ sub process_file {
1915
1918
}
1916
1919
close $fh ;
1917
1920
1918
- push @to , recipients_cmd(" to-cmd" , " to" , $to_cmd , $t )
1921
+ push @to , recipients_cmd(" to-cmd" , " to" , $to_cmd , $t , $quiet )
1919
1922
if defined $to_cmd ;
1920
- push @cc , recipients_cmd(" cc-cmd" , " cc" , $cc_cmd , $t )
1923
+ push @cc , recipients_cmd(" cc-cmd" , " cc" , $cc_cmd , $t , $quiet )
1921
1924
if defined $cc_cmd && !$suppress_cc {' cccmd' };
1922
1925
1923
1926
if ($broken_encoding {$t } && !$has_content_type ) {
@@ -1976,6 +1979,15 @@ sub process_file {
1976
1979
@initial_to = @to ;
1977
1980
}
1978
1981
}
1982
+ }
1983
+
1984
+ # Prepares the email, prompts the user, and sends it out
1985
+ # Returns 0 if an edit was done and the function should be called again, or 1
1986
+ # on the email being successfully sent out.
1987
+ sub process_file {
1988
+ my ($t ) = @_ ;
1989
+
1990
+ pre_process_file($t , $quiet );
1979
1991
1980
1992
my $message_was_sent = send_message();
1981
1993
if ($message_was_sent == -1) {
@@ -2024,7 +2036,7 @@ sub process_file {
2024
2036
# Execute a command (e.g. $to_cmd) to get a list of email addresses
2025
2037
# and return a results array
2026
2038
sub recipients_cmd {
2027
- my ($prefix , $what , $cmd , $file ) = @_ ;
2039
+ my ($prefix , $what , $cmd , $file , $quiet ) = @_ ;
2028
2040
2029
2041
my @addresses = ();
2030
2042
open my $fh , " -|" , " $cmd \Q $file \E "
@@ -2110,10 +2122,21 @@ sub validate_patch {
2110
2122
chdir ($repo -> wc_path() or $repo -> repo_path())
2111
2123
or die (" chdir: $! " );
2112
2124
local $ENV {" GIT_DIR" } = $repo -> repo_path();
2125
+
2126
+ my ($recipients_ref , $to , $date , $gitversion , $cc , $ccline , $header ) = gen_header();
2127
+
2128
+ require File::Temp;
2129
+ my ($header_filehandle , $header_filename ) = File::Temp::tempfile(
2130
+ TEMPLATE => " .gitsendemail.header.XXXXXX" ,
2131
+ DIR => $repo -> repo_path(),
2132
+ UNLINK => 1,
2133
+ );
2134
+ print $header_filehandle $header ;
2135
+
2113
2136
my @cmd = (" git" , " hook" , " run" , " --ignore-missing" ,
2114
2137
$hook_name , " --" );
2115
- my @cmd_msg = (@cmd , " <patch>" );
2116
- my @cmd_run = (@cmd , $target );
2138
+ my @cmd_msg = (@cmd , " <patch>" , " <header> " );
2139
+ my @cmd_run = (@cmd , $target , $header_filename );
2117
2140
$hook_error = system_or_msg(\@cmd_run , undef , " @cmd_msg " );
2118
2141
chdir ($cwd_save ) or die (" chdir: $! " );
2119
2142
}
0 commit comments