Commit 35fca0d0 authored by sikeda's avatar sikeda
Browse files

[-dev] Small refactoring: New Sympa::get_listmasters_email() to get valid addresses of listmasters.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12292 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 3035c5dc
......@@ -11,6 +11,12 @@ Subject: [% FILTER qencode %][%|loc(list.name,list.host,email)%]List "%1@%2" cre
[%|loc%]To activate/delete this mailing list:[%END%]
[% conf.wwsympa_url %]/ticket/[%one_time_ticket%]
[%- ELSIF type == 'list_created' -%]
[% PROCESS 'list_created.tt2' -%]
[%- ELSIF type == 'list_rejected' -%]
[% PROCESS 'list_rejected.tt2' -%]
[%- ELSIF type == 'request_list_renaming' -%]
[%- IF mode == 'copy' -%]
Subject: [% FILTER qencode %][%|loc(new_listname)%]%1 mailing list creation[%END%][%END%]
......
......@@ -10883,18 +10883,12 @@ sub do_install_pending_list {
}
 
## Notify listmasters
my @listmasters = split /\s*,\s*/,
Conf::get_robot_conf($robot, 'listmaster');
if ($in{'status'} eq 'open') {
unless (Sympa::send_file($list, 'list_created', \@listmasters, {})) {
wwslog('notice',
'Unable to send template "list_created" to listmaster');
}
Sympa::send_notify_to_listmaster($list, 'list_created',
[$list->{'name'}]);
} elsif ($in{'status'} eq 'closed') {
unless (Sympa::send_file($list, 'list_rejected', \@listmasters, {})) {
wwslog('notice',
'Unable to send template "list_rejected" to listmaster');
}
Sympa::send_notify_to_listmaster($list, 'list_rejected',
[$list->{'name'}]);
}
 
