Commit e828912e authored by sikeda's avatar sikeda
Browse files

[dev] Refactoring. Renaming several functions:

Old name                            New name
----------------------------------- ----------------------------------------
Sympa::Auth::password_fingerprint   Sympa::User::password_fingerprint
Sympa::Tools::WWW::_load_mime_types Conf::_load_mime_types
Sympa::Tools::WWW::get_mime_type    Conf::get_mime_type
tools::add_in_blacklist             _add_in_blacklist in wwsympa.fcgi
tools::addrencode                   Sympa::Tools::Text::addrencode
tools::clean_msg_id                 Sympa::Tools::Text::canonic_message_id
tools::escape_chars                 Sympa::Tools::Text::escape_chars
tools::escape_docname               Sympa::SharedDocument::escape_docname
tools::escape_html                  Sympa::Tools::WWW::escape_html_minimum
tools::escape_quote                 Sympa::Template::_escape_quote
tools::escape_url                   Sympa::Tools::Text::escape_url
tools::escape_xml                   Sympa::Template::_escape_xml
tools::eval_in_time                 Sympa::Process::eval_in_time
tools::get_list_params              Sympa::Robot::list_params
tools::get_message_id               Sympa::unique_message_id
tools::lang2charset                 Conf::lang2charset
tools::load_edit_list_conf          Sympa::List::_load_edit_list_conf
tools::qdecode_filename             Sympa::Tools::Text::qdecode_filename
tools::qencode_filename             Sympa::Tools::Text::qencode_filename
tools::qencode_hierarchy            Sympa::Tools::File::qencode_hierarchy
tools::unescape_chars               Sympa::Tools::Text::unescape_chars
tools::unescape_html                Sympa::Tools::WWW::unescape_html_minimum
tools::valid_email                  Sympa::Tools::Text::valid_email 
----------------------------------- ----------------------------------------

As a result, tools.pm was deprecated.

