@@ -569,6 +569,15 @@ sub evaluate_uri {
569
569
' sub' => \&feature_extra_branch_refs,
570
570
' override' => 0,
571
571
' default' => []},
572
+
573
+ # Redact e-mail addresses.
574
+
575
+ # To enable system wide have in $GITWEB_CONFIG
576
+ # $feature{'email-privacy'}{'default'} = [1];
577
+ ' email-privacy' => {
578
+ ' sub' => sub { feature_bool(' email-privacy' , @_ ) },
579
+ ' override' => 1,
580
+ ' default' => [0]},
572
581
);
573
582
574
583
sub gitweb_get_feature {
@@ -3449,6 +3458,13 @@ sub parse_date {
3449
3458
return %date ;
3450
3459
}
3451
3460
3461
+ sub hide_mailaddrs_if_private {
3462
+ my $line = shift ;
3463
+ return $line unless gitweb_check_feature(' email-privacy' );
3464
+ $line =~ s / <[^@>]+@[^>]+>/ <redacted>/ g ;
3465
+ return $line ;
3466
+ }
3467
+
3452
3468
sub parse_tag {
3453
3469
my $tag_id = shift ;
3454
3470
my %tag ;
@@ -3465,7 +3481,7 @@ sub parse_tag {
3465
3481
} elsif ($line =~ m / ^tag (.+)$ / ) {
3466
3482
$tag {' name' } = $1 ;
3467
3483
} elsif ($line =~ m / ^tagger (.*) ([0-9]+) (.*)$ / ) {
3468
- $tag {' author' } = $1 ;
3484
+ $tag {' author' } = hide_mailaddrs_if_private( $1 ) ;
3469
3485
$tag {' author_epoch' } = $2 ;
3470
3486
$tag {' author_tz' } = $3 ;
3471
3487
if ($tag {' author' } =~ m / ^([^<]+) <([^>]*)>/ ) {
@@ -3513,7 +3529,7 @@ sub parse_commit_text {
3513
3529
} elsif ((!defined $withparents ) && ($line =~ m / ^parent ($oid_regex )$ / )) {
3514
3530
push @parents , $1 ;
3515
3531
} elsif ($line =~ m / ^author (.*) ([0-9]+) (.*)$ / ) {
3516
- $co {' author' } = to_utf8($1 );
3532
+ $co {' author' } = hide_mailaddrs_if_private( to_utf8($1 ) );
3517
3533
$co {' author_epoch' } = $2 ;
3518
3534
$co {' author_tz' } = $3 ;
3519
3535
if ($co {' author' } =~ m / ^([^<]+) <([^>]*)>/ ) {
@@ -3523,7 +3539,7 @@ sub parse_commit_text {
3523
3539
$co {' author_name' } = $co {' author' };
3524
3540
}
3525
3541
} elsif ($line =~ m / ^committer (.*) ([0-9]+) (.*)$ / ) {
3526
- $co {' committer' } = to_utf8($1 );
3542
+ $co {' committer' } = hide_mailaddrs_if_private( to_utf8($1 ) );
3527
3543
$co {' committer_epoch' } = $2 ;
3528
3544
$co {' committer_tz' } = $3 ;
3529
3545
if ($co {' committer' } =~ m / ^([^<]+) <([^>]*)>/ ) {
@@ -3568,9 +3584,10 @@ sub parse_commit_text {
3568
3584
if (! defined $co {' title' } || $co {' title' } eq " " ) {
3569
3585
$co {' title' } = $co {' title_short' } = ' (no commit message)' ;
3570
3586
}
3571
- # remove added spaces
3587
+ # remove added spaces, redact e-mail addresses if applicable.
3572
3588
foreach my $line (@commit_lines ) {
3573
3589
$line =~ s / ^ // ;
3590
+ $line = hide_mailaddrs_if_private($line );
3574
3591
}
3575
3592
$co {' comment' } = \@commit_lines ;
3576
3593
@@ -7489,7 +7506,8 @@ sub git_log_generic {
7489
7506
-accesskey => " n" , -title => " Alt-n" }, " next" );
7490
7507
}
7491
7508
my $patch_max = gitweb_get_feature(' patches' );
7492
- if ($patch_max && !defined $file_name ) {
7509
+ if ($patch_max && !defined $file_name &&
7510
+ !gitweb_check_feature(' email-privacy' )) {
7493
7511
if ($patch_max < 0 || @commitlist <= $patch_max ) {
7494
7512
$paging_nav .= " ⋅ " .
7495
7513
$cgi -> a({-href => href(action => " patches" , -replay => 1)},
@@ -7550,7 +7568,8 @@ sub git_commit {
7550
7568
} @$parents ) .
7551
7569
' )' ;
7552
7570
}
7553
- if (gitweb_check_feature(' patches' ) && @$parents <= 1) {
7571
+ if (gitweb_check_feature(' patches' ) && @$parents <= 1 &&
7572
+ !gitweb_check_feature(' email-privacy' )) {
7554
7573
$formats_nav .= " | " .
7555
7574
$cgi -> a({-href => href(action => " patch" , -replay => 1)},
7556
7575
" patch" );
@@ -7863,7 +7882,8 @@ sub git_commitdiff {
7863
7882
$formats_nav =
7864
7883
$cgi -> a({-href => href(action => " commitdiff_plain" , -replay => 1)},
7865
7884
" raw" );
7866
- if ($patch_max && @{$co {' parents' }} <= 1) {
7885
+ if ($patch_max && @{$co {' parents' }} <= 1 &&
7886
+ !gitweb_check_feature(' email-privacy' )) {
7867
7887
$formats_nav .= " | " .
7868
7888
$cgi -> a({-href => href(action => " patch" , -replay => 1)},
7869
7889
" patch" );
0 commit comments