if ($in{'notify'}) {
......
......@@ -2310,6 +2310,7 @@ sub _set_listmasters_entry {
$number_of_email_provided = $#emails_provided + 1;
foreach my $lismaster_address (@emails_provided) {
if (tools::valid_email($lismaster_address)) {
# Note: 'listmasters' was obsoleted.
push @{$param->{'config_hash'}{'listmasters'}},
$lismaster_address;
$number_of_valid_email++;
......@@ -2329,6 +2330,7 @@ sub _set_listmasters_entry {
);
return undef;
} else {
# Note: 'listmasters' was obsoleted.
$param->{'config_hash'}{'listmasters'} = $Conf{'listmasters'};
$param->{'config_hash'}{'listmaster'} = $Conf{'listmaster'};
$number_of_valid_email =
......
......@@ -770,8 +770,7 @@ sub send_notify_to_listmaster {
$robot_id = '*';
}
my $listmaster =
[split /\s*,\s*/, Conf::get_robot_conf($robot_id, 'listmaster')];
my @listmasters = Sympa::get_listmasters_email($that);
my $to =
Conf::get_robot_conf($robot_id, 'listmaster_email') . '@'
. Conf::get_robot_conf($robot_id, 'host');
......@@ -801,7 +800,7 @@ sub send_notify_to_listmaster {
if ( $operation eq 'request_list_creation'
or $operation eq 'request_list_renaming') {
foreach my $email (@$listmaster) {
foreach my $email (@listmasters) {
my $cdata = Sympa::Tools::Data::dup_var($data);
$cdata->{'one_time_ticket'} =
Sympa::Auth::create_one_time_ticket($email, $robot_id,
......@@ -815,7 +814,7 @@ sub send_notify_to_listmaster {
} else {
push @tosend,
{
email => $listmaster,
email => [@listmasters],
data => $data
};
}
......@@ -843,7 +842,7 @@ sub send_notify_to_listmaster {
'notice',
'Unable to send template "listmaster_notification" to %s listmaster %s',
$robot_id,
$listmaster
$ts->{'email'}
) unless $operation eq 'logs_failed';
return undef;
}
......@@ -959,6 +958,52 @@ sub get_supported_languages {
return \@lang_list;
}
=head3 Users
These are accessors derived from configuration parameters.
=over
=item get_listmasters_email ( $that )
# To get addresses of super-listmasters.
@addrs = Sympa::get_listmasters_email('*');
# To get addresses of normal listmasters of a robot.
@addrs = Sympa::get_listmasters_email($robot);
# To get addresses of normal listmasters of the robot of a family.
@addrs = Sympa::get_listmasters_email($family);
# To get addresses of normal listmasters of the robot of a list.
@addrs = Sympa::get_listmasters_email($list);
Gets valid email addresses of listmasters. In array context, returns array of
addresses. In scalar context, returns arrayref to them.
=back
=cut
# Old names:
# [6.2b] Conf::get_robot_conf(..., 'listmasters'), $Conf::Conf{'listmasters'}.
# [trunk] Site::listmasters().
sub get_listmasters_email {
my $that = shift;
my $listmaster;
if (ref $that eq 'Sympa::List') {
$listmaster = Conf::get_robot_conf($that->{'domain'}, 'listmaster');
} elsif (ref $that eq 'Sympa::Family') {
$listmaster = Conf::get_robot_conf($that->{'robot'}, 'listmaster');
} elsif (not ref($that) and $that and $that ne '*') {
$listmaster = Conf::get_robot_conf($that, 'listmaster');
} else {
$listmaster = Conf::get_robot_conf('*', 'listmaster');
}
my @listmasters =
grep { tools::valid_email($_) } split /\s*,\s*/, $listmaster;
return wantarray ? @listmasters : [@listmasters];
}
1;
__END__
......
......@@ -2877,7 +2877,7 @@ sub send_notify_to_owner {
'No owner defined or all of them use nomail option in list %s; using listmasters as default',
$self->{'name'}
);
@to = split /,/, Conf::get_robot_conf($robot, 'listmaster');
@to = Sympa::get_listmasters_email($self);
}
unless (defined $operation) {
die 'missing incoming parameter "$operation"';
......
......@@ -63,14 +63,8 @@ sub is_listmaster {
$who =~ y/A-Z/a-z/;
foreach my $listmaster (@{Conf::get_robot_conf($robot, 'listmasters')}) {
return 1 if (lc($listmaster) eq lc($who));
}
foreach my $listmaster (@{Conf::get_robot_conf('*', 'listmasters')}) {
return 1 if (lc($listmaster) eq lc($who));
}
return 1 if grep { lc $_ eq $who } Sympa::get_listmasters_email($robot);
return 1 if grep { lc $_ eq $who } Sympa::get_listmasters_email('*');
return 0;
}
......
......@@ -340,7 +340,7 @@ while (!$end) {
my $result = Sympa::Scenario::request_action(
$list, 'del', 'smtp',
{ 'sender' => $Conf::Conf{'listmasters'}[0],
{ 'sender' => $Conf::Conf{'listmaster'}, #FIXME
'email' => $who
}
);
......
......@@ -1019,11 +1019,9 @@ sub DoForward {
delete $message->{'family'};
if ($function eq "listmaster") {
my $listmasters = Conf::get_robot_conf($robot, 'listmasters');
@rcpt = @{$listmasters};
@rcpt = Sympa::get_listmasters_email($robot);
$log->syslog('notice', 'Warning: No listmaster defined in sympa.conf')
unless @rcpt;
} elsif ($function eq "owner") { # -request
@rcpt = $list->get_owners_email();
......
......@@ -1157,11 +1157,10 @@ sub delete_subs_cmd {
my %selection; # hash of subscriber emails who are successfully deleted
foreach my $email (keys %{$Rvars->{$var}}) {
$log->syslog('notice', '%s', $email);
my $result = Sympa::Scenario::request_action(
$list, 'del', 'smime',
{ 'sender' => $Conf::Conf{'listmaster'},
{ 'sender' => $Conf::Conf{'listmaster'}, #FIXME
'email' => $email,
}
);
......@@ -1482,7 +1481,7 @@ sub purge_user_table {
my $time = time;
# Marking super listmasters
foreach my $l (@{$Conf::Conf{'listmasters'}}) {
foreach my $l (Sympa::get_listmasters_email('*')) {
unless (
$sdm
and $sdm->do_prepared_query(
......@@ -1498,7 +1497,7 @@ sub purge_user_table {
}
# Marking per-robot listmasters.
foreach my $robot_id (Sympa::List::get_robots()) {
foreach my $l (@{Conf::get_robot_conf($robot_id, 'listmasters')}) {
foreach my $l (Sympa::get_listmasters_email($robot_id)) {
unless (
$sdm->do_prepared_query(
q{UPDATE user_table
......@@ -1888,10 +1887,7 @@ sub process_bouncers {
$rcpt = [$list->get_owners_email];
$to = $list->get_list_address('owner');
} elsif ($notification eq 'listmaster') {
$rcpt = [
split /\s*,\s*/,
Conf::get_robot_conf($robot_id, 'listmaster')
];
$rcpt = Sympa::get_listmasters_email($robot_id);
$to =
Conf::get_robot_conf($robot_id, 'listmaster_email')
. '@'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment