@@ -177,11 +177,15 @@ sub format_2822_time {
177177my $re_encoded_word = qr / =\? ($re_token )\? ($re_token )\? ($re_encoded_text )\? =/ ;
178178
179179# Variables we fill in automatically, or via prompting:
180- my (@to ,$no_to , @initial_to , @ cc ,$no_cc , @initial_cc , @bcclist , $no_bcc , @xh ,
180+ my (@to ,@ cc ,@xh , $envelope_sender ,
181181 $initial_in_reply_to ,$reply_to ,$initial_subject ,@files ,
182- $author ,$sender ,$smtp_authpass ,$annotate ,$use_xmailer ,$compose ,$time );
183-
184- my $envelope_sender ;
182+ $author ,$sender ,$smtp_authpass ,$annotate ,$compose ,$time );
183+ # Things we either get from config, *or* are overridden on the
184+ # command-line.
185+ my ($no_cc , $no_to , $no_bcc , $no_identity );
186+ my (@config_to , @getopt_to );
187+ my (@config_cc , @getopt_cc );
188+ my (@config_bcc , @getopt_bcc );
185189
186190# Example reply to:
187191# $initial_in_reply_to = ''; #<[email protected] >';@@ -228,33 +232,37 @@ sub do_edit {
228232}
229233
230234# Variables with corresponding config settings
231- my ($thread , $chain_reply_to , $ suppress_from , $signed_off_by_cc );
235+ my ($suppress_from , $signed_off_by_cc );
232236my ($cover_cc , $cover_to );
233237my ($to_cmd , $cc_cmd );
234238my ($smtp_server , $smtp_server_port , @smtp_server_options );
235239my ($smtp_authuser , $smtp_encryption , $smtp_ssl_cert_path );
236240my ($batch_size , $relogin_delay );
237241my ($identity , $aliasfiletype , @alias_files , $smtp_domain , $smtp_auth );
238- my ($validate , $ confirm );
242+ my ($confirm );
239243my (@suppress_cc );
240244my ($auto_8bit_encoding );
241245my ($compose_encoding );
242- my $target_xfer_encoding = ' auto' ;
243-
246+ # Variables with corresponding config settings & hardcoded defaults
244247my ($debug_net_smtp ) = 0; # Net::SMTP, see send_message()
248+ my $thread = 1;
249+ my $chain_reply_to = 0;
250+ my $use_xmailer = 1;
251+ my $validate = 1;
252+ my $target_xfer_encoding = ' auto' ;
245253
246254my %config_bool_settings = (
247- " thread" => [ \$thread , 1] ,
248- " chainreplyto" => [ \$chain_reply_to , 0] ,
249- " suppressfrom" => [ \$suppress_from , undef ] ,
250- " signedoffbycc" => [ \$signed_off_by_cc , undef ] ,
251- " cccover" => [ \$cover_cc , undef ] ,
252- " tocover" => [ \$cover_to , undef ] ,
253- " signedoffcc" => [ \$signed_off_by_cc , undef ], # Deprecated
254- " validate" => [ \$validate , 1] ,
255- " multiedit" => [ \$multiedit , undef ] ,
256- " annotate" => [ \$annotate , undef ] ,
257- " xmailer" => [ \$use_xmailer , 1]
255+ " thread" => \$thread ,
256+ " chainreplyto" => \$chain_reply_to ,
257+ " suppressfrom" => \$suppress_from ,
258+ " signedoffbycc" => \$signed_off_by_cc ,
259+ " cccover" => \$cover_cc ,
260+ " tocover" => \$cover_to ,
261+ " signedoffcc" => \$signed_off_by_cc ,
262+ " validate" => \$validate ,
263+ " multiedit" => \$multiedit ,
264+ " annotate" => \$annotate ,
265+ " xmailer" => \$use_xmailer ,
258266);
259267
260268my %config_settings = (
@@ -267,12 +275,12 @@ sub do_edit {
267275 " smtpauth" => \$smtp_auth ,
268276 " smtpbatchsize" => \$batch_size ,
269277 " smtprelogindelay" => \$relogin_delay ,
270- " to" => \@initial_to ,
278+ " to" => \@config_to ,
271279 " tocmd" => \$to_cmd ,
272- " cc" => \@initial_cc ,
280+ " cc" => \@config_cc ,
273281 " cccmd" => \$cc_cmd ,
274282 " aliasfiletype" => \$aliasfiletype ,
275- " bcc" => \@bcclist ,
283+ " bcc" => \@config_bcc ,
276284 " suppresscc" => \@suppress_cc ,
277285 " envelopesender" => \$envelope_sender ,
278286 " confirm" => \$confirm ,
@@ -315,13 +323,87 @@ sub signal_handler {
315323$SIG {TERM } = \&signal_handler;
316324$SIG {INT } = \&signal_handler;
317325
326+ # Read our sendemail.* config
327+ sub read_config {
328+ my ($configured , $prefix ) = @_ ;
329+
330+ foreach my $setting (keys %config_bool_settings ) {
331+ my $target = $config_bool_settings {$setting };
332+ my $v = Git::config_bool(@repo , " $prefix .$setting " );
333+ next unless defined $v ;
334+ next if $configured -> {$setting }++;
335+ $$target = $v ;
336+ }
337+
338+ foreach my $setting (keys %config_path_settings ) {
339+ my $target = $config_path_settings {$setting };
340+ if (ref ($target ) eq " ARRAY" ) {
341+ my @values = Git::config_path(@repo , " $prefix .$setting " );
342+ next unless @values ;
343+ next if $configured -> {$setting }++;
344+ @$target = @values ;
345+ }
346+ else {
347+ my $v = Git::config_path(@repo , " $prefix .$setting " );
348+ next unless defined $v ;
349+ next if $configured -> {$setting }++;
350+ $$target = $v ;
351+ }
352+ }
353+
354+ foreach my $setting (keys %config_settings ) {
355+ my $target = $config_settings {$setting };
356+ if (ref ($target ) eq " ARRAY" ) {
357+ my @values = Git::config(@repo , " $prefix .$setting " );
358+ next unless @values ;
359+ next if $configured -> {$setting }++;
360+ @$target = @values ;
361+ }
362+ else {
363+ my $v = Git::config(@repo , " $prefix .$setting " );
364+ next unless defined $v ;
365+ next if $configured -> {$setting }++;
366+ $$target = $v ;
367+ }
368+ }
369+
370+ if (!defined $smtp_encryption ) {
371+ my $setting = " $prefix .smtpencryption" ;
372+ my $enc = Git::config(@repo , $setting );
373+ return unless defined $enc ;
374+ return if $configured -> {$setting }++;
375+ if (defined $enc ) {
376+ $smtp_encryption = $enc ;
377+ } elsif (Git::config_bool(@repo , " $prefix .smtpssl" )) {
378+ $smtp_encryption = ' ssl' ;
379+ }
380+ }
381+ }
382+
383+ # sendemail.identity yields to --identity. We must parse this
384+ # special-case first before the rest of the config is read.
385+ $identity = Git::config(@repo , " sendemail.identity" );
386+ my $rc = GetOptions(
387+ " identity=s" => \$identity ,
388+ " no-identity" => \$no_identity ,
389+ );
390+ usage() unless $rc ;
391+ undef $identity if $no_identity ;
392+
393+ # Now we know enough to read the config
394+ {
395+ my %configured ;
396+ read_config(\%configured , " sendemail.$identity " ) if defined $identity ;
397+ read_config(\%configured , " sendemail" );
398+ }
399+
318400# Begin by accumulating all the variables (defined above), that we will end up
319401# needing, first, from the command line:
320402
321403my $help ;
322404my $git_completion_helper ;
323- my $rc = GetOptions(" h" => \$help ,
324- " dump-aliases" => \$dump_aliases );
405+ $rc = GetOptions(" h" => \$help ,
406+ " dump-aliases" => \$dump_aliases );
325407usage() unless $rc ;
326408die __(" --dump-aliases incompatible with other options\n " )
327409 if !$help and $dump_aliases and @ARGV ;
@@ -330,12 +412,12 @@ sub signal_handler {
330412 " in-reply-to=s" => \$initial_in_reply_to ,
331413 " reply-to=s" => \$reply_to ,
332414 " subject=s" => \$initial_subject ,
333- " to=s" => \@initial_to ,
415+ " to=s" => \@getopt_to ,
334416 " to-cmd=s" => \$to_cmd ,
335417 " no-to" => \$no_to ,
336- " cc=s" => \@initial_cc ,
418+ " cc=s" => \@getopt_cc ,
337419 " no-cc" => \$no_cc ,
338- " bcc=s" => \@bcclist ,
420+ " bcc=s" => \@getopt_bcc ,
339421 " no-bcc" => \$no_bcc ,
340422 " chain-reply-to!" => \$chain_reply_to ,
341423 " no-chain-reply-to" => sub {$chain_reply_to = 0},
@@ -351,7 +433,6 @@ sub signal_handler {
351433 " smtp-domain:s" => \$smtp_domain ,
352434 " smtp-auth=s" => \$smtp_auth ,
353435 " no-smtp-auth" => sub {$smtp_auth = ' none' },
354- " identity=s" => \$identity ,
355436 " annotate!" => \$annotate ,
356437 " no-annotate" => sub {$annotate = 0},
357438 " compose" => \$compose ,
@@ -386,6 +467,11 @@ sub signal_handler {
386467 " git-completion-helper" => \$git_completion_helper ,
387468 );
388469
470+ # Munge any "either config or getopt, not both" variables
471+ my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to );
472+ my @initial_cc = @getopt_cc ? @getopt_cc : ($no_cc ? () : @config_cc );
473+ my @initial_bcc = @getopt_bcc ? @getopt_bcc : ($no_bcc ? () : @config_bcc );
474+
389475usage() if $help ;
390476completion_helper() if $git_completion_helper ;
391477unless ($rc ) {
@@ -399,65 +485,6 @@ sub signal_handler {
399485 " (via command-line or configuration option)\n " )
400486 if defined $relogin_delay and not defined $batch_size ;
401487
402- # Now, let's fill any that aren't set in with defaults:
403-
404- sub read_config {
405- my ($prefix ) = @_ ;
406-
407- foreach my $setting (keys %config_bool_settings ) {
408- my $target = $config_bool_settings {$setting }-> [0];
409- $$target = Git::config_bool(@repo , " $prefix .$setting " ) unless (defined $$target );
410- }
411-
412- foreach my $setting (keys %config_path_settings ) {
413- my $target = $config_path_settings {$setting };
414- if (ref ($target ) eq " ARRAY" ) {
415- unless (@$target ) {
416- my @values = Git::config_path(@repo , " $prefix .$setting " );
417- @$target = @values if (@values && defined $values [0]);
418- }
419- }
420- else {
421- $$target = Git::config_path(@repo , " $prefix .$setting " ) unless (defined $$target );
422- }
423- }
424-
425- foreach my $setting (keys %config_settings ) {
426- my $target = $config_settings {$setting };
427- next if $setting eq " to" and defined $no_to ;
428- next if $setting eq " cc" and defined $no_cc ;
429- next if $setting eq " bcc" and defined $no_bcc ;
430- if (ref ($target ) eq " ARRAY" ) {
431- unless (@$target ) {
432- my @values = Git::config(@repo , " $prefix .$setting " );
433- @$target = @values if (@values && defined $values [0]);
434- }
435- }
436- else {
437- $$target = Git::config(@repo , " $prefix .$setting " ) unless (defined $$target );
438- }
439- }
440-
441- if (!defined $smtp_encryption ) {
442- my $enc = Git::config(@repo , " $prefix .smtpencryption" );
443- if (defined $enc ) {
444- $smtp_encryption = $enc ;
445- } elsif (Git::config_bool(@repo , " $prefix .smtpssl" )) {
446- $smtp_encryption = ' ssl' ;
447- }
448- }
449- }
450-
451- # read configuration from [sendemail "$identity"], fall back on [sendemail]
452- $identity = Git::config(@repo , " sendemail.identity" ) unless (defined $identity );
453- read_config(" sendemail.$identity " ) if (defined $identity );
454- read_config(" sendemail" );
455-
456- # fall back on builtin bool defaults
457- foreach my $setting (values %config_bool_settings ) {
458- ${$setting -> [0]} = $setting -> [1] unless (defined (${$setting -> [0]}));
459- }
460-
461488# 'default' encryption is none -- this only prevents a warning
462489$smtp_encryption = ' ' unless (defined $smtp_encryption );
463490
@@ -941,7 +968,7 @@ sub expand_one_alias {
941968
942969@initial_to = process_address_list(@initial_to );
943970@initial_cc = process_address_list(@initial_cc );
944- @bcclist = process_address_list(@bcclist );
971+ @initial_bcc = process_address_list(@initial_bcc );
945972
946973if ($thread && !defined $initial_in_reply_to && $prompting ) {
947974 $initial_in_reply_to = ask(
@@ -1364,7 +1391,7 @@ sub send_message {
13641391 }
13651392 @cc );
13661393 my $to = join (" ,\n\t " , @recipients );
1367- @recipients = unique_email_list(@recipients ,@cc ,@bcclist );
1394+ @recipients = unique_email_list(@recipients ,@cc ,@initial_bcc );
13681395 @recipients = (map { extract_valid_address_or_die($_ ) } @recipients );
13691396 my $date = format_2822_time($time ++);
13701397 my $gitversion = ' @@GIT_VERSION@@' ;
0 commit comments