Skip to content

Commit

Permalink
Merge branch 'master' of github.com:virtualmin/virtualmin-gpl
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed Mar 20, 2024
2 parents e889934 + 08768cd commit dfab3a3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions feature-mail.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6894,6 +6894,40 @@ sub list_append_styles
[ 7, "username\%domain" ] );
}

# remove_forward_in_other_users(&user, &domain)
# Remove any forward to this user in other aliases
sub remove_forward_in_other_users
{
my ($user, $d) = @_;
if ($config{'mail_system'} == 0) {
# Postfix
return if (!$user->{'email'});
my $user_alias = "\\" . &escape_alias($user->{'email'});
&foreign_require("postfix");
my $afiles =
[ &postfix::get_aliases_files(
&postfix::get_real_value("alias_maps")) ];
&postfix::lock_alias_files($afiles);
my @aliases = &postfix::list_postfix_aliases($afiles);
my @oaliases = grep { &indexof($user_alias,
@{$_->{'values'}}) >= 0 } @aliases;
my $malias;
foreach my $oalias (@oaliases) {
my @values = grep { $_ ne $user_alias } @{$oalias->{'values'}};
my %nalias = %$oalias;
delete($nalias{'value'});
$nalias{'values'} = \@values;
&postfix::modify_postfix_alias($oalias, \%nalias);
$malias++;
}
&postfix::unlock_alias_files($afiles);
if ($malias) {
&postfix::regenerate_aliases();
&postfix::reload_postfix();
}
}
}

$done_feature_script{'mail'} = 1;

1;
Expand Down
3 changes: 3 additions & 0 deletions virtual-server-lib-funcs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,9 @@ sub delete_user
return undef;
}

# Check if deleted user present in other users aliases
&remove_forward_in_other_users($_[0], $_[1]);

# Zero out his quotas
if ($_[0]->{'unix'} && !$_[0]->{'noquota'}) {
&set_user_quotas($_[0]->{'user'}, 0, 0, $_[1]);
Expand Down

0 comments on commit dfab3a3

Please sign in to comment.