@@ -177,11 +177,15 @@ sub format_2822_time {
177
177
my $re_encoded_word = qr / =\? ($re_token )\? ($re_token )\? ($re_encoded_text )\? =/ ;
178
178
179
179
# 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 ,
181
181
$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 );
185
189
186
190
# Example reply to:
187
191
# $initial_in_reply_to = ''; #<[email protected] >';
@@ -228,33 +232,37 @@ sub do_edit {
228
232
}
229
233
230
234
# 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 );
232
236
my ($cover_cc , $cover_to );
233
237
my ($to_cmd , $cc_cmd );
234
238
my ($smtp_server , $smtp_server_port , @smtp_server_options );
235
239
my ($smtp_authuser , $smtp_encryption , $smtp_ssl_cert_path );
236
240
my ($batch_size , $relogin_delay );
237
241
my ($identity , $aliasfiletype , @alias_files , $smtp_domain , $smtp_auth );
238
- my ($validate , $ confirm );
242
+ my ($confirm );
239
243
my (@suppress_cc );
240
244
my ($auto_8bit_encoding );
241
245
my ($compose_encoding );
242
- my $target_xfer_encoding = ' auto' ;
243
-
246
+ # Variables with corresponding config settings & hardcoded defaults
244
247
my ($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' ;
245
253
246
254
my %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 ,
258
266
);
259
267
260
268
my %config_settings = (
@@ -267,12 +275,12 @@ sub do_edit {
267
275
" smtpauth" => \$smtp_auth ,
268
276
" smtpbatchsize" => \$batch_size ,
269
277
" smtprelogindelay" => \$relogin_delay ,
270
- " to" => \@initial_to ,
278
+ " to" => \@config_to ,
271
279
" tocmd" => \$to_cmd ,
272
- " cc" => \@initial_cc ,
280
+ " cc" => \@config_cc ,
273
281
" cccmd" => \$cc_cmd ,
274
282
" aliasfiletype" => \$aliasfiletype ,
275
- " bcc" => \@bcclist ,
283
+ " bcc" => \@config_bcc ,
276
284
" suppresscc" => \@suppress_cc ,
277
285
" envelopesender" => \$envelope_sender ,
278
286
" confirm" => \$confirm ,
@@ -315,13 +323,87 @@ sub signal_handler {
315
323
$SIG {TERM } = \&signal_handler;
316
324
$SIG {INT } = \&signal_handler;
317
325
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
+
318
400
# Begin by accumulating all the variables (defined above), that we will end up
319
401
# needing, first, from the command line:
320
402
321
403
my $help ;
322
404
my $git_completion_helper ;
323
- my $rc = GetOptions(" h" => \$help ,
324
- " dump-aliases" => \$dump_aliases );
405
+ $rc = GetOptions(" h" => \$help ,
406
+ " dump-aliases" => \$dump_aliases );
325
407
usage() unless $rc ;
326
408
die __(" --dump-aliases incompatible with other options\n " )
327
409
if !$help and $dump_aliases and @ARGV ;
@@ -330,12 +412,12 @@ sub signal_handler {
330
412
" in-reply-to=s" => \$initial_in_reply_to ,
331
413
" reply-to=s" => \$reply_to ,
332
414
" subject=s" => \$initial_subject ,
333
- " to=s" => \@initial_to ,
415
+ " to=s" => \@getopt_to ,
334
416
" to-cmd=s" => \$to_cmd ,
335
417
" no-to" => \$no_to ,
336
- " cc=s" => \@initial_cc ,
418
+ " cc=s" => \@getopt_cc ,
337
419
" no-cc" => \$no_cc ,
338
- " bcc=s" => \@bcclist ,
420
+ " bcc=s" => \@getopt_bcc ,
339
421
" no-bcc" => \$no_bcc ,
340
422
" chain-reply-to!" => \$chain_reply_to ,
341
423
" no-chain-reply-to" => sub {$chain_reply_to = 0},
@@ -351,7 +433,6 @@ sub signal_handler {
351
433
" smtp-domain:s" => \$smtp_domain ,
352
434
" smtp-auth=s" => \$smtp_auth ,
353
435
" no-smtp-auth" => sub {$smtp_auth = ' none' },
354
- " identity=s" => \$identity ,
355
436
" annotate!" => \$annotate ,
356
437
" no-annotate" => sub {$annotate = 0},
357
438
" compose" => \$compose ,
@@ -386,6 +467,11 @@ sub signal_handler {
386
467
" git-completion-helper" => \$git_completion_helper ,
387
468
);
388
469
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
+
389
475
usage() if $help ;
390
476
completion_helper() if $git_completion_helper ;
391
477
unless ($rc ) {
@@ -399,65 +485,6 @@ sub signal_handler {
399
485
" (via command-line or configuration option)\n " )
400
486
if defined $relogin_delay and not defined $batch_size ;
401
487
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
-
461
488
# 'default' encryption is none -- this only prevents a warning
462
489
$smtp_encryption = ' ' unless (defined $smtp_encryption );
463
490
@@ -941,7 +968,7 @@ sub expand_one_alias {
941
968
942
969
@initial_to = process_address_list(@initial_to );
943
970
@initial_cc = process_address_list(@initial_cc );
944
- @bcclist = process_address_list(@bcclist );
971
+ @initial_bcc = process_address_list(@initial_bcc );
945
972
946
973
if ($thread && !defined $initial_in_reply_to && $prompting ) {
947
974
$initial_in_reply_to = ask(
@@ -1364,7 +1391,7 @@ sub send_message {
1364
1391
}
1365
1392
@cc );
1366
1393
my $to = join (" ,\n\t " , @recipients );
1367
- @recipients = unique_email_list(@recipients ,@cc ,@bcclist );
1394
+ @recipients = unique_email_list(@recipients ,@cc ,@initial_bcc );
1368
1395
@recipients = (map { extract_valid_address_or_die($_ ) } @recipients );
1369
1396
my $date = format_2822_time($time ++);
1370
1397
my $gitversion = ' @@GIT_VERSION@@' ;
0 commit comments