Commit d99610cc authored by sikeda's avatar sikeda
Browse files

[dev] tools::get_canonical_email() and tools::clean_email() are deprecated. ...

[dev] tools::get_canonical_email() and tools::clean_email() are deprecated.  Use Sympa::Tools::Text::canonic_email() instead.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12426 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 6a1648db
......@@ -4770,7 +4770,8 @@ sub do_requestpasswd {
$param->{'request_from_host'} = $ip;
unless ($param->{'newuser'} = Sympa::User::get_global_user($in{'email'}))
{
$param->{'newuser'} = {'email' => tools::clean_email($in{'email'})};
$param->{'newuser'} =
{'email' => Sympa::Tools::Text::canonic_email($in{'email'})};
$param->{'newuser'}{'escaped_email'} =
tools::escape_chars($param->{'newuser'}{'email'});
}
......@@ -6366,7 +6367,7 @@ sub do_subrequest {
unless ($param->{'newuser'} =
Sympa::User::get_global_user($in{'email'})) {
$param->{'newuser'} =
{'email' => tools::clean_email($in{'email'})};
{'email' => Sympa::Tools::Text::canonic_email($in{'email'})};
$param->{'newuser'}{'escaped_email'} =
tools::escape_chars($param->{'newuser'}{'email'});
}
......@@ -8022,25 +8023,25 @@ sub do_add {
if ($in{'dump'}) {
foreach (split /\n/, $in{'dump'}) {
if (/^\s*($email_regexp)(\s+(.*))?\s*$/) {
$user{tools::get_canonical_email($1)} = $5;
$user{Sympa::Tools::Text::canonic_email($1)} = $5;
}
}
} elsif ($in{'email'} =~ /,/) {
foreach my $pair (split /\0/, $in{'email'}) {
if ($pair =~ /^($email_regexp)(,(.*))?\s*$/) {
$user{tools::get_canonical_email($1)} = $5;
$user{Sympa::Tools::Text::canonic_email($1)} = $5;
}
}
} elsif ($in{'email'}) {
foreach my $email (split /\0/, $in{'email'}) {
$user{tools::get_canonical_email($email)} = $in{'gecos'};
$user{Sympa::Tools::Text::canonic_email($email)} = $in{'gecos'};
}
} elsif ($in{'pending_email'}) {
foreach my $pair (split /\0/, $in{'pending_email'}) {
my ($email, $gecos);
if ($pair =~ /^($email_regexp)(,(.*))?\s*$/) {
($email, $gecos) = ($1, $5);
$user{tools::get_canonical_email($email)} = $gecos;
$user{Sympa::Tools::Text::canonic_email($email)} = $gecos;
}
}
} else {
......
......@@ -58,6 +58,7 @@ use Sympa::Log;
use Sympa::Message;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::Text;
my $log = Sympa::Log->instance;
......@@ -1030,9 +1031,9 @@ Is the user listmaster?
# Old names: [6.2b-6.2.3] Sympa::Robot::is_listmaster($who, $robot_id)
sub is_listmaster {
my $that = shift;
my $who = tools::clean_email(shift || '');
my $who = Sympa::Tools::Text::canonic_email(shift);
return undef unless length $who;
return undef unless defined $who;
return 1 if grep { lc $_ eq $who } Sympa::get_listmasters_email($that);
return 1 if grep { lc $_ eq $who } Sympa::get_listmasters_email('*');
return 0;
......
......@@ -3235,7 +3235,7 @@ sub delete_list_member {
my $total = 0;
foreach my $who (@u) {
$who = tools::clean_email($who);
$who = Sympa::Tools::Text::canonic_email($who);
## Include in exclusion_table only if option is set.
if ($exclude) {
......@@ -3293,7 +3293,7 @@ sub delete_list_admin {
delete $self->{_admin_cache}{$role}; # Reset cache
foreach my $who (@u) {
$who = tools::clean_email($who);
$who = Sympa::Tools::Text::canonic_email($who);
my $statement;
my $sdm = Sympa::DatabaseManager->instance;
......@@ -3650,7 +3650,7 @@ sub get_exclusion {
######################################################################
sub get_list_member {
my $self = shift;
my $email = tools::clean_email(shift);
my $email = Sympa::Tools::Text::canonic_email(shift);
my %options = @_;
$log->syslog('debug2', '(%s)', $email);
......@@ -3726,7 +3726,7 @@ sub get_list_member_no_object {
my $name = $options->{'name'};
my $email = tools::clean_email($options->{'email'});
my $email = Sympa::Tools::Text::canonic_email($options->{'email'});
## Use session cache
if (defined $list_cache{'get_list_member'}{$options->{'domain'}}{$name}
......@@ -4043,7 +4043,7 @@ sub get_admins {
my %options = @_;
my %query = @{$options{filter} || []};
$query{email} = tools::clean_email($query{email})
$query{email} = Sympa::Tools::Text::canonic_email($query{email})
if defined $query{email};
# Fill caches.
......@@ -4154,11 +4154,11 @@ sub _get_basic_admins {
$sth->finish;
foreach my $user (@$admin_user) {
$user->{'email'} = tools::clean_email($user->{'email'})
$user->{'email'} = Sympa::Tools::Text::canonic_email($user->{'email'})
if defined $user->{'email'};
$log->syslog('err',
'Warning: Entry with empty email address in list %s', $self)
unless defined $user->{'email'} and length $user->{'email'};
unless defined $user->{'email'};
$user->{'reception'} ||= 'mail';
$user->{'update_date'} ||= $user->{'date'};
}
......@@ -4473,9 +4473,9 @@ sub get_resembling_members {
$log->syslog('debug2', '(%s, %s)', @_);
my $self = shift;
my $role = shift;
my $searchkey = tools::clean_email(shift || '');
my $searchkey = Sympa::Tools::Text::canonic_email(shift);
return unless $searchkey;
return unless defined $searchkey;
$searchkey =~ s/(['%_\\])/\\$1/g;
my ($local, $domain) = split /\@/, $searchkey;
......@@ -4608,7 +4608,7 @@ sub is_admin {
## Is the indicated person a subscriber to the list?
sub is_list_member {
my ($self, $who) = @_;
$who = tools::clean_email($who);
$who = Sympa::Tools::Text::canonic_email($who);
$log->syslog('debug3', '(%s)', $who);
return undef unless ($self && $who);
......@@ -4659,7 +4659,7 @@ sub is_list_member {
sub update_list_member {
my ($self, $who, $values) = @_;
$log->syslog('debug2', '(%s)', $who);
$who = tools::clean_email($who);
$who = Sympa::Tools::Text::canonic_email($who);
my ($field, $value, $table);
my $name = $self->{'name'};
......@@ -4855,7 +4855,7 @@ sub update_list_member {
sub update_list_admin {
my ($self, $who, $role, $values) = @_;
$log->syslog('debug2', '(%s, %s)', $role, $who);
$who = tools::clean_email($who);
$who = Sympa::Tools::Text::canonic_email($who);
my ($field, $value, $table);
my $name = $self->{'name'};
......@@ -5029,8 +5029,8 @@ sub add_list_member {
my $current_list_members_count = $self->get_total();
foreach my $new_user (@new_users) {
my $who = tools::clean_email($new_user->{'email'});
unless ($who) {
my $who = Sympa::Tools::Text::canonic_email($new_user->{'email'});
unless (defined $who) {
$log->syslog('err', 'Ignoring %s which is not a valid email',
$new_user->{'email'});
next;
......@@ -5203,9 +5203,10 @@ sub add_list_admin {
delete $self->{_admin_cache}{$role}; # Reset cache
foreach my $new_admin_user (@new_admin_users) {
my $who = tools::clean_email($new_admin_user->{'email'});
my $who =
Sympa::Tools::Text::canonic_email($new_admin_user->{'email'});
next unless $who;
next unless defined $who;
$new_admin_user->{'date'} ||= time;
$new_admin_user->{'update_date'} ||= $new_admin_user->{'date'};
......@@ -6206,7 +6207,7 @@ sub _include_users_file {
next;
}
my $email = tools::clean_email($1);
my $email = Sympa::Tools::Text::canonic_email($1);
unless (tools::valid_email($email)) {
$log->syslog('err', 'Skip badly formed email address: "%s"',
......@@ -6313,7 +6314,7 @@ sub _include_users_remote_file {
next;
}
my $email = tools::clean_email($1);
my $email = Sympa::Tools::Text::canonic_email($1);
unless (tools::valid_email($email)) {
$log->syslog('err', 'Skip badly formed email address: "%s"',
......@@ -6523,7 +6524,7 @@ sub _include_users_ldap {
} elsif (ref $emailentry eq 'ARRAY') {
# Multiple values
foreach my $email (@{$emailentry}) {
my $cleanmail = tools::clean_email($email);
my $cleanmail = Sympa::Tools::Text::canonic_email($email);
## Skip badly formed emails
unless (tools::valid_email($email)) {
$log->syslog('err',
......@@ -6537,7 +6538,7 @@ sub _include_users_ldap {
last if $ldap_select eq 'first';
}
} else { #FIMXE: Probably not reached due to asref.
my $cleanmail = tools::clean_email($emailentry);
my $cleanmail = Sympa::Tools::Text::canonic_email($emailentry);
## Skip badly formed emails
unless (tools::valid_email($emailentry)) {
$log->syslog('err', 'Skip badly formed email address: "%s"',
......@@ -6561,7 +6562,7 @@ sub _include_users_ldap {
my ($email, $gecos) = @$emailgecos;
next if ($email =~ /^\s*$/);
$email = tools::clean_email($email);
$email = Sympa::Tools::Text::canonic_email($email);
my %u;
## Check if user has already been included
if ($users->{$email}) {
......@@ -6744,7 +6745,7 @@ sub _include_users_ldap_2level {
} elsif (ref $emailentry eq 'ARRAY') {
# Multiple values
foreach my $email (@{$emailentry}) {
my $cleanmail = tools::clean_email($email);
my $cleanmail = Sympa::Tools::Text::canonic_email($email);
## Skip badly formed emails
unless (tools::valid_email($email)) {
$log->syslog('err',
......@@ -6761,7 +6762,8 @@ sub _include_users_ldap_2level {
last if $ldap_select2 eq 'first';
}
} else { #FIXME: Probably not reached due to asref
my $cleanmail = tools::clean_email($emailentry);
my $cleanmail =
Sympa::Tools::Text::canonic_email($emailentry);
## Skip badly formed emails
unless (tools::valid_email($emailentry)) {
$log->syslog('err',
......@@ -6789,7 +6791,7 @@ sub _include_users_ldap_2level {
my ($email, $gecos) = @$emailgecos;
next if ($email =~ /^\s*$/);
$email = tools::clean_email($email);
$email = Sympa::Tools::Text::canonic_email($email);
my %u;
## Check if user has already been included
if ($users->{$email}) {
......@@ -6995,7 +6997,7 @@ sub _include_users_sql {
## Empty value
next if ($email =~ /^\s*$/);
$email = tools::clean_email($email);
$email = Sympa::Tools::Text::canonic_email($email);
## Skip badly formed emails
unless (tools::valid_email($email)) {
......@@ -9323,7 +9325,7 @@ function to any list in ROBOT.
sub get_which {
$log->syslog('debug2', '(%s, %s, %s)', @_);
my $email = tools::clean_email(shift);
my $email = Sympa::Tools::Text::canonic_email(shift);
my $robot_id = shift;
my $role = shift;
......
......@@ -30,6 +30,22 @@ use Text::LineFold;
use if (5.008 < $] && $] < 5.016), qw(Unicode::CaseFold fc);
use if (5.016 <= $]), qw(feature fc);
# Old names: tools::clean_email(), tools::get_canonical_email().
sub canonic_email {
my $email = shift;
return undef unless defined $email;
# Remove leading and trailing white spaces.
$email =~ s/\A\s+//;
$email =~ s/\s+\z//;
# Lower-case.
$email =~ tr/A-Z/a-z/;
return (length $email) ? $email : undef;
}
sub wrap_text {
my $text = shift;
my $init = shift;
......@@ -78,6 +94,16 @@ This package provides some text-related functions.
=over
=item canonic_email ( $email )
I<Function>.
Returns canonical form of e-mail address.
Leading and trailing whilte spaces are removed.
Latin letters without accents are lower-cased.
For malformed inputs returns C<undef>.
=item wrap_text ( $text, [ $init_tab, [ $subsequent_tab, [ $cols ] ] ] )
I<Function>.
......
......@@ -33,9 +33,9 @@ use Sympa::DatabaseDescription;
use Sympa::DatabaseManager;
use Sympa::Language;
use Sympa::Log;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::Password;
use Sympa::Tools::Text;
my $log = Sympa::Log->instance;
......@@ -82,10 +82,10 @@ Create new Sympa::User object.
sub new {
my $pkg = shift;
my $who = tools::clean_email(shift || '');
my $who = Sympa::Tools::Text::canonic_email(shift);
my %values = @_;
my $self;
return undef unless $who;
return undef unless defined $who;
## Canonicalize lang if possible
$values{'lang'} = Sympa::Language::canonic_lang($values{'lang'})
......@@ -149,9 +149,9 @@ Change email of user.
sub moveto {
my $self = shift;
my $newemail = tools::clean_email(shift || '');
my $newemail = Sympa::Tools::Text::canonic_email(shift);
unless ($newemail) {
unless (defined $newemail) {
$log->syslog('err', 'No email');
return undef;
}
......@@ -309,13 +309,13 @@ sub delete_global_user {
$log->syslog('debug2', '');
return undef unless ($#users >= 0);
return undef unless @users;
my $sdm = Sympa::DatabaseManager->instance;
foreach my $who (@users) {
$who = tools::clean_email($who);
## Update field
$who = Sympa::Tools::Text::canonic_email($who);
# Update field
unless (
$sdm
and $sdm->do_prepared_query(
......@@ -327,13 +327,13 @@ sub delete_global_user {
}
}
return $#users + 1;
return scalar @users;
}
## Returns a hash for a given user
sub get_global_user {
$log->syslog('debug2', '(%s)', @_);
my $who = tools::clean_email(shift);
my $who = Sympa::Tools::Text::canonic_email(shift);
## Additional subscriber fields
my $additional = '';
......@@ -438,10 +438,10 @@ sub get_all_global_user {
## Is the person in user table (db only)
sub is_global_user {
my $who = tools::clean_email(pop);
my $who = Sympa::Tools::Text::canonic_email(pop);
$log->syslog('debug3', '(%s)', $who);
return undef unless ($who);
return undef unless defined $who;
push @sth_stack, $sth;
my $sdm = Sympa::DatabaseManager->instance;
......@@ -478,7 +478,7 @@ sub update_global_user {
$values = {@_};
}
$who = tools::clean_email($who);
$who = Sympa::Tools::Text::canonic_email($who);
## use md5 fingerprint to store password
$values->{'password'} =
......@@ -573,7 +573,8 @@ sub add_global_user {
|| $values->{'lang'}
if $values->{'lang'};
return undef unless (my $who = tools::clean_email($values->{'email'}));
my $who = Sympa::Tools::Text::canonic_email($values->{'email'});
return undef unless defined $who;
return undef if (is_global_user($who));
## Update each table
......
......@@ -459,33 +459,11 @@ sub valid_email {
return 1;
}
## Clean email address
sub clean_email {
my $email = shift;
## Lower-case
$email = lc($email);
## remove leading and trailing spaces
$email =~ s/^\s*//;
$email =~ s/\s*$//;
return $email;
}
#DEPRECATED. Use Sympa::Tools::Text::canonic_email().
#sub clean_email;
## Return canonical email address (lower-cased + space cleanup)
## It could also support alternate email
sub get_canonical_email {
my $email = shift;
## Remove leading and trailing white spaces
$email =~ s/^\s*(\S.*\S)\s*$/$1/;
## Lower-case
$email = lc($email);
return $email;
}
#DEPRECATED. Use Sympa::Tools::Text::canonic_email().
#sub get_canonical_email;
#DEPRECATED: No longer used.
# sub dump_html_var2($var);
......
......@@ -56,6 +56,7 @@ use Sympa::Scenario;
use Sympa::Spool::Bounce;
use Sympa::Tools::Daemon;
use Sympa::Tools::Data;
use Sympa::Tools::Text;
use Sympa::Tracking;
## Check options
......@@ -791,8 +792,8 @@ sub _parse_dsn {
next unless $rcpt;
$rcpt = $1 if $rcpt =~ /\@.+:\s*(.+)\z/;
$rcpt = $1 if $rcpt =~ /<(.+)>/;
$rcpt = tools::clean_email($rcpt);
next unless $rcpt;
$rcpt = Sympa::Tools::Text::canonic_email($rcpt);
next unless defined $rcpt;
$result->{$rcpt} = $status;
}
......
Markdown is supported
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