A few dependency loop among modules are reduced.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12677 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 2e41e0c7
......@@ -27,10 +27,10 @@ use lib split(/:/, $ENV{SYMPALIB} || ''), '--modulesdir--';
use strict;
use warnings;
use Sympa::Auth;
use Conf;
use Sympa::DatabaseManager;
use Sympa::Tools::Password;
use Sympa::User;
die "Crypt::CipherSaber not installed ; cannot crypt passwords"
unless $Crypt::CipherSaber::VERSION;
......@@ -79,7 +79,7 @@ while (my $user = $sth->fetchrow_hashref('NAME_lc')) {
q{UPDATE user_table
SET password_user = ?
WHERE email_user = ?},
Sympa::Auth::password_fingerprint($clear_password),
Sympa::User::password_fingerprint($clear_password),
$user->{'email_user'}
)
) {
......
This diff is collapsed.
......@@ -38,9 +38,9 @@ use Sympa::DatabaseManager;
use Sympa::Language;
use Sympa::LockedFile;
use Sympa::Log;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::File;
use Sympa::Tools::Text;
my $log = Sympa::Log->instance;
......@@ -1290,6 +1290,43 @@ sub load_charset {
return $charset;
}
=over
=item lang2charset ( $lang )
Gets charset for e-mail messages sent by Sympa.
Parameters:
$lang - language.
Returns:
Charset name.
If it is not known, returns default charset.
=back
=cut
# Old name: tools::lang2charset().
# FIXME: This would be moved to such as Site package.
sub lang2charset {
my $lang = shift;
my $locale2charset;
if ($lang and %Conf::Conf # configuration loaded
and $locale2charset = $Conf::Conf{'locale2charset'}
) {
foreach my $l (Sympa::Language::implicated_langs($lang)) {
if (exists $locale2charset->{$l}) {
return $locale2charset->{$l};
}
}
}
return 'utf-8'; # the last resort
}
## load nrcpt file (limite receipient par domain
sub load_nrcpt_by_domain {
my $config_file = Sympa::search_fullpath('*', 'nrcpt_by_domain.conf');
......@@ -2273,7 +2310,7 @@ sub _set_listmasters_entry {
split(/,/, $param->{'config_hash'}{'listmaster'});
$number_of_email_provided = $#emails_provided + 1;
foreach my $lismaster_address (@emails_provided) {
if (tools::valid_email($lismaster_address)) {
if (Sympa::Tools::Text::valid_email($lismaster_address)) {
# Note: 'listmasters' was obsoleted.
push @{$param->{'config_hash'}{'listmasters'}},
$lismaster_address;
......@@ -2626,4 +2663,55 @@ sub _load_wwsconf {
# MOVED: Use Sympa::Tools::WWW::update_css().
#sub update_css;
# lazy loading on demand
my %mime_types;
# Old name: Sympa::Tools::WWW::get_mime_type().
# FIXME: This would be moved to such as Site package.
sub get_mime_type {
my $type = shift;
%mime_types = _load_mime_types() unless %mime_types;
return $mime_types{$type};
}
# Old name: Sympa::Tools::WWW::load_mime_types().
sub _load_mime_types {
my %types = ();
my @localisation = (
Sympa::search_fullpath('*', 'mime.types'),
'/etc/mime.types', '/usr/local/apache/conf/mime.types',
'/etc/httpd/conf/mime.types',
);
foreach my $loc (@localisation) {
my $fh;
next unless $loc and open $fh, '<', $loc;
foreach my $line (<$fh>) {
next if $line =~ /^\s*\#/;
chomp $line;
my ($k, $v) = split /\s+/, $line, 2;
next unless $k and $v and $v =~ /\S/;
my @extensions = split /\s+/, $v;
# provides file extention, given the content-type
if (@extensions) {
$types{$k} = $extensions[0];
}
foreach my $ext (@extensions) {
$types{$ext} = $k;
}
}
close $fh;
return %types;
}
return;
}
1;
......@@ -153,7 +153,6 @@ nobase_modules_DATA = \
Sympa/Task.pm \
Sympa/Template.pm \
Sympa/Ticket.pm \
tools.pm \
Sympa/Tools/Data.pm \
Sympa/Tools/DKIM.pm \
Sympa/Tools/File.pm \
......
......@@ -55,7 +55,6 @@ use Sympa::Language;
use Sympa::Log;
use Sympa::Spindle::ProcessTemplate;
use Sympa::Ticket;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::Text;
......@@ -277,8 +276,9 @@ sub request_auth {
$data->{'type'} = 'review';
}
$data->{'command_escaped'} = tools::escape_url($data->{'command'});
$data->{'auto_submitted'} = 'auto-replied';
$data->{'command_escaped'} =
Sympa::Tools::Text::escape_url($data->{'command'});
$data->{'auto_submitted'} = 'auto-replied';
unless (Sympa::send_file($list, 'request_auth', $sender, $data)) {
$log->syslog('notice',
'Unable to send template "request_auth" to %s', $sender);
......@@ -293,7 +293,7 @@ sub request_auth {
);
$data->{'command'} = "auth $keyauth remind *";
$data->{'command_escaped'} =
tools::escape_url($data->{'command'});
Sympa::Tools::Text::escape_url($data->{'command'});
$data->{'type'} = 'remind';
}
......@@ -1276,7 +1276,8 @@ sub get_listmasters_email {
}
my @listmasters =
grep { tools::valid_email($_) } split /\s*,\s*/, $listmaster;
grep { Sympa::Tools::Text::valid_email($_) } split /\s*,\s*/,
$listmaster;
# If no valid adresses found, use listmaster of site config.
unless (@listmasters or (not ref $that and $that eq '*')) {
$log->syslog('notice', 'Warning: No listmasters found for %s', $that);
......@@ -1307,6 +1308,32 @@ sub is_listmaster {
return 0;
}
=over
=item unique_message_id ( $that )
TBD
=back
=cut
# Old name: tools::get_message_id().
sub unique_message_id {
my $that = shift;
my $domain;
if (ref $that eq 'Sympa::List') {
$domain = Conf::get_robot_conf($that->{'domain'}, 'domain');
} elsif ($that and $that ne '*') {
$domain = Conf::get_robot_conf($that, 'domain');
} else {
$domain = $Conf::Conf{'domain'};
}
return sprintf '<sympa.%d.%d.%d@%s>', time, $PID, (int rand 999), $domain;
}
1;
__END__
......
......@@ -27,12 +27,12 @@ package Sympa::Alarm;
use strict;
use warnings;
use Sympa;
use Sympa::Bulk;
use Conf;
use Sympa::Log;
use Sympa::Mailer;
use Sympa::Message::Template;
use tools;
use base qw(Class::Singleton);
......@@ -134,7 +134,7 @@ sub flush {
operation => $operation,
notification_messages => $messages{$rcpt},
boundary => '----------=_'
. tools::get_message_id($robot_id)
. Sympa::unique_message_id($robot_id)
};
$log->syslog('info', 'Send messages to %s', $rcpt);
......
......@@ -41,8 +41,8 @@ use Sympa::LockedFile;
use Sympa::Log;
use Sympa::Message;
use Sympa::Spool;
use tools;
use Sympa::Tools::File;
use Sympa::Tools::Text;
my $log = Sympa::Log->instance;
......@@ -188,8 +188,9 @@ sub fetch {
next unless $message; # Malformed message.
if ($options{message_id}) {
my $message_id =
tools::clean_msg_id($message->get_header('Message-Id')) || '';
my $message_id = Sympa::Tools::Text::canonic_message_id(
$message->get_header('Message-Id'))
|| '';
if ($message_id eq $options{message_id}) {
undef $self->{_metadatas}; # Rewind cache.
return ($message, $handle);
......@@ -391,7 +392,10 @@ sub html_remove {
);
# Remomve urlized message.
my $url_dir = $list->{'dir'} . '/urlized/' . tools::escape_chars($msgid);
my $url_dir =
$list->{'dir'}
. '/urlized/'
. Sympa::Tools::Text::escape_chars($msgid);
my $error;
File::Path::remove_tree($url_dir, {error => \$error});
......
......@@ -34,25 +34,14 @@ use Sympa::Database;
use Sympa::Log;
use Sympa::Report;
use Sympa::Robot;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::Text;
use Sympa::User;
my $log = Sympa::Log->instance;
## return the password finger print (this proc allow futur replacement of md5
## by sha1 or ....)
sub password_fingerprint {
$log->syslog('debug', '');
my $pwd = shift;
if (Conf::get_robot_conf('*', 'password_case') eq 'insensitive') {
return Digest::MD5::md5_hex(lc($pwd));
} else {
return Digest::MD5::md5_hex($pwd);
}
}
# Moved to: Sympa::User::password_fingerprint().
#sub password_fingerprint;
## authentication : via email or uid
sub check_auth {
......@@ -63,7 +52,7 @@ sub check_auth {
my ($canonic, $user);
if (tools::valid_email($auth)) {
if (Sympa::Tools::Text::valid_email($auth)) {
return authentication($robot, $auth, $pwd);
} else {
## This is an UID
......@@ -158,7 +147,7 @@ sub authentication {
## the user passwords
## Other backends are Single Sign-On solutions
if ($auth_service->{'auth_type'} eq 'user_table') {
my $fingerprint = password_fingerprint($pwd);
my $fingerprint = Sympa::User::password_fingerprint($pwd);
if ($fingerprint eq $user->{'password'}) {
Sympa::User::update_global_user($email,
......@@ -198,7 +187,7 @@ sub authentication {
my $param; #FIXME FIXME: not used.
$param->{'init_email'} = $email;
$param->{'escaped_init_email'} = tools::escape_chars($email);
$param->{'escaped_init_email'} = Sympa::Tools::Text::escape_chars($email);
return undef;
}
......@@ -336,7 +325,7 @@ sub ldap_authentication {
## If the identifier provided was a valid email, return the provided
## email.
## Otherwise, return the canonical email guessed after the login.
if (tools::valid_email($auth)
if (Sympa::Tools::Text::valid_email($auth)
and not Conf::get_robot_conf($robot, 'ldap_force_canonical_email')) {
return $auth;
} else {
......
......@@ -470,7 +470,7 @@ sub get_lang {
return $self->{lang} || 'en'; # the last resort
}
# DEPRECATED: use tools::lang2charset().
# DEPRECATED: use Conf::lang2charset().
# sub GetCharset;
## DEPRECATED: Use canonic_lang().
......
......@@ -50,6 +50,7 @@ use Sympa::Language;
use Sympa::ListDef;
use Sympa::LockedFile;
use Sympa::Log;
use Sympa::Process;
use Sympa::Regexps;
use Sympa::Robot;
use Sympa::Scenario;
......@@ -58,7 +59,6 @@ use Sympa::Spindle::ProcessTemplate;
use Sympa::Task;
use Sympa::Template;
use Sympa::Ticket;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::File;
use Sympa::Tools::Password;
......@@ -1159,7 +1159,7 @@ sub get_param_value {
my $self = shift;
my $param = shift;
my $as_arrayref = shift || 0;
my $pinfo = tools::get_list_params($self->{'domain'});
my $pinfo = Sympa::Robot::list_params($self->{'domain'});
my $minor_param;
my $value;
......@@ -1419,9 +1419,9 @@ sub get_recipients_per_mode {
# # missing.
# if ($message->{'smime_crypted'}
# and not -r $Conf::Conf{'ssl_cert_dir'} . '/'
# . tools::escape_chars($user->{'email'})
# . Sympa::Tools::Text::escape_chars($user->{'email'})
# and not -r $Conf::Conf{'ssl_cert_dir'} . '/'
# . tools::escape_chars($user->{'email'} . '@enc')) {
# . Sympa::Tools::Text::escape_chars($user->{'email'} . '@enc')) {
# my $subject = $message->{'decoded_subject'};
# my $sender = $message->{'sender'};
# unless (
......@@ -4136,7 +4136,7 @@ sub may_edit {
$Sympa::Robot::mtime{'edit_list_conf'}{$edit_conf_file}) {
$edit_conf = $edit_list_conf{$edit_conf_file} =
tools::load_edit_list_conf($self);
$self->_load_edit_list_conf;
$Sympa::Robot::mtime{'edit_list_conf'}{$edit_conf_file} = time;
} else {
$edit_conf = $edit_list_conf{$edit_conf_file};
......@@ -4199,12 +4199,11 @@ sub may_create_parameter {
if (Sympa::is_listmaster($robot, $who)) {
return 1;
}
my $edit_conf = tools::load_edit_list_conf($self);
my $edit_conf = $self->_load_edit_list_conf;
$edit_conf->{$parameter} ||= $edit_conf->{'default'};
if (!$edit_conf->{$parameter}) {
$log->syslog('notice',
'tools::load_edit_list_conf privilege for parameter $parameter undefined'
);
$log->syslog('notice', 'Privilege for parameter %s undefined',
$parameter);
return undef;
}
if ($edit_conf->{$parameter} =~ /^(owner|privileged_owner)$/i) {
......@@ -4928,7 +4927,7 @@ sub _include_users_file {
my $email = Sympa::Tools::Text::canonic_email($1);
unless (tools::valid_email($email)) {
unless (Sympa::Tools::Text::valid_email($email)) {
$log->syslog('err', 'Skip badly formed email address: "%s"',
$email);
next;
......@@ -5035,7 +5034,7 @@ sub _include_users_remote_file {
my $email = Sympa::Tools::Text::canonic_email($1);
unless (tools::valid_email($email)) {
unless (Sympa::Tools::Text::valid_email($email)) {
$log->syslog('err', 'Skip badly formed email address: "%s"',
$line);
next;
......@@ -5130,7 +5129,7 @@ sub _include_users_voot_group {
foreach my $member (@$members) {
#foreach my $email (@{$member->{'emails'}}) {
if (my $email = shift(@{$member->{'emails'}})) {
unless (tools::valid_email($email)) {
unless (Sympa::Tools::Text::valid_email($email)) {
$log->syslog('err', 'Skip badly formed email address: "%s"',
$email);
next;
......@@ -5245,7 +5244,7 @@ sub _include_users_ldap {
foreach my $email (@{$emailentry}) {
my $cleanmail = Sympa::Tools::Text::canonic_email($email);
## Skip badly formed emails
unless (tools::valid_email($email)) {
unless (Sympa::Tools::Text::valid_email($email)) {
$log->syslog('err',
'Skip badly formed email address: "%s"', $email);
next;
......@@ -5259,7 +5258,7 @@ sub _include_users_ldap {
} else { #FIMXE: Probably not reached due to asref.
my $cleanmail = Sympa::Tools::Text::canonic_email($emailentry);
## Skip badly formed emails
unless (tools::valid_email($emailentry)) {
unless (Sympa::Tools::Text::valid_email($emailentry)) {
$log->syslog('err', 'Skip badly formed email address: "%s"',
$emailentry);
next;
......@@ -5466,7 +5465,7 @@ sub _include_users_ldap_2level {
foreach my $email (@{$emailentry}) {
my $cleanmail = Sympa::Tools::Text::canonic_email($email);
## Skip badly formed emails
unless (tools::valid_email($email)) {
unless (Sympa::Tools::Text::valid_email($email)) {
$log->syslog('err',
'Skip badly formed email address: "%s"', $email);
next;
......@@ -5484,7 +5483,7 @@ sub _include_users_ldap_2level {
my $cleanmail =
Sympa::Tools::Text::canonic_email($emailentry);
## Skip badly formed emails
unless (tools::valid_email($emailentry)) {
unless (Sympa::Tools::Text::valid_email($emailentry)) {
$log->syslog('err',
'Skip badly formed email address: "%s"', $emailentry);
next;
......@@ -5701,7 +5700,8 @@ sub _include_users_sql {
## Process the SQL results
my $array_of_users =
tools::eval_in_time(sub { $sth->fetchall_arrayref }, $fetch_timeout);
Sympa::Process::eval_in_time(sub { $sth->fetchall_arrayref },
$fetch_timeout);
$sth->finish;
unless (ref $array_of_users eq 'ARRAY') {
......@@ -5719,7 +5719,7 @@ sub _include_users_sql {
$email = Sympa::Tools::Text::canonic_email($email);
## Skip badly formed emails
unless (tools::valid_email($email)) {
unless (Sympa::Tools::Text::valid_email($email)) {
$log->syslog('err', 'Skip badly formed email address: "%s"',
$email);
next;
......@@ -6248,7 +6248,7 @@ sub _load_include_admin_user_file {
$log->syslog('debug3', '(%s, %s, %s)', @_);
my ($robot, $file, $parsing) = @_;
my $pinfo = tools::get_list_params($robot);
my $pinfo = Sympa::Robot::list_params($robot);
my %include;
my (@paragraphs);
......@@ -8159,7 +8159,7 @@ sub by_order {
}
## Apply defaults to parameters definition (%Sympa::ListDef::pinfo)
## DEPRECATED: use tools::get_list_params($robot).
## DEPRECATED: use Sympa::Robot::list_params($robot).
##sub _apply_defaults {
## Save a parameter
......@@ -8170,7 +8170,7 @@ sub _save_list_param {
return 1 if $defaults;
return 1 unless (defined($p));
my $pinfo = tools::get_list_params($robot_id);
my $pinfo = Sympa::Robot::list_params($robot_id);
if ( defined($pinfo->{$key}{'scenario'})
|| defined($pinfo->{$key}{'task'})) {
return 1 if ($p->{'name'} eq 'default');
......@@ -8354,7 +8354,7 @@ sub _load_list_config_file {
my ($directory, $robot, $file) = @_;
$log->syslog('debug3', '(%s, %s, %s)', $directory, $robot, $file);
my $pinfo = tools::get_list_params($robot);
my $pinfo = Sympa::Robot::list_params($robot);
my $config_file = $directory . '/' . $file;
my %admin;
......@@ -8715,7 +8715,7 @@ sub _save_list_config_file {
my $self = shift;
my ($config_file, $old_config_file) = @_;
my $pinfo = tools::get_list_params($self->{'domain'});
my $pinfo = Sympa::Robot::list_params($self->{'domain'});
unless (rename $config_file, $old_config_file) {
$log->syslog(
......@@ -9560,8 +9560,8 @@ sub add_list_header {
and $self->is_web_archived()) {
# Use possiblly anonymized Message-Id: field instead of
# {message_id} attribute.
my $message_id =
tools::clean_msg_id($message->get_header('Message-Id'));
my $message_id = Sympa::Tools::Text::canonic_message_id(
$message->get_header('Message-Id'));
my @now = localtime(time);
my $yyyy = sprintf '%04d', 1900 + $now[5];
......@@ -9695,6 +9695,66 @@ sub _flush_list_db {
# Moved to Sympa::ListOpt::get_title().
#sub get_option_title;
# Return a hash from the edit_list_conf file.
# Old name: tools::load_edit_list_conf().
sub _load_edit_list_conf {
$log->syslog('debug2', '(%s)', @_);
my $self = shift;
my $robot = $self->{'domain'};
my $file;
my $conf;
return undef
unless $file = Sympa::search_fullpath($self, 'edit_list.conf');
my $fh;
unless (open $fh, '<', $file) {
$log->syslog('info', 'Unable to open config file %s', $file);
return undef;
}
my $error_in_conf;
my $roles_regexp =
'listmaster|privileged_owner|owner|editor|subscriber|default';
while (<$fh>) {
next if /^\s*(\#.*|\s*)$/;
if (/^\s*(\S+)\s+(($roles_regexp)\s*(,\s*($roles_regexp))*)\s+(read|write|hidden)\s*$/i
) {
my ($param, $role, $priv) = ($1, $2, $6);
my @roles = split /,/, $role;
foreach my $r (@roles) {
$r =~ s/^\s*(\S+)\s*$/$1/;
if ($r eq 'default') {
$error_in_conf = 1;
$log->syslog('notice', '"default" is no more recognised');
foreach
my $set ('owner', 'privileged_owner', 'listmaster') {
$conf->{$param}{$set} = $priv;
}
next;
}
$conf->{$param}{$r} = $priv;
}
} else {
$log->syslog(
'info',
'Unknown parameter in %s (Ignored) %s',
"$Conf::Conf{'etc'}/edit_list.conf", $_
);
next;
}
}
if ($error_in_conf) {
Sympa::send_notify_to_listmaster($robot, 'edit_list_error', [$file]);
}
close $fh;
return $conf;
}
=head2 Pluggin data-sources
=head3 $obj->includes(DATASOURCE, [NEW])
......
......@@ -54,13 +54,11 @@ use Sympa::Log;
use Sympa::Scenario;
use Sympa::Spool;
use Sympa::Template;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::File;
use Sympa::Tools::Password;
use Sympa::Tools::SMIME;